@alwaysai/device-agent 1.5.0 → 2.0.1
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/lib/application-control/config.d.ts.map +1 -1
- package/lib/application-control/config.js +8 -3
- package/lib/application-control/config.js.map +1 -1
- package/lib/application-control/environment-variables.d.ts +5 -5
- package/lib/application-control/environment-variables.d.ts.map +1 -1
- package/lib/application-control/environment-variables.js +25 -38
- package/lib/application-control/environment-variables.js.map +1 -1
- package/lib/application-control/environment-variables.test.js +27 -7
- package/lib/application-control/environment-variables.test.js.map +1 -1
- package/lib/application-control/index.d.ts +4 -4
- package/lib/application-control/index.d.ts.map +1 -1
- package/lib/application-control/index.js +1 -4
- package/lib/application-control/index.js.map +1 -1
- package/lib/application-control/install.d.ts +4 -1
- package/lib/application-control/install.d.ts.map +1 -1
- package/lib/application-control/install.js +24 -8
- package/lib/application-control/install.js.map +1 -1
- package/lib/application-control/models.d.ts +0 -11
- package/lib/application-control/models.d.ts.map +1 -1
- package/lib/application-control/models.js +5 -54
- package/lib/application-control/models.js.map +1 -1
- package/lib/application-control/utils.d.ts +0 -4
- package/lib/application-control/utils.d.ts.map +1 -1
- package/lib/application-control/utils.js +12 -22
- package/lib/application-control/utils.js.map +1 -1
- package/lib/cloud-connection/base-message-handler.d.ts +27 -0
- package/lib/cloud-connection/base-message-handler.d.ts.map +1 -0
- package/lib/cloud-connection/base-message-handler.js +72 -0
- package/lib/cloud-connection/base-message-handler.js.map +1 -0
- package/lib/cloud-connection/bootstrap-provision.js +3 -2
- package/lib/cloud-connection/bootstrap-provision.js.map +1 -1
- package/lib/cloud-connection/connection-manager.d.ts +21 -0
- package/lib/cloud-connection/connection-manager.d.ts.map +1 -0
- package/lib/cloud-connection/connection-manager.js +158 -0
- package/lib/cloud-connection/connection-manager.js.map +1 -0
- package/lib/cloud-connection/device-agent-cloud-connection.d.ts +9 -30
- package/lib/cloud-connection/device-agent-cloud-connection.d.ts.map +1 -1
- package/lib/cloud-connection/device-agent-cloud-connection.js +69 -508
- package/lib/cloud-connection/device-agent-cloud-connection.js.map +1 -1
- package/lib/cloud-connection/device-agent-message-handler.d.ts +22 -0
- package/lib/cloud-connection/device-agent-message-handler.d.ts.map +1 -0
- package/lib/cloud-connection/device-agent-message-handler.js +357 -0
- package/lib/cloud-connection/device-agent-message-handler.js.map +1 -0
- package/lib/cloud-connection/device-agent.d.ts.map +1 -1
- package/lib/cloud-connection/device-agent.js +11 -9
- package/lib/cloud-connection/device-agent.js.map +1 -1
- package/lib/cloud-connection/live-updates-handler.d.ts +19 -28
- package/lib/cloud-connection/live-updates-handler.d.ts.map +1 -1
- package/lib/cloud-connection/live-updates-handler.js +60 -172
- package/lib/cloud-connection/live-updates-handler.js.map +1 -1
- package/lib/cloud-connection/live-updates-handler.test.js +71 -165
- package/lib/cloud-connection/live-updates-handler.test.js.map +1 -1
- package/lib/cloud-connection/message-dispatcher.d.ts +10 -0
- package/lib/cloud-connection/message-dispatcher.d.ts.map +1 -0
- package/lib/cloud-connection/message-dispatcher.js +27 -0
- package/lib/cloud-connection/message-dispatcher.js.map +1 -0
- package/lib/cloud-connection/passthrough-handler.d.ts +4 -1
- package/lib/cloud-connection/passthrough-handler.d.ts.map +1 -1
- package/lib/cloud-connection/passthrough-handler.js +30 -11
- package/lib/cloud-connection/passthrough-handler.js.map +1 -1
- package/lib/cloud-connection/shadow-handler.d.ts +11 -3
- package/lib/cloud-connection/shadow-handler.d.ts.map +1 -1
- package/lib/cloud-connection/shadow-handler.js +133 -28
- package/lib/cloud-connection/shadow-handler.js.map +1 -1
- package/lib/cloud-connection/shadow-handler.test.js +45 -57
- package/lib/cloud-connection/shadow-handler.test.js.map +1 -1
- package/lib/cloud-connection/shadow.d.ts.map +1 -1
- package/lib/cloud-connection/shadow.js +2 -1
- package/lib/cloud-connection/shadow.js.map +1 -1
- package/lib/cloud-connection/transaction-manager.d.ts +12 -3
- package/lib/cloud-connection/transaction-manager.d.ts.map +1 -1
- package/lib/cloud-connection/transaction-manager.js +29 -28
- package/lib/cloud-connection/transaction-manager.js.map +1 -1
- package/lib/cloud-connection/transaction-manager.test.js +46 -5
- package/lib/cloud-connection/transaction-manager.test.js.map +1 -1
- package/lib/device-control/device-control.d.ts +8 -8
- package/lib/device-control/device-control.d.ts.map +1 -1
- package/lib/device-control/device-control.js +95 -71
- package/lib/device-control/device-control.js.map +1 -1
- package/lib/docker/docker-compose.d.ts.map +1 -1
- package/lib/docker/docker-compose.js +2 -1
- package/lib/docker/docker-compose.js.map +1 -1
- package/lib/infrastructure/agent-config.d.ts +2 -1
- package/lib/infrastructure/agent-config.d.ts.map +1 -1
- package/lib/infrastructure/agent-config.js +7 -7
- package/lib/infrastructure/agent-config.js.map +1 -1
- package/lib/infrastructure/agent-config.test.js +3 -1
- package/lib/infrastructure/agent-config.test.js.map +1 -1
- package/lib/infrastructure/config-check-utility.d.ts +6 -0
- package/lib/infrastructure/config-check-utility.d.ts.map +1 -0
- package/lib/infrastructure/config-check-utility.js +67 -0
- package/lib/infrastructure/config-check-utility.js.map +1 -0
- package/lib/infrastructure/config-check-utility.test.d.ts +2 -0
- package/lib/infrastructure/config-check-utility.test.d.ts.map +1 -0
- package/lib/infrastructure/config-check-utility.test.js +109 -0
- package/lib/infrastructure/config-check-utility.test.js.map +1 -0
- package/lib/infrastructure/device-certificate.d.ts +10 -0
- package/lib/infrastructure/device-certificate.d.ts.map +1 -0
- package/lib/infrastructure/device-certificate.js +47 -0
- package/lib/infrastructure/device-certificate.js.map +1 -0
- package/lib/infrastructure/device-certificate.test.d.ts +2 -0
- package/lib/infrastructure/device-certificate.test.d.ts.map +1 -0
- package/lib/infrastructure/device-certificate.test.js +24 -0
- package/lib/infrastructure/device-certificate.test.js.map +1 -0
- package/lib/infrastructure/legacy-migration/legacy-file.test.d.ts +2 -0
- package/lib/infrastructure/legacy-migration/legacy-file.test.d.ts.map +1 -0
- package/lib/infrastructure/legacy-migration/legacy-file.test.js +61 -0
- package/lib/infrastructure/legacy-migration/legacy-file.test.js.map +1 -0
- package/lib/infrastructure/legacy-migration/legacy-files.d.ts +75 -0
- package/lib/infrastructure/legacy-migration/legacy-files.d.ts.map +1 -0
- package/lib/infrastructure/legacy-migration/legacy-files.js +75 -0
- package/lib/infrastructure/legacy-migration/legacy-files.js.map +1 -0
- package/lib/infrastructure/legacy-migration/legacy-migration.d.ts +6 -0
- package/lib/infrastructure/legacy-migration/legacy-migration.d.ts.map +1 -0
- package/lib/infrastructure/legacy-migration/legacy-migration.js +149 -0
- package/lib/infrastructure/legacy-migration/legacy-migration.js.map +1 -0
- package/lib/infrastructure/legacy-migration/legacy-migration.test.d.ts +2 -0
- package/lib/infrastructure/legacy-migration/legacy-migration.test.d.ts.map +1 -0
- package/lib/infrastructure/legacy-migration/legacy-migration.test.js +226 -0
- package/lib/infrastructure/legacy-migration/legacy-migration.test.js.map +1 -0
- package/lib/infrastructure/require-files-present-ready.test.d.ts +2 -0
- package/lib/infrastructure/require-files-present-ready.test.d.ts.map +1 -0
- package/lib/infrastructure/require-files-present-ready.test.js +44 -0
- package/lib/infrastructure/require-files-present-ready.test.js.map +1 -0
- package/lib/infrastructure/required-config-checks.d.ts +2 -0
- package/lib/infrastructure/required-config-checks.d.ts.map +1 -0
- package/lib/infrastructure/required-config-checks.js +30 -0
- package/lib/infrastructure/required-config-checks.js.map +1 -0
- package/lib/infrastructure/tokens-and-device-cfg.d.ts.map +1 -1
- package/lib/infrastructure/tokens-and-device-cfg.js +11 -8
- package/lib/infrastructure/tokens-and-device-cfg.js.map +1 -1
- package/lib/jobs/job-handler.d.ts +23 -0
- package/lib/jobs/job-handler.d.ts.map +1 -0
- package/lib/jobs/job-handler.js +131 -0
- package/lib/jobs/job-handler.js.map +1 -0
- package/lib/local-connection/rabbitmq-connection.d.ts.map +1 -1
- package/lib/local-connection/rabbitmq-connection.js +14 -14
- package/lib/local-connection/rabbitmq-connection.js.map +1 -1
- package/lib/secure-tunneling/secure-tunnel-message-handler.d.ts +8 -0
- package/lib/secure-tunneling/secure-tunnel-message-handler.d.ts.map +1 -0
- package/lib/secure-tunneling/secure-tunnel-message-handler.js +42 -0
- package/lib/secure-tunneling/secure-tunnel-message-handler.js.map +1 -0
- package/lib/secure-tunneling/secure-tunneling.d.ts +9 -9
- package/lib/secure-tunneling/secure-tunneling.d.ts.map +1 -1
- package/lib/secure-tunneling/secure-tunneling.js +21 -16
- package/lib/secure-tunneling/secure-tunneling.js.map +1 -1
- package/lib/secure-tunneling/secure-tunneling.test.js +11 -13
- package/lib/secure-tunneling/secure-tunneling.test.js.map +1 -1
- package/lib/subcommands/app/analytics.d.ts.map +1 -1
- package/lib/subcommands/app/analytics.js +1 -2
- package/lib/subcommands/app/analytics.js.map +1 -1
- package/lib/subcommands/app/env-vars.d.ts +4 -0
- package/lib/subcommands/app/env-vars.d.ts.map +1 -1
- package/lib/subcommands/app/env-vars.js +52 -6
- package/lib/subcommands/app/env-vars.js.map +1 -1
- package/lib/subcommands/app/index.d.ts.map +1 -1
- package/lib/subcommands/app/index.js +1 -3
- package/lib/subcommands/app/index.js.map +1 -1
- package/lib/subcommands/app/models.d.ts +0 -11
- package/lib/subcommands/app/models.d.ts.map +1 -1
- package/lib/subcommands/app/models.js +2 -58
- package/lib/subcommands/app/models.js.map +1 -1
- package/lib/subcommands/app/shadow.d.ts.map +1 -1
- package/lib/subcommands/app/shadow.js +6 -5
- package/lib/subcommands/app/shadow.js.map +1 -1
- package/lib/subcommands/app/version.d.ts +2 -0
- package/lib/subcommands/app/version.d.ts.map +1 -1
- package/lib/subcommands/app/version.js +16 -6
- package/lib/subcommands/app/version.js.map +1 -1
- package/lib/subcommands/config.d.ts +2 -0
- package/lib/subcommands/config.d.ts.map +1 -0
- package/lib/subcommands/config.js +39 -0
- package/lib/subcommands/config.js.map +1 -0
- package/lib/subcommands/device/clean.d.ts +1 -1
- package/lib/subcommands/device/clean.d.ts.map +1 -1
- package/lib/subcommands/device/clean.js +23 -13
- package/lib/subcommands/device/clean.js.map +1 -1
- package/lib/subcommands/device/index.d.ts.map +1 -1
- package/lib/subcommands/device/index.js +3 -1
- package/lib/subcommands/device/index.js.map +1 -1
- package/lib/subcommands/device/init.js +8 -8
- package/lib/subcommands/device/init.js.map +1 -1
- package/lib/subcommands/device/migrate.d.ts +2 -0
- package/lib/subcommands/device/migrate.d.ts.map +1 -0
- package/lib/subcommands/device/migrate.js +24 -0
- package/lib/subcommands/device/migrate.js.map +1 -0
- package/lib/subcommands/device/refresh.d.ts.map +1 -1
- package/lib/subcommands/device/refresh.js +1 -0
- package/lib/subcommands/device/refresh.js.map +1 -1
- package/lib/subcommands/index.d.ts +1 -1
- package/lib/subcommands/index.d.ts.map +1 -1
- package/lib/subcommands/index.js +3 -1
- package/lib/subcommands/index.js.map +1 -1
- package/lib/subcommands/rabbitmq-connection.d.ts +1 -1
- package/lib/subcommands/rabbitmq-connection.d.ts.map +1 -1
- package/lib/util/aai-error.d.ts +12 -0
- package/lib/util/aai-error.d.ts.map +1 -0
- package/lib/util/aai-error.js +11 -0
- package/lib/util/aai-error.js.map +1 -0
- package/lib/util/aws-regions.d.ts +2 -0
- package/lib/util/aws-regions.d.ts.map +1 -0
- package/lib/util/{cloud-mode-ready.js → aws-regions.js} +2 -20
- package/lib/util/aws-regions.js.map +1 -0
- package/lib/util/check-for-updates.d.ts.map +1 -1
- package/lib/util/check-for-updates.js +5 -28
- package/lib/util/check-for-updates.js.map +1 -1
- package/lib/util/clean-certs.d.ts.map +1 -1
- package/lib/util/clean-certs.js +5 -4
- package/lib/util/clean-certs.js.map +1 -1
- package/lib/util/directories.d.ts +4 -18
- package/lib/util/directories.d.ts.map +1 -1
- package/lib/util/directories.js +18 -32
- package/lib/util/directories.js.map +1 -1
- package/lib/util/file.d.ts +4 -0
- package/lib/util/file.d.ts.map +1 -1
- package/lib/util/file.js +65 -4
- package/lib/util/file.js.map +1 -1
- package/lib/util/get-device-id.d.ts.map +1 -1
- package/lib/util/get-device-id.js +7 -1
- package/lib/util/get-device-id.js.map +1 -1
- package/lib/util/http-client.js +3 -3
- package/lib/util/http-client.js.map +1 -1
- package/package.json +19 -17
- package/readme.md +12 -32
- package/src/application-control/config.ts +9 -12
- package/src/application-control/environment-variables.test.ts +28 -7
- package/src/application-control/environment-variables.ts +42 -59
- package/src/application-control/index.ts +3 -16
- package/src/application-control/install.ts +39 -13
- package/src/application-control/models.ts +6 -87
- package/src/application-control/utils.ts +10 -25
- package/src/cloud-connection/base-message-handler.ts +118 -0
- package/src/cloud-connection/bootstrap-provision.ts +7 -7
- package/src/cloud-connection/connection-manager.ts +187 -0
- package/src/cloud-connection/device-agent-cloud-connection.ts +130 -723
- package/src/cloud-connection/device-agent-message-handler.ts +642 -0
- package/src/cloud-connection/device-agent.ts +16 -7
- package/src/cloud-connection/live-updates-handler.test.ts +121 -189
- package/src/cloud-connection/live-updates-handler.ts +105 -232
- package/src/cloud-connection/message-dispatcher.ts +33 -0
- package/src/cloud-connection/passthrough-handler.ts +55 -18
- package/src/cloud-connection/shadow-handler.test.ts +45 -57
- package/src/cloud-connection/shadow-handler.ts +224 -54
- package/src/cloud-connection/shadow.ts +4 -1
- package/src/cloud-connection/transaction-manager.test.ts +68 -6
- package/src/cloud-connection/transaction-manager.ts +69 -41
- package/src/device-control/device-control.ts +102 -70
- package/src/docker/docker-compose.ts +3 -2
- package/src/infrastructure/agent-config.test.ts +6 -2
- package/src/infrastructure/agent-config.ts +8 -7
- package/src/infrastructure/config-check-utility.test.ts +154 -0
- package/src/infrastructure/config-check-utility.ts +77 -0
- package/src/infrastructure/device-certificate.test.ts +40 -0
- package/src/infrastructure/device-certificate.ts +58 -0
- package/src/infrastructure/legacy-migration/legacy-file.test.ts +88 -0
- package/src/infrastructure/legacy-migration/legacy-files.ts +101 -0
- package/src/infrastructure/legacy-migration/legacy-migration.test.ts +396 -0
- package/src/infrastructure/legacy-migration/legacy-migration.ts +229 -0
- package/src/infrastructure/require-files-present-ready.test.ts +53 -0
- package/src/infrastructure/required-config-checks.ts +33 -0
- package/src/infrastructure/tokens-and-device-cfg.ts +12 -10
- package/src/jobs/job-handler.ts +146 -0
- package/src/local-connection/rabbitmq-connection.ts +22 -17
- package/src/secure-tunneling/secure-tunnel-message-handler.ts +56 -0
- package/src/secure-tunneling/secure-tunneling.test.ts +20 -22
- package/src/secure-tunneling/secure-tunneling.ts +41 -29
- package/src/subcommands/app/analytics.ts +2 -4
- package/src/subcommands/app/env-vars.ts +72 -9
- package/src/subcommands/app/index.ts +3 -11
- package/src/subcommands/app/models.ts +5 -81
- package/src/subcommands/app/shadow.ts +6 -5
- package/src/subcommands/app/version.ts +23 -6
- package/src/subcommands/config.ts +42 -0
- package/src/subcommands/device/clean.ts +31 -17
- package/src/subcommands/device/index.ts +3 -1
- package/src/subcommands/device/init.ts +11 -11
- package/src/subcommands/device/migrate.ts +20 -0
- package/src/subcommands/device/refresh.ts +1 -0
- package/src/subcommands/index.ts +3 -1
- package/src/util/aai-error.ts +20 -0
- package/src/util/{cloud-mode-ready.ts → aws-regions.ts} +0 -24
- package/src/util/check-for-updates.ts +14 -30
- package/src/util/clean-certs.ts +8 -4
- package/src/util/directories.ts +23 -67
- package/src/util/file.ts +83 -3
- package/src/util/get-device-id.ts +7 -7
- package/src/util/http-client.ts +2 -2
- package/lib/util/cloud-mode-ready.d.ts +0 -3
- package/lib/util/cloud-mode-ready.d.ts.map +0 -1
- package/lib/util/cloud-mode-ready.js.map +0 -1
- package/lib/util/download-file.d.ts +0 -6
- package/lib/util/download-file.d.ts.map +0 -1
- package/lib/util/download-file.js +0 -25
- package/lib/util/download-file.js.map +0 -1
- package/lib/util/fetch-with-timeout.d.ts +0 -4
- package/lib/util/fetch-with-timeout.d.ts.map +0 -1
- package/lib/util/fetch-with-timeout.js +0 -30
- package/lib/util/fetch-with-timeout.js.map +0 -1
- package/lib/util/parsing.d.ts +0 -2
- package/lib/util/parsing.d.ts.map +0 -1
- package/lib/util/parsing.js +0 -17
- package/lib/util/parsing.js.map +0 -1
- package/src/util/download-file.ts +0 -25
- package/src/util/fetch-with-timeout.ts +0 -35
- package/src/util/parsing.ts +0 -11
|
@@ -1,230 +1,162 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import {
|
|
2
|
+
DEFAULT_INTERVALS_MS,
|
|
3
|
+
LiveUpdatesHandler
|
|
4
|
+
} from './live-updates-handler';
|
|
5
|
+
import { keyMirrors } from '@alwaysai/device-agent-schemas';
|
|
6
|
+
import { randomUUID } from 'crypto';
|
|
7
|
+
import { PassThrough } from 'stream';
|
|
5
8
|
|
|
6
9
|
jest.mock('../util/sleep');
|
|
7
10
|
jest.mock('./messages');
|
|
8
|
-
|
|
9
|
-
jest.mocked(getDeviceStatsPayload).mockResolvedValue({});
|
|
10
|
-
|
|
11
|
-
global.setTimeout = jest.fn() as unknown as typeof setTimeout;
|
|
11
|
+
jest.useFakeTimers();
|
|
12
12
|
|
|
13
13
|
// https://github.com/facebook/react-native/issues/35701
|
|
14
14
|
Object.defineProperty(global, 'performance', {
|
|
15
15
|
writable: true
|
|
16
16
|
});
|
|
17
17
|
|
|
18
|
-
const
|
|
19
|
-
|
|
20
|
-
appState: true
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
const testFalseToggles = {
|
|
24
|
-
deviceStats: false,
|
|
25
|
-
appState: false
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
const mockClient = {
|
|
29
|
-
publish: jest.fn()
|
|
30
|
-
};
|
|
31
|
-
const clientId = 'test-client';
|
|
32
|
-
const emptyTxId = '';
|
|
18
|
+
const mockTransactionId = '9b1deb4d-3b7d-4bad-9bdd-2b0d7b3dcb6d';
|
|
19
|
+
const mockProjectId = '12345678-abcd-abcd-abcd-0123456789ab';
|
|
33
20
|
|
|
34
21
|
describe('Test Live Updates Handler', () => {
|
|
35
22
|
let liveUpdatesHandler: LiveUpdatesHandler;
|
|
36
|
-
let publisher: Publisher;
|
|
37
23
|
|
|
38
24
|
beforeEach(() => {
|
|
39
|
-
|
|
40
|
-
jest.mocked(sleep).mockImplementation(async () => {
|
|
41
|
-
return;
|
|
42
|
-
});
|
|
43
|
-
publisher = new Publisher(mockClient, clientId);
|
|
44
|
-
liveUpdatesHandler = new LiveUpdatesHandler(publisher, clientId);
|
|
25
|
+
liveUpdatesHandler = new LiveUpdatesHandler();
|
|
45
26
|
jest.clearAllMocks();
|
|
46
27
|
});
|
|
47
28
|
|
|
48
|
-
test('enable
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
const enable = { deviceStats: true };
|
|
54
|
-
const promises = await liveUpdatesHandler.handleToggles(enable, emptyTxId);
|
|
55
|
-
await Promise.all(promises);
|
|
29
|
+
test('enable interval', async () => {
|
|
30
|
+
const mockPublishingFn = jest.fn();
|
|
31
|
+
const mockClearInterval = jest.spyOn(global, 'clearInterval');
|
|
32
|
+
const mockSetInterval = jest.spyOn(global, 'setInterval');
|
|
56
33
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
34
|
+
await liveUpdatesHandler.enable(
|
|
35
|
+
keyMirrors.toClientMessageType.device_stats,
|
|
36
|
+
mockPublishingFn
|
|
37
|
+
);
|
|
61
38
|
|
|
62
|
-
|
|
63
|
-
mockClient.publish = jest.fn().mockImplementation(async () => {
|
|
64
|
-
liveUpdatesHandler.disableAppStateLiveUpdates();
|
|
65
|
-
});
|
|
39
|
+
jest.advanceTimersByTime(DEFAULT_INTERVALS_MS);
|
|
66
40
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
expect(jest.mocked(setTimeout)).toBeCalledTimes(1);
|
|
72
|
-
expect(mockClient.publish).toBeCalledTimes(1);
|
|
73
|
-
expect(jest.mocked(sleep)).toBeCalledTimes(1);
|
|
41
|
+
expect(mockPublishingFn).toBeCalledTimes(2);
|
|
42
|
+
expect(mockClearInterval).toBeCalledWith(undefined);
|
|
43
|
+
expect(mockSetInterval).toBeCalledTimes(1);
|
|
74
44
|
});
|
|
75
45
|
|
|
76
|
-
test('
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
const
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
expect(
|
|
99
|
-
|
|
100
|
-
// Second call
|
|
101
|
-
jest.clearAllMocks();
|
|
102
|
-
|
|
103
|
-
await liveUpdatesHandler.handleToggles(enable, emptyTxId);
|
|
104
|
-
|
|
105
|
-
expect(jest.mocked(setTimeout)).toHaveBeenCalledTimes(1);
|
|
106
|
-
expect(mockClient.publish).toBeCalledTimes(0);
|
|
107
|
-
expect(jest.mocked(sleep)).toBeCalledTimes(0);
|
|
108
|
-
|
|
109
|
-
// Disable and clean up
|
|
110
|
-
liveUpdatesHandler.disableDeviceStatsLiveUpdates();
|
|
111
|
-
doneWaiting();
|
|
46
|
+
test('subsequent enable resets interval with no duplicates', async () => {
|
|
47
|
+
const mockPublishingFn = jest.fn();
|
|
48
|
+
const mockSetInterval = jest.spyOn(global, 'setInterval');
|
|
49
|
+
const mockClearInterval = jest.spyOn(global, 'clearInterval');
|
|
50
|
+
|
|
51
|
+
await liveUpdatesHandler.enable(
|
|
52
|
+
keyMirrors.toClientMessageType.device_stats,
|
|
53
|
+
mockPublishingFn,
|
|
54
|
+
mockTransactionId
|
|
55
|
+
);
|
|
56
|
+
await liveUpdatesHandler.enable(
|
|
57
|
+
keyMirrors.toClientMessageType.device_stats,
|
|
58
|
+
mockPublishingFn,
|
|
59
|
+
mockTransactionId
|
|
60
|
+
);
|
|
61
|
+
|
|
62
|
+
jest.advanceTimersByTime(DEFAULT_INTERVALS_MS);
|
|
63
|
+
|
|
64
|
+
expect(mockClearInterval.mock.calls[0][0]).toEqual(undefined);
|
|
65
|
+
expect(mockClearInterval.mock.calls[1][0]).toEqual(
|
|
66
|
+
mockSetInterval.mock.results[0].value
|
|
67
|
+
);
|
|
68
|
+
expect(mockSetInterval).toBeCalledTimes(2);
|
|
69
|
+
expect(mockPublishingFn).toBeCalledTimes(3);
|
|
112
70
|
});
|
|
113
71
|
|
|
114
72
|
test('test disable live updates', async () => {
|
|
115
|
-
|
|
116
|
-
const
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
startSleeping();
|
|
133
|
-
await waitPromise;
|
|
134
|
-
});
|
|
135
|
-
|
|
136
|
-
// Test calling handleToggles one time, enabling it
|
|
137
|
-
await liveUpdatesHandler.handleToggles(testTrueToggles, emptyTxId);
|
|
138
|
-
await sleepPromise;
|
|
139
|
-
|
|
140
|
-
expect(jest.mocked(setTimeout)).toHaveBeenCalledTimes(1);
|
|
141
|
-
expect(jest.mocked(sleep)).toBeCalledTimes(2);
|
|
142
|
-
expect(liveUpdatesHandler.getDeviceStatsLiveUpdates()).toBe(true);
|
|
143
|
-
expect(liveUpdatesHandler.getAppStateLiveUpdates()).toBe(true);
|
|
144
|
-
expect(liveUpdatesHandler.getAppLogsLiveUpdates()).toBe(false);
|
|
145
|
-
|
|
146
|
-
// Check to see that attributes are properly set to false when disabled
|
|
147
|
-
jest.clearAllMocks();
|
|
148
|
-
await liveUpdatesHandler.handleToggles(testFalseToggles, emptyTxId);
|
|
73
|
+
const mockSetInterval = jest.spyOn(global, 'setInterval');
|
|
74
|
+
const mockClearInterval = jest.spyOn(global, 'clearInterval');
|
|
75
|
+
|
|
76
|
+
await liveUpdatesHandler.enable(
|
|
77
|
+
keyMirrors.toClientMessageType.device_stats,
|
|
78
|
+
async () => undefined,
|
|
79
|
+
mockTransactionId
|
|
80
|
+
);
|
|
81
|
+
liveUpdatesHandler.disable(
|
|
82
|
+
keyMirrors.toClientMessageType.device_stats,
|
|
83
|
+
mockTransactionId
|
|
84
|
+
);
|
|
85
|
+
|
|
86
|
+
expect(mockClearInterval).toHaveBeenLastCalledWith(
|
|
87
|
+
mockSetInterval.mock.results[0].value
|
|
88
|
+
);
|
|
89
|
+
});
|
|
149
90
|
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
91
|
+
test('kill all timeout turns off all live updates', async () => {
|
|
92
|
+
const mockPublishingFn = jest.fn();
|
|
93
|
+
const mockSetInterval = jest.spyOn(global, 'setInterval');
|
|
94
|
+
const mockClearInterval = jest.spyOn(global, 'clearInterval');
|
|
95
|
+
jest.spyOn(global, 'setTimeout');
|
|
96
|
+
|
|
97
|
+
const numLivingIntervals = 5;
|
|
98
|
+
for (let i = 0; i < numLivingIntervals; i++) {
|
|
99
|
+
await liveUpdatesHandler.enable(
|
|
100
|
+
keyMirrors.toClientMessageType.status_response,
|
|
101
|
+
mockPublishingFn,
|
|
102
|
+
randomUUID()
|
|
103
|
+
);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
mockSetInterval.mock.results.forEach((result) =>
|
|
107
|
+
clearInterval(result.value)
|
|
108
|
+
);
|
|
109
|
+
jest.runAllTimers();
|
|
155
110
|
|
|
156
|
-
|
|
111
|
+
expect(mockPublishingFn).toBeCalledTimes(numLivingIntervals);
|
|
112
|
+
expect(mockSetInterval).toBeCalledTimes(numLivingIntervals);
|
|
113
|
+
for (let i = 0; i < numLivingIntervals; i++) {
|
|
114
|
+
expect(mockClearInterval).toHaveBeenCalledWith(
|
|
115
|
+
mockSetInterval.mock.results[i].value
|
|
116
|
+
);
|
|
117
|
+
}
|
|
157
118
|
});
|
|
158
119
|
|
|
159
|
-
test('
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
});
|
|
165
|
-
|
|
166
|
-
let startSleeping;
|
|
167
|
-
const sleepPromise = new Promise(function (resolve) {
|
|
168
|
-
startSleeping = resolve;
|
|
169
|
-
});
|
|
170
|
-
|
|
171
|
-
// Wait for two sleep calls, one for Device Stats and one for App State
|
|
172
|
-
jest
|
|
173
|
-
.mocked(sleep)
|
|
174
|
-
.mockImplementationOnce(async () => {
|
|
175
|
-
await waitPromise;
|
|
176
|
-
})
|
|
177
|
-
.mockImplementationOnce(async () => {
|
|
178
|
-
startSleeping();
|
|
179
|
-
await waitPromise;
|
|
180
|
-
});
|
|
120
|
+
test('startStream streams data to publish', async () => {
|
|
121
|
+
const mockStream = new PassThrough();
|
|
122
|
+
const mockPublishingFn = jest
|
|
123
|
+
.fn()
|
|
124
|
+
.mockImplementation((logChunk: string) => undefined);
|
|
181
125
|
|
|
182
|
-
await liveUpdatesHandler.
|
|
183
|
-
|
|
126
|
+
await liveUpdatesHandler.startStream(
|
|
127
|
+
mockProjectId,
|
|
128
|
+
async () => mockStream,
|
|
129
|
+
mockPublishingFn
|
|
130
|
+
);
|
|
184
131
|
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
expect(liveUpdatesHandler.getAppLogsLiveUpdates()).toBe(false);
|
|
188
|
-
|
|
189
|
-
jest.runAllTimers();
|
|
132
|
+
const data = 'Data for stream';
|
|
133
|
+
mockStream.emit('data', data);
|
|
190
134
|
|
|
191
|
-
expect(
|
|
192
|
-
expect(liveUpdatesHandler.getAppStateLiveUpdates()).toBe(false);
|
|
193
|
-
expect(liveUpdatesHandler.getAppLogsLiveUpdates()).toBe(false);
|
|
135
|
+
expect(mockPublishingFn).toBeCalledWith(data);
|
|
194
136
|
|
|
195
|
-
|
|
137
|
+
mockStream.end();
|
|
138
|
+
mockStream.destroy();
|
|
196
139
|
});
|
|
197
140
|
|
|
198
|
-
test(
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
let startSleeping;
|
|
206
|
-
const sleepPromise = new Promise(function (resolve) {
|
|
207
|
-
startSleeping = resolve;
|
|
208
|
-
});
|
|
209
|
-
jest
|
|
210
|
-
.mocked(sleep)
|
|
211
|
-
.mockImplementationOnce(async () => {
|
|
212
|
-
throw new Error('Test error!');
|
|
213
|
-
})
|
|
214
|
-
.mockImplementationOnce(async () => {
|
|
215
|
-
startSleeping();
|
|
216
|
-
await waitPromise;
|
|
141
|
+
test('failure does not disable interval', async () => {
|
|
142
|
+
const mockPublishingFn = jest
|
|
143
|
+
.fn()
|
|
144
|
+
.mockImplementationOnce(() => undefined)
|
|
145
|
+
.mockImplementation(() => {
|
|
146
|
+
throw new Error('Manual throw for unit test');
|
|
217
147
|
});
|
|
148
|
+
jest.spyOn(global, 'setInterval');
|
|
149
|
+
const mockClearInterval = jest.spyOn(global, 'clearInterval');
|
|
218
150
|
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
151
|
+
await liveUpdatesHandler.enable(
|
|
152
|
+
keyMirrors.toClientMessageType.device_stats,
|
|
153
|
+
mockPublishingFn,
|
|
154
|
+
mockTransactionId
|
|
155
|
+
);
|
|
222
156
|
|
|
223
|
-
|
|
224
|
-
expect(mockClient.publish).toBeCalledTimes(2);
|
|
225
|
-
expect(jest.mocked(sleep)).toBeCalledTimes(2);
|
|
157
|
+
jest.advanceTimersByTime(DEFAULT_INTERVALS_MS);
|
|
226
158
|
|
|
227
|
-
|
|
228
|
-
|
|
159
|
+
expect(mockClearInterval).toBeCalledTimes(1);
|
|
160
|
+
expect(mockPublishingFn).toBeCalledTimes(2);
|
|
229
161
|
});
|
|
230
162
|
});
|