Skip to content

Commit e283cf2

Browse files
authored
[Unit Tests] Fix lag after Unit Tests finish, fix flakiness in Sampling test (aws-observability#78)
*Issue #, if available:* - `npm run test` command stalls for 20s after all tests pass (or fail), discovered caused by `Concurrency` test, likely due to `exportTimeoutMillis` default value being set in `AwsBatchUnsampledSpanProcessor` - Flaky test case `testSomeReservoir` that may fail when sampling targets are not refreshed in time for the unit tests (due to the test being reliant on `setTimeout` which doesn't guarantee exact time of execution). - https://github.com/aws-observability/aws-otel-js-instrumentation/actions/runs/11023689994/job/30615442620#step:7:560 *Description of changes:* - Add short `exportTimeoutMillis` value for `AwsBatchUnsampledSpanProcessor` config in `Concurrency` test - Update `testSomeReservoir` to properly cleanup the fake clock, provide more time for Sampling targets to refresh on time for the unit test run. By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.
1 parent f75a75a commit e283cf2

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed

aws-distro-opentelemetry-node-autoinstrumentation/test/aws-batch-unsampled-span-processor.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -457,6 +457,7 @@ describe('AwsBatchUnsampledSpanProcessor', () => {
457457
const processor = new AwsBatchUnsampledSpanProcessor(exporter, {
458458
maxExportBatchSize: 5,
459459
maxQueueSize: 6,
460+
exportTimeoutMillis: 1000,
460461
});
461462
const totalSpans = 50;
462463
for (let i = 0; i < totalSpans; i++) {

aws-distro-opentelemetry-node-autoinstrumentation/test/sampler/aws-xray-remote-sampler.test.ts

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,9 @@ describe('AwsXrayRemoteSampler', () => {
8888
).toEqual(SamplingDecision.NOT_RECORD);
8989

9090
setTimeout(() => {
91+
// restore function
92+
(_AwsXRayRemoteSampler.prototype as any).getDefaultTargetPollingInterval = tmp;
93+
9194
expect(
9295
sampler.shouldSample(context.active(), '1234', 'name', SpanKind.CLIENT, { abc: '1234' }, []).decision
9396
).toEqual(SamplingDecision.RECORD_AND_SAMPLED);
@@ -98,8 +101,6 @@ describe('AwsXrayRemoteSampler', () => {
98101
sampler.shouldSample(context.active(), '1234', 'name', SpanKind.CLIENT, { abc: '1234' }, []).decision
99102
).toEqual(SamplingDecision.RECORD_AND_SAMPLED);
100103

101-
// reset function
102-
(_AwsXRayRemoteSampler.prototype as any).getDefaultTargetPollingInterval = tmp;
103104
done();
104105
}, 300);
105106
}, 10);
@@ -139,10 +140,12 @@ describe('AwsXrayRemoteSampler', () => {
139140
sampled++;
140141
}
141142
}
143+
144+
// restore function
145+
(_AwsXRayRemoteSampler.prototype as any).getDefaultTargetPollingInterval = tmp;
146+
142147
expect((sampler as any)._root._root.ruleCache.ruleAppliers[0].reservoirSampler.quota).toEqual(100000);
143148
expect(sampled).toEqual(100000);
144-
// reset function
145-
(_AwsXRayRemoteSampler.prototype as any).getDefaultTargetPollingInterval = tmp;
146149
done();
147150
}, 2000);
148151
}, 100);
@@ -184,13 +187,13 @@ describe('AwsXrayRemoteSampler', () => {
184187
sampled++;
185188
}
186189
}
187-
expect(sampled).toEqual(100);
188-
// reset function
189-
(_AwsXRayRemoteSampler.prototype as any).getDefaultTargetPollingInterval = tmp;
190190
clock.restore();
191+
// restore function
192+
(_AwsXRayRemoteSampler.prototype as any).getDefaultTargetPollingInterval = tmp;
193+
expect(sampled).toEqual(100);
191194
done();
192195
}, 2000);
193-
}, 100);
196+
}, 300);
194197
});
195198

196199
it('generates valid ClientId', () => {

0 commit comments

Comments
 (0)