From a8c2facc7ec60ba0d9b86d770917ff20b876e3f5 Mon Sep 17 00:00:00 2001 From: Roey Berman Date: Mon, 1 Mar 2021 15:47:13 +0200 Subject: [PATCH 1/2] Run integrations tests in CI --- .github/workflows/ci.yml | 15 ++++++++-- packages/test/package.json | 3 ++ packages/test/src/test-integration.ts | 11 +++++-- scripts/wait-on-temporal.js | 41 +++++++++++++++++++++++++++ 4 files changed, 66 insertions(+), 4 deletions(-) create mode 100644 scripts/wait-on-temporal.js diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index af31cc3ff..66a019d4a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,4 +1,4 @@ -name: ci +name: Continuous Integration on: # rebuild any PRs and main branch changes pull_request: push: @@ -24,8 +24,19 @@ jobs: - uses: actions/setup-node@v1 with: node-version: ${{ matrix.node }} - - run: npm -g i npm@next-7 + - run: npm -g i npm@next-7 # TODO: do we need this? - run: npm ci - run: npm run build - run: npm run lint + - name: Get Temporal docker-compose.yml + run: wget https://raw.githubusercontent.com/temporalio/docker-compose/main/docker-compose.yml + if: ${{ startsWith(matrix.os, 'ubuntu') }} + - name: Start Temporal Server + run: docker-compose up -d + if: ${{ startsWith(matrix.os, 'ubuntu') }} + - name: Wait for Temporal Server + run: node scripts/wait-on-temporal.js + if: ${{ startsWith(matrix.os, 'ubuntu') }} - run: npm test + env: + RUN_INTEGRATION_TESTS: ${{ startsWith(matrix.os, 'ubuntu') }} diff --git a/packages/test/package.json b/packages/test/package.json index 260abec7e..7d71b9fd5 100644 --- a/packages/test/package.json +++ b/packages/test/package.json @@ -8,6 +8,9 @@ "test": "ava ./lib/test-*.js", "test.watch": "ava --watch ./lib/test-*.js" }, + "ava": { + "timeout": "60s" + }, "keywords": [ "temporal", "workflow", diff --git a/packages/test/src/test-integration.ts b/packages/test/src/test-integration.ts index aa3c65cde..94f4b1326 100644 --- a/packages/test/src/test-integration.ts +++ b/packages/test/src/test-integration.ts @@ -16,9 +16,16 @@ const { EVENT_TYPE_TIMER_FIRED, EVENT_TYPE_TIMER_CANCELED, } = iface.temporal.api.enums.v1.EventType; + const timerEventTypes = new Set([EVENT_TYPE_TIMER_STARTED, EVENT_TYPE_TIMER_FIRED, EVENT_TYPE_TIMER_CANCELED]); -if (process.env.RUN_INTEGRATION_TESTS === '1') { +function isSet(env: string | undefined) { + if (env === undefined) return false; + env = env.toLocaleLowerCase(); + return env === '1' || env === 't' || env === 'true'; +} + +if (isSet(process.env.RUN_INTEGRATION_TESTS)) { test.before((t) => { worker.run('test').catch((err) => { t.fail(`Failed to run worker: ${err}`); @@ -55,7 +62,7 @@ if (process.env.RUN_INTEGRATION_TESTS === '1') { test('cancel-timer-immediately', async (t) => { const client = new Connection(); const opts = compileWorkflowOptions(addDefaults({ taskQueue: 'test' })); - const runId = await client.startWorkflowExecution(opts, 'cancel-timer'); + const runId = await client.startWorkflowExecution(opts, 'cancel-timer-immediately'); const res = await client.untilComplete(opts.workflowId, runId); t.is(res, undefined); const execution = await client.service.getWorkflowExecutionHistory({ diff --git a/scripts/wait-on-temporal.js b/scripts/wait-on-temporal.js new file mode 100644 index 000000000..0a9f9b542 --- /dev/null +++ b/scripts/wait-on-temporal.js @@ -0,0 +1,41 @@ +const { Connection } = require('@temporalio/client'); + +class Timer { + constructor(ms) { + this.ms = ms; + } + + then(resolve) { + setTimeout(resolve, this.ms); + } +} + +async function main(maxAttempts = 100, retryIntervalSecs = 1) { + for (let attempt = 1; attempt <= maxAttempts; ++attempt) { + try { + const client = new Connection(); + await client.service.describeNamespace({ namespace: 'default' }); + // We wait an extra 3 seconds after a successful describe namespace because the namespace + // is not really ready after the call. + // See: https://github.com/temporalio/temporal/issues/1336 + await new Timer(3000); + break; + } catch (err) { + if (attempt === maxAttempts) { + throw err; + } + await new Timer(retryIntervalSecs * 1000); + } + } +} + +main().then( + () => { + console.log('Connected'); + process.exit(0); + }, + (err) => { + console.error('Failed to connect', err); + process.exit(1); + } +); From 59a7ebf3104534008d3716d276b34021bb1d58ec Mon Sep 17 00:00:00 2001 From: Roey Berman Date: Tue, 2 Mar 2021 11:28:24 +0200 Subject: [PATCH 2/2] Stream build and test logs --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index d27b3f427..3e26931d0 100644 --- a/package.json +++ b/package.json @@ -31,9 +31,9 @@ "typescript": "^4.2.2" }, "scripts": { - "build": "lerna run build", + "build": "lerna run --stream build", "build.watch": "lerna run --stream build.watch", - "test": "lerna run test", + "test": "lerna run --stream test", "test.watch": "lerna run --stream test.watch", "lint": "eslint packages/*/src --ext .ts && prettier --check .", "format": "prettier --write .",