From 101e1ec7b6f6a57eb2cda3551927c518c8283fe2 Mon Sep 17 00:00:00 2001 From: Sebastian Malton Date: Mon, 3 Oct 2022 15:29:13 -0400 Subject: [PATCH] Split integration tests into seperate jobs from unit tests for faster CI Signed-off-by: Sebastian Malton --- .github/workflows/test.yml | 68 +++++++++++++++++++++++++++++------- integration/helpers/utils.ts | 33 ++++++++++++----- 2 files changed, 80 insertions(+), 21 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 9aaeec71f6..47347fe1da 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -7,8 +7,8 @@ on: branches: - master jobs: - build: - name: Test + smoke: + name: Run Smoke Tests runs-on: ${{ matrix.os }} strategy: fail-fast: false @@ -62,16 +62,6 @@ jobs: retry_on: error command: make -j2 build-extensions - - run: make test - name: Run tests - - - run: make test-extensions - name: Run In-tree Extension tests - - - run: make ci-validate-dev - if: contains(github.event.pull_request.labels.*.name, 'dependencies') - name: Validate dev mode will work - - name: Install integration test dependencies id: minikube uses: medyagh/setup-minikube@master @@ -96,3 +86,57 @@ jobs: env: ELECTRON_BUILDER_EXTRA_ARGS: "--x64 --ia32" if: runner.os == 'Windows' + + unit: + name: Run Unit Tests + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + os: [ubuntu-20.04, macos-11, windows-2019] + node-version: [16.x] + steps: + - name: Checkout Release from lens + uses: actions/checkout@v2 + with: + fetch-depth: 0 + + - name: Add the current IP address, long hostname and short hostname record to /etc/hosts file + if: runner.os == 'Linux' + run: | + echo -e "$(ip addr show eth0 | grep "inet\b" | awk '{print $2}' | cut -d/ -f1)\t$(hostname -f) $(hostname -s)" | sudo tee -a /etc/hosts + + - name: Using Node.js ${{ matrix.node-version }} + uses: actions/setup-node@v1 + with: + node-version: ${{ matrix.node-version }} + + - name: Get yarn cache directory path + id: yarn-cache-dir-path + run: echo "::set-output name=dir::$(yarn cache dir)" + + - uses: actions/cache@v2 + id: yarn-cache # use this to check for `cache-hit` (`steps.yarn-cache.outputs.cache-hit != 'true'`) + with: + path: ${{ steps.yarn-cache-dir-path.outputs.dir }} + key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }} + restore-keys: | + ${{ runner.os }}-yarn- + + - uses: nick-fields/retry@v2 + name: Install dependencies + with: + timeout_minutes: 10 + max_attempts: 3 + retry_on: error + command: make node_modules + + - run: make test + name: Run tests + + - run: make test-extensions + name: Run In-tree Extension tests + + - run: make ci-validate-dev + if: contains(github.event.pull_request.labels.*.name, 'dependencies') + name: Validate dev mode will work diff --git a/integration/helpers/utils.ts b/integration/helpers/utils.ts index 49cadb4a38..5b49a50fdd 100644 --- a/integration/helpers/utils.ts +++ b/integration/helpers/utils.ts @@ -10,6 +10,8 @@ import * as uuid from "uuid"; import type { ElectronApplication, Frame, Page } from "playwright"; import { _electron as electron } from "playwright"; import { noop } from "lodash"; +import { disposer } from "../../src/common/utils"; +import { Writable } from "stream"; export const appPaths: Partial> = { "win32": "./dist/win-unpacked/OpenLens.exe", @@ -18,19 +20,32 @@ export const appPaths: Partial> = { }; async function getMainWindow(app: ElectronApplication, timeout = 50_000): Promise { - const deadline = Date.now() + timeout; + return new Promise((resolve, reject) => { + const cleanup = disposer(); + const stdoutBuffer = Buffer.from(""); + const stdoutStream = new Writable(stdoutBuffer); - for (; Date.now() < deadline;) { - for (const page of app.windows()) { + const handler = (page: Page) => { if (page.url().startsWith("http://localhost")) { - return page; + cleanup(); + resolve(page); } - } + }; - await new Promise(resolve => setTimeout(resolve, 2_000)); - } + app.addListener("window", handler); + cleanup.push(() => app.removeListener("window", handler)); - throw new Error(`Lens did not open the main window within ${timeout}ms`); + app.process().stdout?.pipe(stdoutStream); + cleanup.push(() => app.process().stdout?.unpipe(stdoutStream)); + + const timeoutId = setTimeout(() => { + cleanup(); + console.log(stdoutBuffer.toString("utf8")); + reject(new Error(`Lens did not open the main window within ${timeout}ms`)); + }, timeout); + + cleanup.push(() => clearTimeout(timeoutId)); + }); } async function attemptStart() { @@ -49,7 +64,7 @@ async function attemptStart() { ...process.env, }, timeout: 100_000, - } as Parameters[0]); + }); try { const window = await getMainWindow(app);