-
-
Notifications
You must be signed in to change notification settings - Fork 578
/
events.spc.js
57 lines (51 loc) · 1.73 KB
/
events.spc.js
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
/* eslint-disable no-console */
const path = require("path");
const Promise = require("bluebird");
let { exec, debugExec, callIn } = require("../util");
const commonString = " received the event.";
const findResponse = (arr) => arr
.map(string => {
const line = string
.split("\n")
.find(a => a.indexOf(commonString) > 0);
return line ? line.slice(0, line.indexOf(commonString)) : false;
})
.filter(a => a);
describe("Test AMQPTransporter events", () => {
//exec = debugExec;
beforeEach(() => exec("node", [path.resolve(__dirname, "..", "purge.js")]));
afterAll(() => exec("node", [path.resolve(__dirname, "..", "purge.js")]));
it("Should send an event to all subscribed nodes.", () => {
return Promise.all([
exec("node", [path.resolve(__dirname,"pub.js")]),
exec("node", [path.resolve(__dirname,"sub1.js")]),
exec("node", [path.resolve(__dirname,"sub2.js")]),
exec("node", [path.resolve(__dirname,"sub3.js")]),
])
.then((stdout) => {
const expectedReceivers = [
"Publisher",
"Subscriber1",
"Subscriber2",
"Subscriber3",
].sort();
expect(findResponse(stdout).sort()).toEqual(expectedReceivers);
});
}, 15000);
it( "Subscribed nodes should not receive events older than 5 seconds.", () => {
return Promise.all([
callIn(() => exec("node", [path.resolve(__dirname,"pub.js")]), 200),
exec("node", [path.resolve(__dirname,"sub1.js")]),
exec("node", [path.resolve(__dirname,"sub2.js")]),
callIn(() => exec("node", [path.resolve(__dirname,"sub3.js")]), 6000),
])
.then((stdout) => {
const expectedReceivers = [
"Publisher",
"Subscriber1",
"Subscriber2",
].sort();
expect(findResponse(stdout).sort()).toEqual(expectedReceivers);
});
}, 20000);
});