Skip to content

Commit 331d281

Browse files
committed
chore(instr-aws-sdk): add events to test fixtures process
1 parent 17b7815 commit 331d281

File tree

2 files changed

+31
-12
lines changed

2 files changed

+31
-12
lines changed

packages/opentelemetry-node/test/instr-aws.test.js

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -240,19 +240,22 @@ const server = http
240240

241241
// Wait for all fixtures to finish before closing the server
242242
// TODO: looks like a nice feature for `runTestFixtures`
243-
let pendingFixtures = testFixtures.length;
244-
testFixtures.forEach((fixt) => {
245-
const origCheck = fixt.checkResult || (() => undefined);
246-
fixt.checkResult = (t, err, stdout, stderr) => {
247-
origCheck.call(this, t, err, stdout, stderr);
248-
pendingFixtures--;
249-
if (pendingFixtures === 0) {
250-
server.close();
251-
}
252-
};
253-
});
243+
// let pendingFixtures = testFixtures.length;
244+
// testFixtures.forEach((fixt) => {
245+
// const origCheck = fixt.checkResult || (() => undefined);
246+
// fixt.checkResult = (t, err, stdout, stderr) => {
247+
// origCheck.call(this, t, err, stdout, stderr);
248+
// pendingFixtures--;
249+
// if (pendingFixtures === 0) {
250+
// server.close();
251+
// }
252+
// };
253+
// });
254254

255255
test('express instrumentation', (suite) => {
256-
runTestFixtures(suite, testFixtures);
256+
const events = runTestFixtures(suite, testFixtures);
257+
events.on('all:completed', () => {
258+
server.close();
259+
});
257260
suite.end();
258261
});

packages/opentelemetry-node/test/testutils.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
const assert = require('assert');
2525
const fs = require('fs');
2626
const {execFile} = require('child_process');
27+
const EventEmitter = require('events');
2728

2829
const moduleDetailsFromPath = require('module-details-from-path');
2930
const semver = require('semver');
@@ -459,6 +460,7 @@ class TestCollector {
459460
*
460461
* @param {import('tape').Test} suite
461462
* @param {Array<TestFixture>} testFixtures
463+
* @returns {import('events').EventEmitter}
462464
*/
463465
function runTestFixtures(suite, testFixtures) {
464466
// Handle fixtures with `only: true`, if any.
@@ -470,7 +472,17 @@ function runTestFixtures(suite, testFixtures) {
470472
testFixtures = onlyTestFixtures;
471473
}
472474

475+
const eventsEmitter = new EventEmitter();
476+
let runningFixtures = testFixtures.length;
477+
478+
eventsEmitter.on('fixture:complete', () => {
479+
runningFixtures -= 1;
480+
if (runningFixtures === 0) {
481+
eventsEmitter.emit('all:completed')
482+
}
483+
});
473484
testFixtures.forEach((tf) => {
485+
eventsEmitter.emit('fixture:start', tf);
474486
const testName = tf.name ?? quoteArgv(tf.args);
475487
const testOpts = Object.assign({}, tf.testOpts);
476488
suite.test(testName, testOpts, async (t) => {
@@ -493,6 +505,7 @@ function runTestFixtures(suite, testFixtures) {
493505
)})`
494506
);
495507
t.end();
508+
eventsEmitter.emit('fixture:complete', tf);
496509
return;
497510
}
498511
}
@@ -593,12 +606,15 @@ function runTestFixtures(suite, testFixtures) {
593606
}
594607
await otlpServer.close();
595608
t.end();
609+
eventsEmitter.emit('fixture:complete', tf);
596610
resolve();
597611
}
598612
);
599613
});
600614
});
601615
});
616+
617+
return eventsEmitter;
602618
}
603619

604620
module.exports = {

0 commit comments

Comments
 (0)