forked from exceptionless/Exceptionless.JavaScript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDefaultEventQueue.test.ts
More file actions
68 lines (54 loc) · 2.03 KB
/
DefaultEventQueue.test.ts
File metadata and controls
68 lines (54 loc) · 2.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import { Configuration } from "../../src/configuration/Configuration.js";
import { IEvent } from "../../src/models/IEvent.js";
import { InMemorySubmissionAdapter } from "../submission/InMemorySubmissionAdapter.js";
describe('DefaultEventQueue', () => {
let config: Configuration;
beforeEach(() => {
config = new Configuration({
apiKey: 'LhhP1C9gijpSKCslHHCvwdSIz298twx271n1l6xw',
serverUrl: 'http://localhost:5000',
submissionAdapter: new InMemorySubmissionAdapter()
});
expect(config.storage.queue.get().length).toBe(0);
});
afterEach(() => {
const queue: any = config.queue;
clearInterval(queue._queueTimer);
config = null;
});
test('should enqueue event', () => {
const event: IEvent = { type: 'log', reference_id: '123454321' };
config.queue.enqueue(event);
expect(config.storage.queue.get().length).toBe(1);
});
test('should process queue', () => {
const event: IEvent = { type: 'log', reference_id: '123454321' };
config.queue.enqueue(event);
expect(config.storage.queue.get().length).toBe(1);
config.queue.process();
config.queue.onEventsPosted(() => {
expect((config.queue as any)._suspendProcessingUntil).toBeUndefined();
expect(config.storage.queue.get().length).toBe(0);
});
});
test('should discard event submission', () => {
config.queue.suspendProcessing(1, true);
const event: IEvent = { type: 'log', reference_id: '123454321' };
config.queue.enqueue(event);
expect(config.storage.queue.get().length).toBe(0);
});
test('should suspend processing', done => {
config.queue.suspendProcessing(.0001);
const event: IEvent = { type: 'log', reference_id: '123454321' };
config.queue.enqueue(event);
expect(config.storage.queue.get().length).toBe(1);
setTimeout(() => {
if (!(config.queue as any)._suspendProcessingUntil) {
expect(config.storage.queue.get().length).toBe(0);
} else {
expect(config.storage.queue.get().length).toBe(1);
}
done();
}, 25);
});
});