Skip to content

Commit dc556fb

Browse files
authored
ci: Address CI flakes and Node warning messages on the 'fetch-esm' sample (#1830)
1 parent 7e25cc3 commit dc556fb

File tree

5 files changed

+45
-17
lines changed

5 files changed

+45
-17
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ jobs:
256256
- name: Instantiate sample project using verdaccio artifacts - Fetch ESM
257257
run: |
258258
node scripts/init-from-verdaccio.js --registry-dir ${{ steps.tmp-dir.outputs.dir }}/npm-registry --sample https://github.com/temporalio/samples-typescript/tree/main/fetch-esm --target-dir ${{ steps.tmp-dir.outputs.dir }}/sample-fetch-esm
259-
node scripts/test-example.js --work-dir "${{ steps.tmp-dir.outputs.dir }}/sample-fetch-esm"
259+
node scripts/test-example.js --work-dir "${{ steps.tmp-dir.outputs.dir }}/sample-fetch-esm" --script-name workflow-local --expected-output "Hello World And Hello Wonderful Temporal!"
260260
261261
# End samples
262262

packages/test/src/test-integration-workflows.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1403,7 +1403,7 @@ test('root execution is exposed', async (t) => {
14031403
}
14041404
}
14051405
};
1406-
await waitUntil(childStarted, 5000);
1406+
await waitUntil(childStarted, 8000);
14071407
const childDesc = await childHandle.describe();
14081408
const parentDesc = await handle.describe();
14091409

packages/test/src/test-prometheus.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -109,15 +109,22 @@ test.serial('Exporting Prometheus metrics from Core works with lots of options',
109109
'temporal_workflow_task_replay_latency_seconds_bucket{namespace="default",' +
110110
'service_name="temporal-core-sdk",task_queue="test-prometheus",' +
111111
'workflow_type="successString",my_tag="my_value",le="0.001"}'
112-
)
112+
),
113+
`Actual: \n-------\n${text}\n-------`
113114
);
114115

115116
// Verify histogram overrides
116-
t.assert(text.match(/temporal_request_latency_seconds_bucket\{.*,le="31415"/));
117-
t.assert(text.match(/workflow_task_execution_latency_seconds_bucket\{.*,le="31415"/));
117+
t.assert(
118+
text.match(/temporal_request_latency_seconds_bucket\{.*,le="31415"/),
119+
`Actual: \n-------\n${text}\n-------`
120+
);
121+
t.assert(
122+
text.match(/workflow_task_execution_latency_seconds_bucket\{.*,le="31415"/),
123+
`Actual: \n-------\n${text}\n-------`
124+
);
118125

119126
// Verify prefix exists on client request metrics
120-
t.assert(text.includes('temporal_long_request{'));
127+
t.assert(text.includes('temporal_long_request{'), `Actual: \n-------\n${text}\n-------`);
121128
});
122129
} finally {
123130
await localEnv.teardown();

scripts/test-example.js

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
const { spawn: spawnChild, spawnSync } = require('child_process');
22
const arg = require('arg');
3-
const { shell, kill } = require('./utils');
3+
const { shell, kill, sleep, waitOnChild } = require('./utils');
44

55
const npm = /^win/.test(process.platform) ? 'npm.cmd' : 'npm';
66

@@ -23,8 +23,8 @@ async function withWorker(workdir, fn) {
2323
}
2424
}
2525

26-
async function test(workdir) {
27-
const { status, output } = spawnSync(npm, ['run', 'workflow'], {
26+
async function test(workdir, scriptName, expectedOutput) {
27+
const { status, output } = spawnSync(npm, ['run', scriptName], {
2828
cwd: workdir,
2929
shell,
3030
encoding: 'utf8',
@@ -33,21 +33,25 @@ async function test(workdir) {
3333
if (status !== 0) {
3434
throw new Error('Failed to run workflow');
3535
}
36-
if (!output[1].includes('Hello, Temporal!\n')) {
36+
if (!output[1].includes(`${expectedOutput}\n`)) {
3737
throw new Error(`Invalid output: "${output[1]}"`);
3838
}
3939
}
4040

4141
async function main() {
4242
const opts = arg({
4343
'--work-dir': String,
44+
'--script-name': String,
45+
'--expected-output': String,
4446
});
4547
const workdir = opts['--work-dir'];
4648
if (!workdir) {
4749
throw new Error('Missing required option --work-dir');
4850
}
51+
const scriptName = opts['--script-name'] ?? 'workflow';
52+
const expectedOutput = opts['--expected-output'] ?? 'Hello, Temporal!';
4953

50-
await withWorker(workdir, () => test(workdir));
54+
await withWorker(workdir, () => test(workdir, scriptName, expectedOutput));
5155
}
5256

5357
main()

scripts/utils.js

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,18 +32,35 @@ async function kill(child, signal = 'SIGINT') {
3232
} else {
3333
process.kill(-child.pid, signal);
3434
}
35+
3536
try {
3637
await waitOnChild(child);
3738
} catch (err) {
38-
// Should error if the error is not a child process error or it is a child
39-
// process and either the platform is Windows or the signal matches.
40-
const shouldError = err.name !== 'ChildProcessError' || (process.platform !== 'win32' && err.signal !== signal);
41-
if (shouldError) {
42-
throw err;
43-
}
39+
const signalNumber = getSignalNumber(signal);
40+
41+
// Ignore the error if it simply indicates process termination due to the signal we just sent.
42+
// On Unix, a process may complete with exit code 128 + signal number to indicate
43+
// that it was terminated by a signal. But we have the signal name.
44+
const shouldIgnore =
45+
err instanceof ChildProcessError &&
46+
(process.platform === 'win32' || err.signal === signal || err.code === 128 + signalNumber);
47+
48+
if (!shouldIgnore) throw err;
4449
}
4550
}
4651

52+
function getSignalNumber(signal) {
53+
// We don't need any other signals for now, and probably never will, so no need to list them all.
54+
// But if any other signals ends up being needed, look at `man 3 signal` for the complete list.
55+
const SIGNAL_NUMBERS = {
56+
SIGINT: 2,
57+
SIGTERM: 15,
58+
};
59+
60+
if (signal in SIGNAL_NUMBERS) return SIGNAL_NUMBERS[signal];
61+
throw new TypeError(`Unknown signal in getSignalNumber: '${signal}'. Please add a case for that signal.`);
62+
}
63+
4764
async function spawnNpx(args, opts) {
4865
const npx = /^win/.test(process.platform) ? 'npx.cmd' : 'npx';
4966
const npxArgs = ['--prefer-offline', '--timing=true', '--yes', '--', ...args];

0 commit comments

Comments
 (0)