Skip to content

Commit

Permalink
Lint and fix browser tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dyladan committed Oct 4, 2023
1 parent 0d1bc40 commit b43ac9b
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,7 @@ export abstract class BatchSpanProcessorBase<T extends BufferConfig>
private _shutdownOnce: BindOnceFuture<void>;
private _droppedSpansCount: number = 0;

constructor(
private readonly _exporter: SpanExporter,
config?: T
) {
constructor(private readonly _exporter: SpanExporter, config?: T) {
const env = getEnv();
this._maxExportBatchSize =
typeof config?.maxExportBatchSize === 'number'
Expand Down Expand Up @@ -204,8 +201,8 @@ export abstract class BatchSpanProcessorBase<T extends BufferConfig>
doExport();
} else {
Promise.all(
pendingResources.map(
resource => resource.waitForAsyncAttributes?.()
pendingResources.map(resource =>
resource.waitForAsyncAttributes?.()
)
).then(doExport, err => {
globalErrorHandler(err);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

import { diag, ROOT_CONTEXT } from '@opentelemetry/api';
import {
ExportResult,
ExportResult,
ExportResultCode,
loggingErrorHandler,
setGlobalErrorHandler,
Expand Down Expand Up @@ -506,41 +506,44 @@ describe('BatchSpanProcessorBase', () => {
});
});

describe('Concurrency', ()=> {
describe('Concurrency', () => {
it('should only send a single batch at a time', async () => {
let callbacks: ((result: ExportResult) => void)[] = []
let spans: ReadableSpan[] = []
const callbacks: ((result: ExportResult) => void)[] = [];
const spans: ReadableSpan[] = [];
const exporter: SpanExporter = {
export: async (exportedSpans: ReadableSpan[], resultCallback: (result: ExportResult) => void) => {
callbacks.push(resultCallback)
spans.push(...exportedSpans)
export: async (
exportedSpans: ReadableSpan[],
resultCallback: (result: ExportResult) => void
) => {
callbacks.push(resultCallback);
spans.push(...exportedSpans);
},
shutdown: async () => {},
};
const processor = new BatchSpanProcessor(exporter, {
maxExportBatchSize: 5,
maxQueueSize: 6,
});
const totalSpans = 50;
for (let i = 0; i < totalSpans; i++) {
const span = createSampledSpan(`${name}_${i}`);
processor.onStart(span, ROOT_CONTEXT);
processor.onEnd(span);
}
const processor = new BatchSpanProcessor(exporter, {
maxExportBatchSize: 5,
maxQueueSize: 6,
});
const totalSpans = 50;
for (let i = 0; i < totalSpans; i++) {
const span = createSampledSpan(`${name}_${i}`);
processor.onStart(span, ROOT_CONTEXT);
processor.onEnd(span);
}
assert.equal(callbacks.length, 1)
assert.equal(spans.length, 5)
callbacks[0]({ code: ExportResultCode.SUCCESS })
await new Promise(resolve => setImmediate(resolve))
// After the first batch completes we will have dropped a number
// of spans and the next batch will be smaller
assert.equal(callbacks.length, 2)
assert.equal(spans.length, 10)
callbacks[1]({ code: ExportResultCode.SUCCESS })

// We expect that all the other spans have been dropped
await new Promise(resolve => setImmediate(resolve))
assert.equal(callbacks.length, 2)
assert.equal(spans.length, 10)
})
})
assert.equal(callbacks.length, 1);
assert.equal(spans.length, 5);
callbacks[0]({ code: ExportResultCode.SUCCESS });
await new Promise(resolve => setTimeout(resolve, 0));
// After the first batch completes we will have dropped a number
// of spans and the next batch will be smaller
assert.equal(callbacks.length, 2);
assert.equal(spans.length, 10);
callbacks[1]({ code: ExportResultCode.SUCCESS });

// We expect that all the other spans have been dropped
await new Promise(resolve => setTimeout(resolve, 0));
assert.equal(callbacks.length, 2);
assert.equal(spans.length, 10);
});
});
});

0 comments on commit b43ac9b

Please sign in to comment.