@sockethub/server 5.0.0-alpha.4 → 5.0.0-alpha.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +54 -60
- package/bin/sockethub +4 -3
- package/package.json +42 -54
- package/res/socket.io.js +4908 -0
- package/res/sockethub-client.js +602 -0
- package/res/sockethub-client.min.js +19 -0
- package/sockethub.config.example.json +2 -3
- package/src/bootstrap/init.d.ts +16 -13
- package/src/bootstrap/init.test.ts +211 -0
- package/src/bootstrap/init.ts +152 -76
- package/src/bootstrap/load-platforms.ts +151 -0
- package/src/config.test.ts +27 -22
- package/src/config.ts +82 -86
- package/src/defaults.json +24 -16
- package/src/index.ts +61 -22
- package/src/janitor.test.ts +191 -169
- package/src/janitor.ts +141 -118
- package/src/listener.ts +148 -58
- package/src/middleware/create-activity-object.test.ts +28 -8
- package/src/middleware/create-activity-object.ts +16 -10
- package/src/middleware/expand-activity-stream.test.data.ts +331 -345
- package/src/middleware/expand-activity-stream.test.ts +65 -66
- package/src/middleware/expand-activity-stream.ts +26 -21
- package/src/middleware/store-credentials.test.ts +74 -60
- package/src/middleware/store-credentials.ts +14 -8
- package/src/middleware/validate.test.data.ts +240 -242
- package/src/middleware/validate.test.ts +39 -78
- package/src/middleware/validate.ts +62 -36
- package/src/middleware.test.ts +168 -138
- package/src/middleware.ts +57 -55
- package/src/platform-instance.test.ts +508 -214
- package/src/platform-instance.ts +324 -231
- package/src/platform.test.ts +375 -0
- package/src/platform.ts +306 -117
- package/src/process-manager.ts +75 -51
- package/src/routes.test.ts +43 -89
- package/src/routes.ts +40 -78
- package/src/sentry.test.ts +106 -0
- package/src/sentry.ts +19 -0
- package/src/sockethub.ts +190 -129
- package/src/util.ts +5 -0
- package/coverage/tmp/coverage-39338-1663949520416-0.json +0 -1
- package/dist/bootstrap/init.d.ts +0 -18
- package/dist/bootstrap/init.js +0 -64
- package/dist/bootstrap/init.js.map +0 -1
- package/dist/bootstrap/platforms.js +0 -75
- package/dist/config.d.ts +0 -12
- package/dist/config.js +0 -107
- package/dist/config.js.map +0 -1
- package/dist/defaults.json +0 -28
- package/dist/index.d.ts +0 -1
- package/dist/index.js +0 -29
- package/dist/index.js.map +0 -1
- package/dist/janitor.d.ts +0 -30
- package/dist/janitor.js +0 -120
- package/dist/janitor.js.map +0 -1
- package/dist/listener.d.ts +0 -31
- package/dist/listener.js +0 -94
- package/dist/listener.js.map +0 -1
- package/dist/middleware/create-activity-object.d.ts +0 -8
- package/dist/middleware/create-activity-object.js +0 -19
- package/dist/middleware/create-activity-object.js.map +0 -1
- package/dist/middleware/expand-activity-stream.d.ts +0 -3
- package/dist/middleware/expand-activity-stream.js +0 -36
- package/dist/middleware/expand-activity-stream.js.map +0 -1
- package/dist/middleware/expand-activity-stream.test.data.d.ts +0 -480
- package/dist/middleware/expand-activity-stream.test.data.js +0 -360
- package/dist/middleware/expand-activity-stream.test.data.js.map +0 -1
- package/dist/middleware/store-credentials.d.ts +0 -3
- package/dist/middleware/store-credentials.js +0 -9
- package/dist/middleware/store-credentials.js.map +0 -1
- package/dist/middleware/validate.d.ts +0 -2
- package/dist/middleware/validate.js +0 -56
- package/dist/middleware/validate.js.map +0 -1
- package/dist/middleware/validate.test.data.d.ts +0 -532
- package/dist/middleware/validate.test.data.js +0 -263
- package/dist/middleware/validate.test.data.js.map +0 -1
- package/dist/middleware.d.ts +0 -21
- package/dist/middleware.js +0 -56
- package/dist/middleware.js.map +0 -1
- package/dist/platform-instance.d.ts +0 -78
- package/dist/platform-instance.js +0 -226
- package/dist/platform-instance.js.map +0 -1
- package/dist/platform.d.ts +0 -6
- package/dist/platform.js +0 -176
- package/dist/platform.js.map +0 -1
- package/dist/process-manager.d.ts +0 -11
- package/dist/process-manager.js +0 -82
- package/dist/process-manager.js.map +0 -1
- package/dist/routes.d.ts +0 -13
- package/dist/routes.js +0 -83
- package/dist/routes.js.map +0 -1
- package/dist/sockethub.d.ts +0 -18
- package/dist/sockethub.js +0 -112
- package/dist/sockethub.js.map +0 -1
- package/src/bootstrap/platforms.js +0 -75
- package/test/init-suite.js +0 -41
- package/test/sockethub-suite.js +0 -25
- package/tsconfig.json +0 -18
- package/views/examples/dummy.ejs +0 -95
- package/views/examples/feeds.ejs +0 -90
- package/views/examples/irc.ejs +0 -239
- package/views/examples/shared.js +0 -72
- package/views/examples/xmpp.ejs +0 -217
- package/views/index.ejs +0 -17
package/src/defaults.json
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
1
|
{
|
|
2
|
-
"
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
"$schema": "https://sockethub.org/schemas/3.0.0-alpha.4/sockethub-config.json",
|
|
3
|
+
"examples": true,
|
|
4
|
+
"log_file": "",
|
|
5
|
+
"packageConfig": {
|
|
6
|
+
"@sockethub/activity-streams": {
|
|
7
|
+
"specialObjs": ["credentials"],
|
|
8
|
+
"failOnUnknownObjectProperties": true
|
|
5
9
|
}
|
|
6
10
|
},
|
|
7
|
-
"
|
|
8
|
-
"
|
|
9
|
-
"
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
"
|
|
13
|
-
|
|
14
|
-
"path": "/sockethub"
|
|
15
|
-
},
|
|
16
|
-
"log_file": "",
|
|
17
|
-
"platforms": [],
|
|
11
|
+
"platforms": [
|
|
12
|
+
"@sockethub/platform-dummy",
|
|
13
|
+
"@sockethub/platform-feeds",
|
|
14
|
+
"@sockethub/platform-irc",
|
|
15
|
+
"@sockethub/platform-metadata",
|
|
16
|
+
"@sockethub/platform-xmpp"
|
|
17
|
+
],
|
|
18
18
|
"public": {
|
|
19
19
|
"protocol": "http",
|
|
20
20
|
"host": "localhost",
|
|
@@ -22,7 +22,15 @@
|
|
|
22
22
|
"path": "/"
|
|
23
23
|
},
|
|
24
24
|
"redis": {
|
|
25
|
-
"
|
|
26
|
-
|
|
25
|
+
"url": "redis://127.0.0.1:6379"
|
|
26
|
+
},
|
|
27
|
+
"sentry": {
|
|
28
|
+
"dsn": "",
|
|
29
|
+
"traceSampleRate": 1.0
|
|
30
|
+
},
|
|
31
|
+
"sockethub": {
|
|
32
|
+
"port": 10550,
|
|
33
|
+
"host": "localhost",
|
|
34
|
+
"path": "/sockethub"
|
|
27
35
|
}
|
|
28
36
|
}
|
package/src/index.ts
CHANGED
|
@@ -1,29 +1,68 @@
|
|
|
1
|
+
import debug from "debug";
|
|
2
|
+
import config from "./config";
|
|
1
3
|
import Sockethub from "./sockethub";
|
|
2
4
|
|
|
3
|
-
|
|
5
|
+
let sentry: { readonly reportError: (err: Error) => void } = {
|
|
6
|
+
reportError: (err: Error) => {},
|
|
7
|
+
};
|
|
4
8
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
// eslint-disable-next-line security-node/detect-crlf
|
|
9
|
-
console.log(err.stack);
|
|
10
|
-
process.exit(1);
|
|
11
|
-
});
|
|
9
|
+
export async function server() {
|
|
10
|
+
let sockethub: Sockethub;
|
|
11
|
+
const log = debug("sockethub:init");
|
|
12
12
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
13
|
+
// conditionally initialize sentry
|
|
14
|
+
if (config.get("sentry:dsn")) {
|
|
15
|
+
log("initializing sentry");
|
|
16
|
+
sentry = await import("./sentry");
|
|
17
|
+
}
|
|
17
18
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
19
|
+
try {
|
|
20
|
+
sockethub = new Sockethub();
|
|
21
|
+
} catch (err) {
|
|
22
|
+
sentry.reportError(err);
|
|
23
|
+
console.error(err);
|
|
24
|
+
process.exit(1);
|
|
25
|
+
}
|
|
22
26
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
+
process.once("uncaughtException", (err: Error) => {
|
|
28
|
+
console.error(
|
|
29
|
+
`${(new Date()).toUTCString()} UNCAUGHT EXCEPTION\n`,
|
|
30
|
+
err.stack,
|
|
31
|
+
);
|
|
32
|
+
sentry.reportError(err);
|
|
33
|
+
process.exit(1);
|
|
34
|
+
});
|
|
27
35
|
|
|
28
|
-
|
|
29
|
-
|
|
36
|
+
process.once("unhandledRejection", (err: Error) => {
|
|
37
|
+
console.error(
|
|
38
|
+
`${(new Date()).toUTCString()} UNHANDLED REJECTION\n`,
|
|
39
|
+
err,
|
|
40
|
+
);
|
|
41
|
+
sentry.reportError(err);
|
|
42
|
+
process.exit(1);
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
process.once("SIGTERM", () => {
|
|
46
|
+
console.log("Received TERM signal. Exiting.");
|
|
47
|
+
process.exit(0);
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
process.once("SIGINT", () => {
|
|
51
|
+
console.log("Received INT signal. Exiting.");
|
|
52
|
+
process.exit(0);
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
process.once("exit", async () => {
|
|
56
|
+
console.log("sockethub shutdown...");
|
|
57
|
+
await sockethub.shutdown();
|
|
58
|
+
process.exit(0);
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
try {
|
|
62
|
+
await sockethub.boot();
|
|
63
|
+
} catch (err) {
|
|
64
|
+
sentry.reportError(err);
|
|
65
|
+
console.error(err);
|
|
66
|
+
process.exit(1);
|
|
67
|
+
}
|
|
68
|
+
}
|
package/src/janitor.test.ts
CHANGED
|
@@ -1,189 +1,211 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import * as sinon from 'sinon';
|
|
1
|
+
import { afterEach, beforeEach, describe, expect, it } from "bun:test";
|
|
2
|
+
import * as sinon from "sinon";
|
|
4
3
|
|
|
5
|
-
|
|
6
|
-
{ id: 'socket foo', emit: () => {} },
|
|
7
|
-
{ id: 'socket bar', emit: () => {} }
|
|
8
|
-
]
|
|
4
|
+
import { Janitor } from "./janitor.js";
|
|
9
5
|
|
|
10
|
-
|
|
11
|
-
|
|
6
|
+
const sockets = [
|
|
7
|
+
{ id: "socket foo", emit: () => {} },
|
|
8
|
+
{ id: "socket bar", emit: () => {} },
|
|
9
|
+
];
|
|
12
10
|
|
|
13
11
|
function getPlatformInstanceFake() {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
[
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
12
|
+
return {
|
|
13
|
+
flaggedForTermination: false,
|
|
14
|
+
config: {
|
|
15
|
+
initialized: false,
|
|
16
|
+
persist: true,
|
|
17
|
+
requireCredentials: ["foo", "bar"],
|
|
18
|
+
},
|
|
19
|
+
global: false,
|
|
20
|
+
shutdown: sinon.stub(),
|
|
21
|
+
process: {
|
|
22
|
+
removeListener: sinon.stub(),
|
|
23
|
+
},
|
|
24
|
+
sessions: new Set(["session foo", "session bar"]),
|
|
25
|
+
sessionCallbacks: {
|
|
26
|
+
close: (() =>
|
|
27
|
+
new Map([
|
|
28
|
+
["session foo", function sessionFooClose() {}],
|
|
29
|
+
["session bar", function sessionBarClose() {}],
|
|
30
|
+
]))(),
|
|
31
|
+
message: (() =>
|
|
32
|
+
new Map([
|
|
33
|
+
["session foo", function sessionFooMessage() {}],
|
|
34
|
+
["session bar", function sessionBarMessage() {}],
|
|
35
|
+
]))(),
|
|
36
|
+
},
|
|
37
|
+
};
|
|
34
38
|
}
|
|
35
39
|
|
|
36
40
|
const cycleInterval = 10;
|
|
37
41
|
|
|
38
|
-
describe(
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
janitor.cycleInterval = cycleInterval;
|
|
56
|
-
expect(janitor.cycleInterval).to.equal(cycleInterval);
|
|
57
|
-
janitor.start();
|
|
58
|
-
setTimeout(() => {
|
|
59
|
-
expect(janitor.cycleCount).to.equal(1);
|
|
60
|
-
done();
|
|
61
|
-
}, cycleInterval)
|
|
62
|
-
});
|
|
63
|
-
|
|
64
|
-
afterEach((done) => {
|
|
65
|
-
sandbox.reset();
|
|
66
|
-
janitor.stop();
|
|
67
|
-
setTimeout(() => {
|
|
68
|
-
done();
|
|
69
|
-
}, janitor.cycleInterval * 2)
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
it('runs cycle at every cycleInterval', (done) => {
|
|
73
|
-
const currCycleCount = janitor.cycleCount;
|
|
74
|
-
expect(currCycleCount).to.not.equal(0);
|
|
75
|
-
setTimeout(() => {
|
|
76
|
-
expect(janitor.cycleCount).to.equal(currCycleCount + 1);
|
|
77
|
-
setTimeout(() => {
|
|
78
|
-
expect(janitor.cycleCount).to.equal(currCycleCount + 2);
|
|
79
|
-
done();
|
|
80
|
-
}, cycleInterval);
|
|
81
|
-
}, cycleInterval);
|
|
82
|
-
});
|
|
83
|
-
|
|
84
|
-
describe('removeSessionCallbacks', () => {
|
|
85
|
-
it('removes session listeners and callbacks for a given platform', () => {
|
|
86
|
-
const pi = getPlatformInstanceFake();
|
|
87
|
-
const barMessage = pi.sessionCallbacks.message.get('session bar');
|
|
88
|
-
const barClose = pi.sessionCallbacks.close.get('session bar');
|
|
89
|
-
pi.flaggedForTermination = true;
|
|
90
|
-
janitor.removeSessionCallbacks(pi, 'session foo');
|
|
91
|
-
sinon.assert.calledTwice(pi.process.removeListener);
|
|
92
|
-
expect(pi.sessionCallbacks.message.get('session foo')).to.be.undefined;
|
|
93
|
-
expect(pi.sessionCallbacks.message.get('session bar')).to.equal(barMessage);
|
|
94
|
-
expect(pi.sessionCallbacks.close.get('session foo')).to.be.undefined;
|
|
95
|
-
expect(pi.sessionCallbacks.close.get('session bar')).to.equal(barClose);
|
|
96
|
-
});
|
|
97
|
-
});
|
|
98
|
-
|
|
99
|
-
describe('removeStaleSocketSessions', () => {
|
|
100
|
-
it('doesnt do anything if the socket is active and stop is not flagged', async () => {
|
|
101
|
-
const pi = getPlatformInstanceFake();
|
|
102
|
-
janitor.removeSessionCallbacks = sinon.stub();
|
|
103
|
-
janitor.socketExists = sinon.stub().returns(true);
|
|
104
|
-
expect(janitor.stopTriggered).to.be.false;
|
|
105
|
-
await janitor.removeStaleSocketSessions(pi);
|
|
106
|
-
sinon.assert.notCalled(janitor.removeSessionCallbacks);
|
|
42
|
+
describe("Janitor", () => {
|
|
43
|
+
let sandbox, fetchSocketsFake, janitor;
|
|
44
|
+
|
|
45
|
+
beforeEach((done) => {
|
|
46
|
+
sandbox = sinon.createSandbox();
|
|
47
|
+
fetchSocketsFake = sandbox.stub().returns(sockets);
|
|
48
|
+
|
|
49
|
+
janitor = new Janitor();
|
|
50
|
+
janitor.getSockets = fetchSocketsFake;
|
|
51
|
+
expect(janitor.cycleInterval).not.toEqual(cycleInterval);
|
|
52
|
+
janitor.cycleInterval = cycleInterval;
|
|
53
|
+
expect(janitor.cycleInterval).toEqual(cycleInterval);
|
|
54
|
+
janitor.start();
|
|
55
|
+
setTimeout(() => {
|
|
56
|
+
expect(janitor.cycleCount).toEqual(1);
|
|
57
|
+
done();
|
|
58
|
+
}, cycleInterval);
|
|
107
59
|
});
|
|
108
60
|
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
await janitor.removeStaleSocketSessions(pi);
|
|
116
|
-
sinon.assert.calledTwice(janitor.removeSessionCallbacks);
|
|
117
|
-
sinon.assert.calledWith(janitor.removeSessionCallbacks, pi, 'session foo');
|
|
118
|
-
sinon.assert.calledWith(janitor.removeSessionCallbacks, pi, 'session bar');
|
|
61
|
+
afterEach((done) => {
|
|
62
|
+
sandbox.reset();
|
|
63
|
+
janitor.stop();
|
|
64
|
+
setTimeout(() => {
|
|
65
|
+
done();
|
|
66
|
+
}, janitor.cycleInterval * 2);
|
|
119
67
|
});
|
|
120
68
|
|
|
121
|
-
it(
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
69
|
+
it("runs cycle at every cycleInterval", (done) => {
|
|
70
|
+
const currCycleCount = janitor.cycleCount;
|
|
71
|
+
expect(currCycleCount).not.toEqual(0);
|
|
72
|
+
setTimeout(() => {
|
|
73
|
+
expect(janitor.cycleCount).toEqual(currCycleCount + 1);
|
|
74
|
+
setTimeout(() => {
|
|
75
|
+
expect(janitor.cycleCount).toEqual(currCycleCount + 2);
|
|
76
|
+
done();
|
|
77
|
+
}, cycleInterval);
|
|
78
|
+
}, cycleInterval);
|
|
129
79
|
});
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
80
|
+
|
|
81
|
+
describe("removeSessionCallbacks", () => {
|
|
82
|
+
it("removes session listeners and callbacks for a given platform", () => {
|
|
83
|
+
const pi = getPlatformInstanceFake();
|
|
84
|
+
const barMessage = pi.sessionCallbacks.message.get("session bar");
|
|
85
|
+
const barClose = pi.sessionCallbacks.close.get("session bar");
|
|
86
|
+
pi.flaggedForTermination = true;
|
|
87
|
+
janitor.removeSessionCallbacks(pi, "session foo");
|
|
88
|
+
sinon.assert.calledTwice(pi.process.removeListener);
|
|
89
|
+
expect(
|
|
90
|
+
pi.sessionCallbacks.message.get("session foo"),
|
|
91
|
+
).toBeUndefined();
|
|
92
|
+
expect(pi.sessionCallbacks.message.get("session bar")).toEqual(
|
|
93
|
+
barMessage,
|
|
94
|
+
);
|
|
95
|
+
expect(
|
|
96
|
+
pi.sessionCallbacks.close.get("session foo"),
|
|
97
|
+
).toBeUndefined();
|
|
98
|
+
expect(pi.sessionCallbacks.close.get("session bar")).toEqual(
|
|
99
|
+
barClose,
|
|
100
|
+
);
|
|
101
|
+
});
|
|
143
102
|
});
|
|
144
103
|
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
104
|
+
describe("removeStaleSocketSessions", () => {
|
|
105
|
+
it("doesnt do anything if the socket is active and stop is not flagged", async () => {
|
|
106
|
+
const pi = getPlatformInstanceFake();
|
|
107
|
+
janitor.removeSessionCallbacks = sinon.stub();
|
|
108
|
+
janitor.socketExists = sinon.stub().returns(true);
|
|
109
|
+
expect(janitor.stopTriggered).toBeFalse();
|
|
110
|
+
await janitor.removeStaleSocketSessions(pi);
|
|
111
|
+
sinon.assert.notCalled(janitor.removeSessionCallbacks);
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
it("removes session if the socket is active and stop is flagged", async () => {
|
|
115
|
+
const pi = getPlatformInstanceFake();
|
|
116
|
+
janitor.removeSessionCallbacks = sinon.stub();
|
|
117
|
+
janitor.socketExists = sinon.stub().returns(true);
|
|
118
|
+
janitor.stop();
|
|
119
|
+
expect(janitor.stopTriggered).toBeTrue();
|
|
120
|
+
await janitor.removeStaleSocketSessions(pi);
|
|
121
|
+
sinon.assert.calledTwice(janitor.removeSessionCallbacks);
|
|
122
|
+
sinon.assert.calledWith(
|
|
123
|
+
janitor.removeSessionCallbacks,
|
|
124
|
+
pi,
|
|
125
|
+
"session foo",
|
|
126
|
+
);
|
|
127
|
+
sinon.assert.calledWith(
|
|
128
|
+
janitor.removeSessionCallbacks,
|
|
129
|
+
pi,
|
|
130
|
+
"session bar",
|
|
131
|
+
);
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
it("removes session if the socket is inactive", async () => {
|
|
135
|
+
const pi = getPlatformInstanceFake();
|
|
136
|
+
janitor.removeSessionCallbacks = sinon.stub();
|
|
137
|
+
janitor.socketExists = sinon
|
|
138
|
+
.stub()
|
|
139
|
+
.onFirstCall()
|
|
140
|
+
.returns(false)
|
|
141
|
+
.onSecondCall()
|
|
142
|
+
.returns(true);
|
|
143
|
+
expect(janitor.stopTriggered).toBeFalse();
|
|
144
|
+
await janitor.removeStaleSocketSessions(pi);
|
|
145
|
+
sinon.assert.calledOnce(janitor.removeSessionCallbacks);
|
|
146
|
+
sinon.assert.calledWith(
|
|
147
|
+
janitor.removeSessionCallbacks,
|
|
148
|
+
pi,
|
|
149
|
+
"session foo",
|
|
150
|
+
);
|
|
151
|
+
});
|
|
155
152
|
});
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
153
|
+
|
|
154
|
+
describe("performStaleCheck", () => {
|
|
155
|
+
it("removes flagged and uninitialized platform instances", async () => {
|
|
156
|
+
const pi = getPlatformInstanceFake();
|
|
157
|
+
pi.flaggedForTermination = true;
|
|
158
|
+
pi.config.initialized = false;
|
|
159
|
+
janitor.removeStaleSocketSessions = sandbox.stub();
|
|
160
|
+
janitor.removeStalePlatformInstance = sandbox.stub();
|
|
161
|
+
await janitor.performStaleCheck(pi);
|
|
162
|
+
sinon.assert.calledOnce(janitor.removeStaleSocketSessions);
|
|
163
|
+
sinon.assert.calledOnce(janitor.removeStalePlatformInstance);
|
|
164
|
+
expect(pi.flaggedForTermination).toBeTrue();
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
it("flags for termination when there are not sockets", async () => {
|
|
168
|
+
const pi = getPlatformInstanceFake();
|
|
169
|
+
pi.sessions = new Set();
|
|
170
|
+
pi.flaggedForTermination = false;
|
|
171
|
+
pi.config.initialized = true;
|
|
172
|
+
janitor.removeStaleSocketSessions = sandbox.stub();
|
|
173
|
+
janitor.removeStalePlatformInstance = sandbox.stub();
|
|
174
|
+
await janitor.performStaleCheck(pi);
|
|
175
|
+
sinon.assert.calledOnce(janitor.removeStaleSocketSessions);
|
|
176
|
+
sinon.assert.calledOnce(janitor.removeStalePlatformInstance);
|
|
177
|
+
});
|
|
165
178
|
});
|
|
166
179
|
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
180
|
+
describe("removeStalePlatformInstance", () => {
|
|
181
|
+
it("flags stale platform", async () => {
|
|
182
|
+
const pi = getPlatformInstanceFake();
|
|
183
|
+
expect(pi.flaggedForTermination).toBeFalse();
|
|
184
|
+
await janitor.removeStalePlatformInstance(pi);
|
|
185
|
+
sinon.assert.notCalled(pi.shutdown);
|
|
186
|
+
expect(pi.flaggedForTermination).toBeTrue();
|
|
187
|
+
});
|
|
188
|
+
|
|
189
|
+
it("removes flagged stale platform", async () => {
|
|
190
|
+
const pi = getPlatformInstanceFake();
|
|
191
|
+
pi.flaggedForTermination = true;
|
|
192
|
+
await janitor.removeStalePlatformInstance(pi);
|
|
193
|
+
sinon.assert.calledOnce(pi.shutdown);
|
|
194
|
+
});
|
|
172
195
|
});
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
janitor.stop();
|
|
178
|
-
setTimeout(() => {
|
|
179
|
-
expect(janitor.cycleCount).to.equal(prevCycle);
|
|
180
|
-
setTimeout(() => {
|
|
181
|
-
expect(janitor.cycleCount).to.equal(prevCycle);
|
|
196
|
+
|
|
197
|
+
it("closes all connections when stop() is called", (done) => {
|
|
198
|
+
const prevCycle = janitor.cycleCount;
|
|
199
|
+
janitor.stop();
|
|
182
200
|
setTimeout(() => {
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
})
|
|
201
|
+
expect(janitor.cycleCount).toEqual(prevCycle);
|
|
202
|
+
setTimeout(() => {
|
|
203
|
+
expect(janitor.cycleCount).toEqual(prevCycle);
|
|
204
|
+
setTimeout(() => {
|
|
205
|
+
expect(janitor.cycleCount).toEqual(prevCycle);
|
|
206
|
+
done();
|
|
207
|
+
}, cycleInterval);
|
|
208
|
+
}, cycleInterval);
|
|
209
|
+
}, cycleInterval);
|
|
210
|
+
});
|
|
211
|
+
});
|