Skip to content

Commit

Permalink
fix: lint
Browse files Browse the repository at this point in the history
  • Loading branch information
mayurkale22 committed Sep 4, 2019
1 parent ce670c9 commit defe812
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,33 +19,33 @@ import { ReadableSpan } from './ReadableSpan';
import { ExportResult } from './ExportResult';

/**
* This class can be used for testing purposes. It saves the exported spans
* in a list in memory that can be retrieve using the `getFinishedSpans`
* This class can be used for testing purposes. It stores the exported spans
* in a list in memory that can be retrieve using the `getFinishedSpans()`
* method.
*/
export class InMemorySpanExporter implements SpanExporter {
private _finishedSpan: ReadableSpan[] = [];
private _finishedSpans: ReadableSpan[] = [];
private _stopped = false;

export(
spans: ReadableSpan[],
resultCallback: (result: ExportResult) => void
): void {
if (this._stopped) return resultCallback(ExportResult.FailedNonRetryable);
this._finishedSpan.push(...spans);
this._finishedSpans.push(...spans);
return resultCallback(ExportResult.Success);
}

shutdown(): void {
this._stopped = true;
this._finishedSpan = [];
this._finishedSpans = [];
}

reset() {
this._finishedSpan = [];
this._finishedSpans = [];
}

getFinishedSpans(): ReadableSpan[] {
return this._finishedSpan;
return this._finishedSpans;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,17 @@ import { NoopScopeManager } from '@opentelemetry/scope-base';
class TestProcessor implements SpanProcessor {
spans: Span[] = [];
onStart(span: Span): void {}

onEnd(span: Span): void {
this.spans.push(span);
}
shutdown(): void {
this.spans = []
this.spans = [];
}
}


describe('MultiSpanProcessor', () => {
const tracer = new BasicTracer({
scopeManager: new NoopScopeManager()
scopeManager: new NoopScopeManager(),
});
const span = tracer.startSpan('one');

Expand All @@ -43,7 +41,7 @@ describe('MultiSpanProcessor', () => {
multiSpanProcessor.onStart(span);
multiSpanProcessor.onEnd(span);
multiSpanProcessor.shutdown();
})
});

it('should handle one span processor', () => {
const processor1 = new TestProcessor();
Expand All @@ -52,7 +50,7 @@ describe('MultiSpanProcessor', () => {
assert.strictEqual(processor1.spans.length, 0);
multiSpanProcessor.onEnd(span);
assert.strictEqual(processor1.spans.length, 1);
})
});

it('should handle two span processor', () => {
const processor1 = new TestProcessor();
Expand All @@ -68,5 +66,5 @@ describe('MultiSpanProcessor', () => {
multiSpanProcessor.shutdown();
assert.strictEqual(processor1.spans.length, 0);
assert.strictEqual(processor1.spans.length, processor2.spans.length);
})
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,12 @@
*/

import * as assert from 'assert';
import { InMemorySpanExporter, SimpleSpanProcessor, BasicTracer, ExportResult } from '../../src';
import {
InMemorySpanExporter,
SimpleSpanProcessor,
BasicTracer,
ExportResult,
} from '../../src';
import { NoopScopeManager } from '@opentelemetry/scope-base';

describe('InMemorySpanExporter', () => {
Expand All @@ -28,12 +33,12 @@ describe('InMemorySpanExporter', () => {
afterEach(() => {
// reset spans in memory.
memoryExporter.reset();
})
});

it('should get finished spans', () => {
const root = tracer.startSpan('root');
const child = tracer.startSpan('child', {parent: root});
const grandChild = tracer.startSpan('grand-child', {parent: child});
const child = tracer.startSpan('child', { parent: root });
const grandChild = tracer.startSpan('grand-child', { parent: child });

assert.strictEqual(memoryExporter.getFinishedSpans().length, 0);
grandChild.end();
Expand All @@ -55,15 +60,15 @@ describe('InMemorySpanExporter', () => {

it('should shutdown the exorter', () => {
const root = tracer.startSpan('root');
tracer.startSpan('child', {parent: root}).end();
tracer.startSpan('child', { parent: root }).end();
root.end();
assert.strictEqual(memoryExporter.getFinishedSpans().length, 2);
memoryExporter.shutdown();
assert.strictEqual(memoryExporter.getFinishedSpans().length, 0);

// after shutdown no new spans are accepted
tracer.startSpan('child1', {parent: root}).end();
assert.strictEqual(memoryExporter.getFinishedSpans().length, 0);
// after shutdown no new spans are accepted
tracer.startSpan('child1', { parent: root }).end();
assert.strictEqual(memoryExporter.getFinishedSpans().length, 0);
});

it('should return the success result', () => {
Expand All @@ -82,5 +87,4 @@ describe('InMemorySpanExporter', () => {
assert.strictEqual(result, ExportResult.FailedNonRetryable);
});
});

});

0 comments on commit defe812

Please sign in to comment.