@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.
Files changed (105) hide show
  1. package/README.md +54 -60
  2. package/bin/sockethub +4 -3
  3. package/package.json +42 -54
  4. package/res/socket.io.js +4908 -0
  5. package/res/sockethub-client.js +602 -0
  6. package/res/sockethub-client.min.js +19 -0
  7. package/sockethub.config.example.json +2 -3
  8. package/src/bootstrap/init.d.ts +16 -13
  9. package/src/bootstrap/init.test.ts +211 -0
  10. package/src/bootstrap/init.ts +152 -76
  11. package/src/bootstrap/load-platforms.ts +151 -0
  12. package/src/config.test.ts +27 -22
  13. package/src/config.ts +82 -86
  14. package/src/defaults.json +24 -16
  15. package/src/index.ts +61 -22
  16. package/src/janitor.test.ts +191 -169
  17. package/src/janitor.ts +141 -118
  18. package/src/listener.ts +148 -58
  19. package/src/middleware/create-activity-object.test.ts +28 -8
  20. package/src/middleware/create-activity-object.ts +16 -10
  21. package/src/middleware/expand-activity-stream.test.data.ts +331 -345
  22. package/src/middleware/expand-activity-stream.test.ts +65 -66
  23. package/src/middleware/expand-activity-stream.ts +26 -21
  24. package/src/middleware/store-credentials.test.ts +74 -60
  25. package/src/middleware/store-credentials.ts +14 -8
  26. package/src/middleware/validate.test.data.ts +240 -242
  27. package/src/middleware/validate.test.ts +39 -78
  28. package/src/middleware/validate.ts +62 -36
  29. package/src/middleware.test.ts +168 -138
  30. package/src/middleware.ts +57 -55
  31. package/src/platform-instance.test.ts +508 -214
  32. package/src/platform-instance.ts +324 -231
  33. package/src/platform.test.ts +375 -0
  34. package/src/platform.ts +306 -117
  35. package/src/process-manager.ts +75 -51
  36. package/src/routes.test.ts +43 -89
  37. package/src/routes.ts +40 -78
  38. package/src/sentry.test.ts +106 -0
  39. package/src/sentry.ts +19 -0
  40. package/src/sockethub.ts +190 -129
  41. package/src/util.ts +5 -0
  42. package/coverage/tmp/coverage-39338-1663949520416-0.json +0 -1
  43. package/dist/bootstrap/init.d.ts +0 -18
  44. package/dist/bootstrap/init.js +0 -64
  45. package/dist/bootstrap/init.js.map +0 -1
  46. package/dist/bootstrap/platforms.js +0 -75
  47. package/dist/config.d.ts +0 -12
  48. package/dist/config.js +0 -107
  49. package/dist/config.js.map +0 -1
  50. package/dist/defaults.json +0 -28
  51. package/dist/index.d.ts +0 -1
  52. package/dist/index.js +0 -29
  53. package/dist/index.js.map +0 -1
  54. package/dist/janitor.d.ts +0 -30
  55. package/dist/janitor.js +0 -120
  56. package/dist/janitor.js.map +0 -1
  57. package/dist/listener.d.ts +0 -31
  58. package/dist/listener.js +0 -94
  59. package/dist/listener.js.map +0 -1
  60. package/dist/middleware/create-activity-object.d.ts +0 -8
  61. package/dist/middleware/create-activity-object.js +0 -19
  62. package/dist/middleware/create-activity-object.js.map +0 -1
  63. package/dist/middleware/expand-activity-stream.d.ts +0 -3
  64. package/dist/middleware/expand-activity-stream.js +0 -36
  65. package/dist/middleware/expand-activity-stream.js.map +0 -1
  66. package/dist/middleware/expand-activity-stream.test.data.d.ts +0 -480
  67. package/dist/middleware/expand-activity-stream.test.data.js +0 -360
  68. package/dist/middleware/expand-activity-stream.test.data.js.map +0 -1
  69. package/dist/middleware/store-credentials.d.ts +0 -3
  70. package/dist/middleware/store-credentials.js +0 -9
  71. package/dist/middleware/store-credentials.js.map +0 -1
  72. package/dist/middleware/validate.d.ts +0 -2
  73. package/dist/middleware/validate.js +0 -56
  74. package/dist/middleware/validate.js.map +0 -1
  75. package/dist/middleware/validate.test.data.d.ts +0 -532
  76. package/dist/middleware/validate.test.data.js +0 -263
  77. package/dist/middleware/validate.test.data.js.map +0 -1
  78. package/dist/middleware.d.ts +0 -21
  79. package/dist/middleware.js +0 -56
  80. package/dist/middleware.js.map +0 -1
  81. package/dist/platform-instance.d.ts +0 -78
  82. package/dist/platform-instance.js +0 -226
  83. package/dist/platform-instance.js.map +0 -1
  84. package/dist/platform.d.ts +0 -6
  85. package/dist/platform.js +0 -176
  86. package/dist/platform.js.map +0 -1
  87. package/dist/process-manager.d.ts +0 -11
  88. package/dist/process-manager.js +0 -82
  89. package/dist/process-manager.js.map +0 -1
  90. package/dist/routes.d.ts +0 -13
  91. package/dist/routes.js +0 -83
  92. package/dist/routes.js.map +0 -1
  93. package/dist/sockethub.d.ts +0 -18
  94. package/dist/sockethub.js +0 -112
  95. package/dist/sockethub.js.map +0 -1
  96. package/src/bootstrap/platforms.js +0 -75
  97. package/test/init-suite.js +0 -41
  98. package/test/sockethub-suite.js +0 -25
  99. package/tsconfig.json +0 -18
  100. package/views/examples/dummy.ejs +0 -95
  101. package/views/examples/feeds.ejs +0 -90
  102. package/views/examples/irc.ejs +0 -239
  103. package/views/examples/shared.js +0 -72
  104. package/views/examples/xmpp.ejs +0 -217
  105. package/views/index.ejs +0 -17
