Skip to content

Commit feab15a

Browse files
committed
fix lag after tests finish, fix flaky Sampler unit test
1 parent 62b1f1b commit feab15a

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
@@ -87,6 +87,9 @@ describe('AwsXrayRemoteSampler', () => {
8787
).toEqual(SamplingDecision.NOT_RECORD);
8888

8989
setTimeout(() => {
90+
// restore function
91+
(AwsXRayRemoteSampler.prototype as any).getDefaultTargetPollingInterval = tmp;
92+
9093
expect(
9194
sampler.shouldSample(context.active(), '1234', 'name', SpanKind.CLIENT, { abc: '1234' }, []).decision
9295
).toEqual(SamplingDecision.RECORD_AND_SAMPLED);
@@ -97,8 +100,6 @@ describe('AwsXrayRemoteSampler', () => {
97100
sampler.shouldSample(context.active(), '1234', 'name', SpanKind.CLIENT, { abc: '1234' }, []).decision
98101
).toEqual(SamplingDecision.RECORD_AND_SAMPLED);
99102

100-
// reset function
101-
(AwsXRayRemoteSampler.prototype as any).getDefaultTargetPollingInterval = tmp;
102103
done();
103104
}, 300);
104105
}, 10);
@@ -138,12 +139,14 @@ describe('AwsXrayRemoteSampler', () => {
138139
sampled++;
139140
}
140141
}
142+
143+
// restore function
144+
(AwsXRayRemoteSampler.prototype as any).getDefaultTargetPollingInterval = tmp;
145+
141146
expect((((sampler as any).ruleCache as any).ruleAppliers[0] as any).reservoirSampler._root.quota).toEqual(
142147
100000
143148
);
144149
expect(sampled).toEqual(100000);
145-
// reset function
146-
(AwsXRayRemoteSampler.prototype as any).getDefaultTargetPollingInterval = tmp;
147150
done();
148151
}, 2000);
149152
}, 100);
@@ -185,13 +188,13 @@ describe('AwsXrayRemoteSampler', () => {
185188
sampled++;
186189
}
187190
}
188-
expect(sampled).toEqual(100);
189-
// reset function
190-
(AwsXRayRemoteSampler.prototype as any).getDefaultTargetPollingInterval = tmp;
191191
clock.restore();
192+
// restore function
193+
(AwsXRayRemoteSampler.prototype as any).getDefaultTargetPollingInterval = tmp;
194+
expect(sampled).toEqual(100);
192195
done();
193196
}, 2000);
194-
}, 100);
197+
}, 300);
195198
});
196199

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

0 commit comments

Comments
 (0)