package/src/defaults.json CHANGED
@@ -1,20 +1,20 @@
1
1
  {
2
- "activity-streams": {
3
- "opts": {
4
- "specialObjs": [ "credentials" ]
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
- "examples": {
8
- "enabled": false,
9
- "secret": 1234567890
10
- },
11
- "sockethub": {
12
- "port": 10550,
13
- "host": "localhost",
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
- "host": "127.0.0.1",
26
- "port": 6379
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
- const sockethub = new Sockethub();
5
+ let sentry: { readonly reportError: (err: Error) => void } = {
6
+ reportError: (err: Error) => {},
7
+ };
4
8
 
5
- module.exports = async () => {
6
- process.once('uncaughtException', function (err) {
7
- console.log('UNCAUGHT EXCEPTION');
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
- process.once('SIGTERM', function () {
14
- console.log('Received TERM signal. Exiting.');
15
- process.exit(0);
16
- });
13
+ // conditionally initialize sentry
14
+ if (config.get("sentry:dsn")) {
15
+ log("initializing sentry");
16
+ sentry = await import("./sentry");
17
+ }
17
18
 
18
- process.once('SIGINT', function () {
19
- console.log('Received INT signal. Exiting.');
20
- process.exit(0);
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
- process.once('exit', async function () {
24
- console.log('destroying all platform instances');
25
- await sockethub.shutdown();
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
- sockethub.boot();
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
+ }
@@ -1,189 +1,211 @@
1
- import proxyquire from 'proxyquire';
2
- import { expect } from 'chai';
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
- let sockets = [
6
- { id: 'socket foo', emit: () => {} },
7
- { id: 'socket bar', emit: () => {} }
8
- ]
4
+ import { Janitor } from "./janitor.js";
9
5
 
10
- proxyquire.noPreserveCache();
11
- proxyquire.noCallThru();
6
+ const sockets = [
7
+ { id: "socket foo", emit: () => {} },
8
+ { id: "socket bar", emit: () => {} },
9
+ ];
12
10
 
13
11
  function getPlatformInstanceFake() {
14
- return {
15
- flaggedForTermination: false,
16
- initialized: false,
17
- global: false,
18
- shutdown: sinon.stub(),
19
- process: {
20
- removeListener: sinon.stub()
21
- },
22
- sessions: new Set(['session foo', 'session bar']),
23
- sessionCallbacks: {
24
- 'close': (() => new Map([
25
- ['session foo', function sessionFooClose() {}],
26
- ['session bar', function sessionBarClose() {}]
27
- ]))(),
28
- 'message': (() => new Map([
29
- ['session foo', function sessionFooMessage() {}],
30
- ['session bar', function sessionBarMessage() {}]
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('Janitor', () => {
39
- let sandbox, fetchSocketsFake, janitor;
40
-
41
- beforeEach(function (done) {
42
- this.timeout(3000);
43
- sandbox = sinon.createSandbox();
44
- fetchSocketsFake = sandbox.stub().returns(sockets);
45
- const janitorMod = proxyquire('./janitor', {
46
- listener: {
47
- io: {
48
- fetchSockets: fetchSocketsFake
49
- }
50
- }
51
- });
52
- janitor = janitorMod.default;
53
- janitor.getSockets = fetchSocketsFake;
54
- expect(janitor.cycleInterval).to.not.equal(cycleInterval);
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
- it('removes session if the socket is active and stop is flagged', async () => {
110
- const pi = getPlatformInstanceFake();
111
- janitor.removeSessionCallbacks = sinon.stub();
112
- janitor.socketExists = sinon.stub().returns(true);
113
- janitor.stop();
114
- expect(janitor.stopTriggered).to.be.true;
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('removes session if the socket is inactive', async () => {
122
- const pi = getPlatformInstanceFake();
123
- janitor.removeSessionCallbacks = sinon.stub();
124
- janitor.socketExists = sinon.stub().onFirstCall().returns(false).onSecondCall().returns(true);
125
- expect(janitor.stopTriggered).to.be.false;
126
- await janitor.removeStaleSocketSessions(pi);
127
- sinon.assert.calledOnce(janitor.removeSessionCallbacks);
128
- sinon.assert.calledWith(janitor.removeSessionCallbacks, pi, 'session foo');
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
- describe('performStaleCheck', () => {
133
- it('removes flagged and uninitialized platform instances', async () => {
134
- const pi = getPlatformInstanceFake();
135
- pi.flaggedForTermination = true;
136
- pi.initialized = false;
137
- janitor.removeStaleSocketSessions = sandbox.stub();
138
- janitor.removeStalePlatformInstance = sandbox.stub();
139
- await janitor.performStaleCheck(pi);
140
- sinon.assert.calledOnce(janitor.removeStaleSocketSessions);
141
- sinon.assert.calledOnce(janitor.removeStalePlatformInstance);
142
- expect(pi.flaggedForTermination).to.be.true;
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
- it('flags for termination when there are not sockets', async () => {
146
- const pi = getPlatformInstanceFake();
147
- pi.sessions = new Set();
148
- pi.flaggedForTermination = false;
149
- pi.initialized = true;
150
- janitor.removeStaleSocketSessions = sandbox.stub();
151
- janitor.removeStalePlatformInstance = sandbox.stub();
152
- await janitor.performStaleCheck(pi);
153
- sinon.assert.calledOnce(janitor.removeStaleSocketSessions);
154
- sinon.assert.calledOnce(janitor.removeStalePlatformInstance);
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
- describe('removeStalePlatformInstance', () => {
159
- it('flags stale platform', async () => {
160
- const pi = getPlatformInstanceFake();
161
- expect(pi.flaggedForTermination).to.be.false;
162
- await janitor.removeStalePlatformInstance(pi);
163
- sinon.assert.notCalled(pi.shutdown);
164
- expect(pi.flaggedForTermination).to.be.true;
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
- it('removes flagged stale platform', async () => {
168
- const pi = getPlatformInstanceFake();
169
- pi.flaggedForTermination = true;
170
- await janitor.removeStalePlatformInstance(pi);
171
- sinon.assert.calledOnce(pi.shutdown);
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
- it('closes all connections when stop() is called', (done) => {
176
- const prevCycle = janitor.cycleCount;
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
- expect(janitor.cycleCount).to.equal(prevCycle);
184
- done();
185
- }, cycleInterval)
186
- }, cycleInterval)
187
- }, cycleInterval);
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
+ });