@hatchet-dev/typescript-sdk 0.0.2 → 0.0.3
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 +2 -3
- package/dist/clients/admin/admin-client.d.ts +1 -1
- package/dist/clients/admin/admin-client.js +1 -1
- package/dist/clients/dispatcher/action-listener.d.ts +2 -2
- package/dist/clients/dispatcher/dispatcher-client.d.ts +2 -2
- package/dist/clients/dispatcher/dispatcher-client.js +1 -1
- package/dist/clients/event/event-client.d.ts +2 -2
- package/dist/clients/event/event-client.js +1 -1
- package/dist/clients/hatchet-client/hatchet-client.d.ts +2 -2
- package/dist/clients/hatchet-client/hatchet-client.js +1 -1
- package/dist/clients/worker/worker.d.ts +3 -3
- package/dist/clients/worker/worker.js +3 -3
- package/package.json +4 -2
- package/dist/clients/admin/admin-client.test.d.ts +0 -1
- package/dist/clients/admin/admin-client.test.js +0 -101
- package/dist/clients/dispatcher/action-listener.test.d.ts +0 -4
- package/dist/clients/dispatcher/action-listener.test.js +0 -277
- package/dist/clients/dispatcher/dispatcher-client.test.d.ts +0 -1
- package/dist/clients/dispatcher/dispatcher-client.test.js +0 -99
- package/dist/clients/event/event-client.test.d.ts +0 -1
- package/dist/clients/event/event-client.test.js +0 -60
- package/dist/clients/hatchet-client/hatchet-client.test.d.ts +0 -2
- package/dist/clients/hatchet-client/hatchet-client.test.js +0 -135
- package/dist/clients/worker/worker.test.d.ts +0 -1
- package/dist/clients/worker/worker.test.js +0 -256
- package/dist/util/config-loader/config-loader.test.d.ts +0 -1
- package/dist/util/config-loader/config-loader.test.js +0 -72
- package/dist/util/hatchet-promise/hatchet-promise.test.d.ts +0 -1
- package/dist/util/hatchet-promise/hatchet-promise.test.js +0 -40
package/README.md
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
# Hatchet - Typescript
|
|
1
|
+
# Hatchet - Typescript SDK
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
https://google.github.io/proto-lens/installing-protoc.html
|
|
3
|
+
Please refer to the [Hatchet Typescript SDK documentation](https://docs.hatchet.run/typescript-sdk/setup) for setup instructions and usage details.
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Channel, ClientFactory } from 'nice-grpc';
|
|
2
|
-
import { CreateWorkflowVersionOpts, WorkflowServiceClient } from '
|
|
2
|
+
import { CreateWorkflowVersionOpts, WorkflowServiceClient } from '../../protoc/workflows';
|
|
3
3
|
import { ClientConfig } from '../hatchet-client/client-config';
|
|
4
4
|
export declare class AdminClient {
|
|
5
5
|
config: ClientConfig;
|
|
@@ -13,7 +13,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
13
13
|
};
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
exports.AdminClient = void 0;
|
|
16
|
-
const workflows_1 = require("
|
|
16
|
+
const workflows_1 = require("../../protoc/workflows");
|
|
17
17
|
const hatchet_error_1 = __importDefault(require("../../util/errors/hatchet-error"));
|
|
18
18
|
class AdminClient {
|
|
19
19
|
constructor(config, channel, factory) {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { DispatcherClient as PbDispatcherClient, AssignedAction } from '
|
|
1
|
+
import { DispatcherClient as PbDispatcherClient, AssignedAction } from '../../protoc/dispatcher';
|
|
2
2
|
import { ClientConfig } from '../hatchet-client/client-config';
|
|
3
3
|
import { DispatcherClient } from './dispatcher-client';
|
|
4
4
|
export interface Action {
|
|
@@ -20,5 +20,5 @@ export declare class ActionListener {
|
|
|
20
20
|
constructor(client: DispatcherClient, listener: AsyncIterable<AssignedAction>, workerId: string);
|
|
21
21
|
actions: () => AsyncGenerator<Action, void, unknown>;
|
|
22
22
|
retrySubscribe(): Promise<void>;
|
|
23
|
-
unregister(): Promise<import("
|
|
23
|
+
unregister(): Promise<import("../../protoc/dispatcher").WorkerUnsubscribeResponse>;
|
|
24
24
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Channel, ClientFactory } from 'nice-grpc';
|
|
2
|
-
import { DispatcherClient as PbDispatcherClient, ActionEvent } from '
|
|
2
|
+
import { DispatcherClient as PbDispatcherClient, ActionEvent } from '../../protoc/dispatcher';
|
|
3
3
|
import { ClientConfig } from '../hatchet-client/client-config';
|
|
4
4
|
import { ActionListener } from './action-listener';
|
|
5
5
|
interface GetActionListenerOptions {
|
|
@@ -12,6 +12,6 @@ export declare class DispatcherClient {
|
|
|
12
12
|
client: PbDispatcherClient;
|
|
13
13
|
constructor(config: ClientConfig, channel: Channel, factory: ClientFactory);
|
|
14
14
|
get_action_listener(options: GetActionListenerOptions): Promise<ActionListener>;
|
|
15
|
-
send_action_event(in_: ActionEvent): Promise<import("
|
|
15
|
+
send_action_event(in_: ActionEvent): Promise<import("../../protoc/dispatcher").ActionEventResponse>;
|
|
16
16
|
}
|
|
17
17
|
export {};
|
|
@@ -13,7 +13,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
13
13
|
};
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
exports.DispatcherClient = void 0;
|
|
16
|
-
const dispatcher_1 = require("
|
|
16
|
+
const dispatcher_1 = require("../../protoc/dispatcher");
|
|
17
17
|
const hatchet_error_1 = __importDefault(require("../../util/errors/hatchet-error"));
|
|
18
18
|
const action_listener_1 = require("./action-listener");
|
|
19
19
|
class DispatcherClient {
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { Channel, ClientFactory } from 'nice-grpc';
|
|
2
|
-
import { EventsServiceClient } from '
|
|
2
|
+
import { EventsServiceClient } from '../../protoc/events/events';
|
|
3
3
|
import { ClientConfig } from '../hatchet-client/client-config';
|
|
4
4
|
export declare class EventClient {
|
|
5
5
|
config: ClientConfig;
|
|
6
6
|
client: EventsServiceClient;
|
|
7
7
|
constructor(config: ClientConfig, channel: Channel, factory: ClientFactory);
|
|
8
|
-
push<T>(type: string, input: T): Promise<import("
|
|
8
|
+
push<T>(type: string, input: T): Promise<import("../../protoc/events/events").Event>;
|
|
9
9
|
}
|
|
@@ -4,7 +4,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.EventClient = void 0;
|
|
7
|
-
const events_1 = require("
|
|
7
|
+
const events_1 = require("../../protoc/events/events");
|
|
8
8
|
const hatchet_error_1 = __importDefault(require("../../util/errors/hatchet-error"));
|
|
9
9
|
class EventClient {
|
|
10
10
|
constructor(config, channel, factory) {
|
|
@@ -2,9 +2,9 @@ import { EventClient } from '../event/event-client';
|
|
|
2
2
|
import { DispatcherClient } from '../dispatcher/dispatcher-client';
|
|
3
3
|
import { AdminClient } from '../admin/admin-client';
|
|
4
4
|
import { Channel, ChannelCredentials } from 'nice-grpc';
|
|
5
|
-
import { Workflow } from '
|
|
5
|
+
import { Workflow } from '../../workflow';
|
|
6
6
|
import { Worker } from '../worker';
|
|
7
|
-
import Logger from '
|
|
7
|
+
import Logger from '../../util/logger/logger';
|
|
8
8
|
import { ClientConfig } from './client-config';
|
|
9
9
|
export interface HatchetClientOptions {
|
|
10
10
|
config_path?: string;
|
|
@@ -45,7 +45,7 @@ const dispatcher_client_1 = require("../dispatcher/dispatcher-client");
|
|
|
45
45
|
const admin_client_1 = require("../admin/admin-client");
|
|
46
46
|
const nice_grpc_1 = require("nice-grpc");
|
|
47
47
|
const worker_1 = require("../worker");
|
|
48
|
-
const logger_1 = __importDefault(require("
|
|
48
|
+
const logger_1 = __importDefault(require("../../util/logger/logger"));
|
|
49
49
|
const client_config_1 = require("./client-config");
|
|
50
50
|
const addTokenMiddleware = (token) => function _(call, options) {
|
|
51
51
|
return __asyncGenerator(this, arguments, function* _1() {
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { HatchetClient } from '../hatchet-client';
|
|
2
2
|
import { Action, ActionListener } from '../dispatcher/action-listener';
|
|
3
|
-
import { ActionEvent, ActionEventType } from '
|
|
3
|
+
import { ActionEvent, ActionEventType } from '../../protoc/dispatcher';
|
|
4
4
|
import HatchetPromise from '../../util/hatchet-promise/hatchet-promise';
|
|
5
|
-
import { Workflow } from '
|
|
6
|
-
import { Logger } from '
|
|
5
|
+
import { Workflow } from '../../workflow';
|
|
6
|
+
import { Logger } from '../../util/logger';
|
|
7
7
|
export type ActionRegistry = Record<Action['actionId'], Function>;
|
|
8
8
|
export declare class Worker {
|
|
9
9
|
serviceName: string;
|
|
@@ -21,10 +21,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
21
21
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
22
22
|
exports.Worker = void 0;
|
|
23
23
|
const hatchet_error_1 = __importDefault(require("../../util/errors/hatchet-error"));
|
|
24
|
-
const dispatcher_1 = require("
|
|
24
|
+
const dispatcher_1 = require("../../protoc/dispatcher");
|
|
25
25
|
const hatchet_promise_1 = __importDefault(require("../../util/hatchet-promise/hatchet-promise"));
|
|
26
|
-
const logger_1 = require("
|
|
27
|
-
const sleep_1 = __importDefault(require("
|
|
26
|
+
const logger_1 = require("../../util/logger");
|
|
27
|
+
const sleep_1 = __importDefault(require("../../util/sleep"));
|
|
28
28
|
const step_1 = require("../../step");
|
|
29
29
|
class Worker {
|
|
30
30
|
constructor(client, options) {
|
package/package.json
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hatchet-dev/typescript-sdk",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.3",
|
|
4
4
|
"description": "Background task orchestration & visibility for developers",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
7
7
|
"files": [
|
|
8
|
-
"dist"
|
|
8
|
+
"dist",
|
|
9
|
+
"!**/*.test.js",
|
|
10
|
+
"!**/*.test.d.ts"
|
|
9
11
|
],
|
|
10
12
|
"repository": {
|
|
11
13
|
"type": "git",
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,101 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
const admin_client_1 = require("./admin-client");
|
|
13
|
-
const hatchet_client_test_1 = require("../hatchet-client/hatchet-client.test");
|
|
14
|
-
describe('AdminClient', () => {
|
|
15
|
-
let client;
|
|
16
|
-
it('should create a client', () => {
|
|
17
|
-
const x = new admin_client_1.AdminClient({
|
|
18
|
-
token: 'TOKEN',
|
|
19
|
-
host_port: 'HOST_PORT',
|
|
20
|
-
tls_config: {
|
|
21
|
-
cert_file: 'TLS_CERT_FILE',
|
|
22
|
-
key_file: 'TLS_KEY_FILE',
|
|
23
|
-
ca_file: 'TLS_ROOT_CA_FILE',
|
|
24
|
-
server_name: 'TLS_SERVER_NAME',
|
|
25
|
-
},
|
|
26
|
-
}, hatchet_client_test_1.mockChannel, hatchet_client_test_1.mockFactory);
|
|
27
|
-
expect(x).toBeDefined();
|
|
28
|
-
});
|
|
29
|
-
beforeEach(() => {
|
|
30
|
-
client = new admin_client_1.AdminClient({
|
|
31
|
-
token: 'TOKEN',
|
|
32
|
-
host_port: 'HOST_PORT',
|
|
33
|
-
tls_config: {
|
|
34
|
-
cert_file: 'TLS_CERT_FILE',
|
|
35
|
-
key_file: 'TLS_KEY_FILE',
|
|
36
|
-
ca_file: 'TLS_ROOT_CA_FILE',
|
|
37
|
-
server_name: 'TLS_SERVER_NAME',
|
|
38
|
-
},
|
|
39
|
-
}, hatchet_client_test_1.mockChannel, hatchet_client_test_1.mockFactory);
|
|
40
|
-
});
|
|
41
|
-
describe('put_workflow', () => {
|
|
42
|
-
it('should throw an error if no version and not auto version', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
43
|
-
const workflow = {
|
|
44
|
-
name: 'workflow1',
|
|
45
|
-
version: '',
|
|
46
|
-
description: 'description1',
|
|
47
|
-
eventTriggers: [],
|
|
48
|
-
cronTriggers: [],
|
|
49
|
-
scheduledTriggers: [],
|
|
50
|
-
jobs: [],
|
|
51
|
-
};
|
|
52
|
-
expect(() => client.put_workflow(workflow, { autoVersion: false })).rejects.toThrow('PutWorkflow error: workflow version is required, or use autoVersion');
|
|
53
|
-
}));
|
|
54
|
-
it('should attempt to put the workflow', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
55
|
-
const workflow = {
|
|
56
|
-
name: 'workflow1',
|
|
57
|
-
version: 'v0.0.1',
|
|
58
|
-
description: 'description1',
|
|
59
|
-
eventTriggers: [],
|
|
60
|
-
cronTriggers: [],
|
|
61
|
-
scheduledTriggers: [],
|
|
62
|
-
jobs: [],
|
|
63
|
-
};
|
|
64
|
-
const putSpy = jest.spyOn(client.client, 'putWorkflow').mockResolvedValue({
|
|
65
|
-
id: 'workflow1',
|
|
66
|
-
version: 'v0.1.0',
|
|
67
|
-
order: 1,
|
|
68
|
-
workflowId: 'workflow1',
|
|
69
|
-
jobs: [],
|
|
70
|
-
createdAt: undefined,
|
|
71
|
-
updatedAt: undefined,
|
|
72
|
-
triggers: undefined,
|
|
73
|
-
});
|
|
74
|
-
yield client.put_workflow(workflow);
|
|
75
|
-
expect(putSpy).toHaveBeenCalled();
|
|
76
|
-
}));
|
|
77
|
-
});
|
|
78
|
-
describe('schedule_workflow', () => {
|
|
79
|
-
it('should schedule a workflow', () => {
|
|
80
|
-
const res = {
|
|
81
|
-
id: 'string',
|
|
82
|
-
version: 'v0.0.1',
|
|
83
|
-
order: 1,
|
|
84
|
-
workflowId: 'string',
|
|
85
|
-
jobs: [],
|
|
86
|
-
createdAt: undefined,
|
|
87
|
-
updatedAt: undefined,
|
|
88
|
-
triggers: undefined,
|
|
89
|
-
};
|
|
90
|
-
const spy = jest.spyOn(client.client, 'scheduleWorkflow').mockResolvedValue(res);
|
|
91
|
-
const now = new Date();
|
|
92
|
-
client.schedule_workflow('workflowId', {
|
|
93
|
-
schedules: [now],
|
|
94
|
-
});
|
|
95
|
-
expect(spy).toHaveBeenCalledWith({
|
|
96
|
-
workflowId: 'workflowId',
|
|
97
|
-
schedules: [now],
|
|
98
|
-
});
|
|
99
|
-
});
|
|
100
|
-
});
|
|
101
|
-
});
|
|
@@ -1,277 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
var __await = (this && this.__await) || function (v) { return this instanceof __await ? (this.v = v, this) : new __await(v); }
|
|
12
|
-
var __asyncGenerator = (this && this.__asyncGenerator) || function (thisArg, _arguments, generator) {
|
|
13
|
-
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
|
|
14
|
-
var g = generator.apply(thisArg, _arguments || []), i, q = [];
|
|
15
|
-
return i = {}, verb("next"), verb("throw"), verb("return", awaitReturn), i[Symbol.asyncIterator] = function () { return this; }, i;
|
|
16
|
-
function awaitReturn(f) { return function (v) { return Promise.resolve(v).then(f, reject); }; }
|
|
17
|
-
function verb(n, f) { if (g[n]) { i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; if (f) i[n] = f(i[n]); } }
|
|
18
|
-
function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }
|
|
19
|
-
function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }
|
|
20
|
-
function fulfill(value) { resume("next", value); }
|
|
21
|
-
function reject(value) { resume("throw", value); }
|
|
22
|
-
function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); }
|
|
23
|
-
};
|
|
24
|
-
var __asyncValues = (this && this.__asyncValues) || function (o) {
|
|
25
|
-
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
|
|
26
|
-
var m = o[Symbol.asyncIterator], i;
|
|
27
|
-
return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
|
|
28
|
-
function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
|
|
29
|
-
function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
|
|
30
|
-
};
|
|
31
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
32
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
33
|
-
};
|
|
34
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
35
|
-
exports.mockListener = void 0;
|
|
36
|
-
const dispatcher_1 = require("@hatchet/protoc/dispatcher");
|
|
37
|
-
const sleep_1 = __importDefault(require("../../util/sleep"));
|
|
38
|
-
const nice_grpc_common_1 = require("nice-grpc-common");
|
|
39
|
-
const dispatcher_client_1 = require("./dispatcher-client");
|
|
40
|
-
const action_listener_1 = require("./action-listener");
|
|
41
|
-
const hatchet_client_test_1 = require("../hatchet-client/hatchet-client.test");
|
|
42
|
-
let dispatcher;
|
|
43
|
-
// Mock data for AssignedAction
|
|
44
|
-
const mockAssignedActions = [
|
|
45
|
-
{
|
|
46
|
-
tenantId: 'tenant1',
|
|
47
|
-
jobId: 'job1',
|
|
48
|
-
jobName: 'Job One',
|
|
49
|
-
jobRunId: 'run1',
|
|
50
|
-
stepId: 'step1',
|
|
51
|
-
stepRunId: 'runStep1',
|
|
52
|
-
actionId: 'action1',
|
|
53
|
-
actionType: dispatcher_1.ActionType.START_STEP_RUN,
|
|
54
|
-
actionPayload: 'payload1',
|
|
55
|
-
},
|
|
56
|
-
// ... Add more mock AssignedAction objects as needed
|
|
57
|
-
];
|
|
58
|
-
// Mock implementation of the listener
|
|
59
|
-
const mockListener = (fixture) => (function gen() {
|
|
60
|
-
return __asyncGenerator(this, arguments, function* gen_1() {
|
|
61
|
-
for (const action of fixture) {
|
|
62
|
-
// Simulate asynchronous behavior
|
|
63
|
-
yield __await((0, sleep_1.default)(100));
|
|
64
|
-
if (action instanceof Error) {
|
|
65
|
-
throw action;
|
|
66
|
-
}
|
|
67
|
-
yield yield __await(action);
|
|
68
|
-
}
|
|
69
|
-
});
|
|
70
|
-
})();
|
|
71
|
-
exports.mockListener = mockListener;
|
|
72
|
-
describe('ActionListener', () => {
|
|
73
|
-
beforeEach(() => {
|
|
74
|
-
dispatcher = new dispatcher_client_1.DispatcherClient({
|
|
75
|
-
token: 'TOKEN',
|
|
76
|
-
host_port: 'HOST_PORT',
|
|
77
|
-
log_level: 'OFF',
|
|
78
|
-
tls_config: {
|
|
79
|
-
cert_file: 'TLS_CERT_FILE',
|
|
80
|
-
key_file: 'TLS_KEY_FILE',
|
|
81
|
-
ca_file: 'TLS_ROOT_CA_FILE',
|
|
82
|
-
server_name: 'TLS_SERVER_NAME',
|
|
83
|
-
},
|
|
84
|
-
}, hatchet_client_test_1.mockChannel, hatchet_client_test_1.mockFactory);
|
|
85
|
-
});
|
|
86
|
-
it('should create a client', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
87
|
-
const listener = new action_listener_1.ActionListener(dispatcher, (0, exports.mockListener)(mockAssignedActions), 'WORKER_ID');
|
|
88
|
-
expect(listener).toBeDefined();
|
|
89
|
-
expect(listener.workerId).toEqual('WORKER_ID');
|
|
90
|
-
}));
|
|
91
|
-
describe('actions', () => {
|
|
92
|
-
it('it should "yield" actions', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
93
|
-
var _a, e_1, _b, _c;
|
|
94
|
-
const listener = new action_listener_1.ActionListener(dispatcher, (0, exports.mockListener)([...mockAssignedActions, new nice_grpc_common_1.ServerError(nice_grpc_common_1.Status.CANCELLED, 'CANCELLED')]), 'WORKER_ID');
|
|
95
|
-
const actions = listener.actions();
|
|
96
|
-
const res = [];
|
|
97
|
-
try {
|
|
98
|
-
for (var _d = true, actions_1 = __asyncValues(actions), actions_1_1; actions_1_1 = yield actions_1.next(), _a = actions_1_1.done, !_a; _d = true) {
|
|
99
|
-
_c = actions_1_1.value;
|
|
100
|
-
_d = false;
|
|
101
|
-
const action = _c;
|
|
102
|
-
res.push(action);
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
106
|
-
finally {
|
|
107
|
-
try {
|
|
108
|
-
if (!_d && !_a && (_b = actions_1.return)) yield _b.call(actions_1);
|
|
109
|
-
}
|
|
110
|
-
finally { if (e_1) throw e_1.error; }
|
|
111
|
-
}
|
|
112
|
-
expect(res[0]).toEqual({
|
|
113
|
-
tenantId: 'tenant1',
|
|
114
|
-
jobId: 'job1',
|
|
115
|
-
jobName: 'Job One',
|
|
116
|
-
jobRunId: 'run1',
|
|
117
|
-
stepId: 'step1',
|
|
118
|
-
stepRunId: 'runStep1',
|
|
119
|
-
actionId: 'action1',
|
|
120
|
-
actionType: dispatcher_1.ActionType.START_STEP_RUN,
|
|
121
|
-
actionPayload: 'payload1',
|
|
122
|
-
});
|
|
123
|
-
}));
|
|
124
|
-
it('it should break on grpc CANCELLED', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
125
|
-
var _e, e_2, _f, _g;
|
|
126
|
-
const listener = new action_listener_1.ActionListener(dispatcher, (0, exports.mockListener)([...mockAssignedActions, new nice_grpc_common_1.ServerError(nice_grpc_common_1.Status.CANCELLED, 'CANCELLED')]), 'WORKER_ID');
|
|
127
|
-
const actions = listener.actions();
|
|
128
|
-
const retrySpy = jest.spyOn(listener, 'retrySubscribe').mockResolvedValue(undefined);
|
|
129
|
-
const res = [];
|
|
130
|
-
try {
|
|
131
|
-
for (var _h = true, actions_2 = __asyncValues(actions), actions_2_1; actions_2_1 = yield actions_2.next(), _e = actions_2_1.done, !_e; _h = true) {
|
|
132
|
-
_g = actions_2_1.value;
|
|
133
|
-
_h = false;
|
|
134
|
-
const action = _g;
|
|
135
|
-
res.push(action);
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
139
|
-
finally {
|
|
140
|
-
try {
|
|
141
|
-
if (!_h && !_e && (_f = actions_2.return)) yield _f.call(actions_2);
|
|
142
|
-
}
|
|
143
|
-
finally { if (e_2) throw e_2.error; }
|
|
144
|
-
}
|
|
145
|
-
expect(res.length).toEqual(1);
|
|
146
|
-
expect(retrySpy).not.toHaveBeenCalled();
|
|
147
|
-
}));
|
|
148
|
-
it('it should break on unknown error', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
149
|
-
var _j, e_3, _k, _l;
|
|
150
|
-
const listener = new action_listener_1.ActionListener(dispatcher, (0, exports.mockListener)([...mockAssignedActions, new Error('Simulated error')]), 'WORKER_ID');
|
|
151
|
-
const actions = listener.actions();
|
|
152
|
-
const retrySpy = jest.spyOn(listener, 'retrySubscribe').mockResolvedValue(undefined);
|
|
153
|
-
const res = [];
|
|
154
|
-
try {
|
|
155
|
-
for (var _m = true, actions_3 = __asyncValues(actions), actions_3_1; actions_3_1 = yield actions_3.next(), _j = actions_3_1.done, !_j; _m = true) {
|
|
156
|
-
_l = actions_3_1.value;
|
|
157
|
-
_m = false;
|
|
158
|
-
const action = _l;
|
|
159
|
-
res.push(action);
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
catch (e_3_1) { e_3 = { error: e_3_1 }; }
|
|
163
|
-
finally {
|
|
164
|
-
try {
|
|
165
|
-
if (!_m && !_j && (_k = actions_3.return)) yield _k.call(actions_3);
|
|
166
|
-
}
|
|
167
|
-
finally { if (e_3) throw e_3.error; }
|
|
168
|
-
}
|
|
169
|
-
expect(res.length).toEqual(1);
|
|
170
|
-
expect(retrySpy).not.toHaveBeenCalled();
|
|
171
|
-
}));
|
|
172
|
-
it('it should attempt to re-establish connection on grpc UNAVAILABLE', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
173
|
-
var _o, e_4, _p, _q;
|
|
174
|
-
const listener = new action_listener_1.ActionListener(dispatcher, (0, exports.mockListener)([...mockAssignedActions, new nice_grpc_common_1.ServerError(nice_grpc_common_1.Status.UNAVAILABLE, 'UNAVAILABLE')]), 'WORKER_ID');
|
|
175
|
-
const retrySpy = jest.spyOn(listener, 'retrySubscribe').mockResolvedValue(undefined);
|
|
176
|
-
const actions = listener.actions();
|
|
177
|
-
const res = [];
|
|
178
|
-
try {
|
|
179
|
-
for (var _r = true, actions_4 = __asyncValues(actions), actions_4_1; actions_4_1 = yield actions_4.next(), _o = actions_4_1.done, !_o; _r = true) {
|
|
180
|
-
_q = actions_4_1.value;
|
|
181
|
-
_r = false;
|
|
182
|
-
const action = _q;
|
|
183
|
-
res.push(action);
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
catch (e_4_1) { e_4 = { error: e_4_1 }; }
|
|
187
|
-
finally {
|
|
188
|
-
try {
|
|
189
|
-
if (!_r && !_o && (_p = actions_4.return)) yield _p.call(actions_4);
|
|
190
|
-
}
|
|
191
|
-
finally { if (e_4) throw e_4.error; }
|
|
192
|
-
}
|
|
193
|
-
expect(res.length).toEqual(1);
|
|
194
|
-
expect(retrySpy).toHaveBeenCalled();
|
|
195
|
-
}));
|
|
196
|
-
});
|
|
197
|
-
describe('retry_subscribe', () => {
|
|
198
|
-
it('should exit after successful connection', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
199
|
-
const listener = new action_listener_1.ActionListener(dispatcher, (0, exports.mockListener)(mockAssignedActions), 'WORKER_ID');
|
|
200
|
-
// Mock the listener to throw an error on the first call
|
|
201
|
-
const listenSpy = jest
|
|
202
|
-
.spyOn(listener.client, 'listen')
|
|
203
|
-
.mockReturnValue((0, exports.mockListener)(mockAssignedActions));
|
|
204
|
-
yield listener.retrySubscribe();
|
|
205
|
-
expect(listenSpy).toHaveBeenCalledTimes(1);
|
|
206
|
-
}));
|
|
207
|
-
it('should retry until success', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
208
|
-
const listener = new action_listener_1.ActionListener(dispatcher, (0, exports.mockListener)(mockAssignedActions), 'WORKER_ID');
|
|
209
|
-
// Mock the listener to throw an error on the first call
|
|
210
|
-
const listenSpy = jest
|
|
211
|
-
.spyOn(listener.client, 'listen')
|
|
212
|
-
.mockImplementationOnce(() => {
|
|
213
|
-
throw new Error('Simulated error');
|
|
214
|
-
})
|
|
215
|
-
.mockImplementationOnce(() => (0, exports.mockListener)(mockAssignedActions));
|
|
216
|
-
yield expect(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
217
|
-
yield listener.retrySubscribe();
|
|
218
|
-
})).not.toThrow();
|
|
219
|
-
}));
|
|
220
|
-
it('should not throw an error if successful', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
221
|
-
const listener = new action_listener_1.ActionListener(dispatcher, (0, exports.mockListener)(mockAssignedActions), 'WORKER_ID');
|
|
222
|
-
// Mock the listener to throw an error on the first call
|
|
223
|
-
const listenSpy = jest
|
|
224
|
-
.spyOn(listener.client, 'listen')
|
|
225
|
-
.mockImplementationOnce(() => {
|
|
226
|
-
throw new Error('Simulated error');
|
|
227
|
-
})
|
|
228
|
-
.mockImplementationOnce(() => (0, exports.mockListener)(mockAssignedActions));
|
|
229
|
-
yield listener.retrySubscribe();
|
|
230
|
-
expect(listenSpy).toHaveBeenCalledTimes(2);
|
|
231
|
-
}));
|
|
232
|
-
it('should retry at most COUNT times and throw an error', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
233
|
-
const listener = new action_listener_1.ActionListener(dispatcher, (0, exports.mockListener)(mockAssignedActions), 'WORKER_ID');
|
|
234
|
-
// Mock the listener to throw an error on the first call
|
|
235
|
-
const listenSpy = jest
|
|
236
|
-
.spyOn(listener.client, 'listen')
|
|
237
|
-
.mockImplementationOnce(() => {
|
|
238
|
-
throw new Error('Simulated error');
|
|
239
|
-
})
|
|
240
|
-
.mockImplementationOnce(() => {
|
|
241
|
-
throw new Error('Simulated error');
|
|
242
|
-
})
|
|
243
|
-
.mockImplementationOnce(() => {
|
|
244
|
-
throw new Error('Simulated error');
|
|
245
|
-
})
|
|
246
|
-
.mockImplementationOnce(() => {
|
|
247
|
-
throw new Error('Simulated error');
|
|
248
|
-
})
|
|
249
|
-
.mockImplementationOnce(() => {
|
|
250
|
-
throw new Error('Simulated error');
|
|
251
|
-
})
|
|
252
|
-
.mockImplementationOnce(() => {
|
|
253
|
-
throw new Error('Simulated error');
|
|
254
|
-
})
|
|
255
|
-
.mockImplementationOnce(() => (0, exports.mockListener)(mockAssignedActions));
|
|
256
|
-
try {
|
|
257
|
-
yield listener.retrySubscribe();
|
|
258
|
-
expect(listenSpy).toHaveBeenCalledTimes(5);
|
|
259
|
-
}
|
|
260
|
-
catch (e) {
|
|
261
|
-
expect(e.message).toEqual(`Could not subscribe to the worker after 5 retries`);
|
|
262
|
-
}
|
|
263
|
-
}));
|
|
264
|
-
});
|
|
265
|
-
describe('unregister', () => {
|
|
266
|
-
it('should unsubscribe itself', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
267
|
-
const listener = new action_listener_1.ActionListener(dispatcher, (0, exports.mockListener)(mockAssignedActions), 'WORKER_ID');
|
|
268
|
-
const unsubscribeSpy = jest.spyOn(listener.client, 'unsubscribe').mockResolvedValue({
|
|
269
|
-
tenantId: 'TENANT_ID',
|
|
270
|
-
workerId: 'WORKER_ID',
|
|
271
|
-
});
|
|
272
|
-
const res = yield listener.unregister();
|
|
273
|
-
expect(unsubscribeSpy).toHaveBeenCalled();
|
|
274
|
-
expect(res.workerId).toEqual('WORKER_ID');
|
|
275
|
-
}));
|
|
276
|
-
});
|
|
277
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,99 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
const dispatcher_1 = require("@hatchet/protoc/dispatcher");
|
|
13
|
-
const dispatcher_client_1 = require("./dispatcher-client");
|
|
14
|
-
const hatchet_client_test_1 = require("../hatchet-client/hatchet-client.test");
|
|
15
|
-
let client;
|
|
16
|
-
describe('DispatcherClient', () => {
|
|
17
|
-
it('should create a client', () => {
|
|
18
|
-
const x = new dispatcher_client_1.DispatcherClient({
|
|
19
|
-
token: 'TOKEN',
|
|
20
|
-
host_port: 'HOST_PORT',
|
|
21
|
-
log_level: 'OFF',
|
|
22
|
-
tls_config: {
|
|
23
|
-
cert_file: 'TLS_CERT_FILE',
|
|
24
|
-
key_file: 'TLS_KEY_FILE',
|
|
25
|
-
ca_file: 'TLS_ROOT_CA_FILE',
|
|
26
|
-
server_name: 'TLS_SERVER_NAME',
|
|
27
|
-
},
|
|
28
|
-
}, hatchet_client_test_1.mockChannel, hatchet_client_test_1.mockFactory);
|
|
29
|
-
expect(x).toBeDefined();
|
|
30
|
-
});
|
|
31
|
-
beforeEach(() => {
|
|
32
|
-
client = new dispatcher_client_1.DispatcherClient({
|
|
33
|
-
token: 'TOKEN',
|
|
34
|
-
host_port: 'HOST_PORT',
|
|
35
|
-
log_level: 'OFF',
|
|
36
|
-
tls_config: {
|
|
37
|
-
cert_file: 'TLS_CERT_FILE',
|
|
38
|
-
key_file: 'TLS_KEY_FILE',
|
|
39
|
-
ca_file: 'TLS_ROOT_CA_FILE',
|
|
40
|
-
server_name: 'TLS_SERVER_NAME',
|
|
41
|
-
},
|
|
42
|
-
}, hatchet_client_test_1.mockChannel, hatchet_client_test_1.mockFactory);
|
|
43
|
-
});
|
|
44
|
-
describe('get_action_listener', () => {
|
|
45
|
-
it('should register the worker', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
46
|
-
const clientSpy = jest.spyOn(client.client, 'register').mockResolvedValue({
|
|
47
|
-
workerId: 'WORKER_ID',
|
|
48
|
-
tenantId: 'TENANT_ID',
|
|
49
|
-
workerName: 'WORKER_NAME',
|
|
50
|
-
});
|
|
51
|
-
const listenerSpy = jest.spyOn(client.client, 'listen');
|
|
52
|
-
const listener = yield client.get_action_listener({
|
|
53
|
-
workerName: 'WORKER_NAME',
|
|
54
|
-
services: ['SERVICE'],
|
|
55
|
-
actions: ['ACTION'],
|
|
56
|
-
});
|
|
57
|
-
expect(clientSpy).toHaveBeenCalledWith({
|
|
58
|
-
workerName: 'WORKER_NAME',
|
|
59
|
-
services: ['SERVICE'],
|
|
60
|
-
actions: ['ACTION'],
|
|
61
|
-
});
|
|
62
|
-
expect(listenerSpy).toHaveBeenCalledWith({
|
|
63
|
-
workerId: 'WORKER_ID',
|
|
64
|
-
});
|
|
65
|
-
expect(listener).toBeDefined();
|
|
66
|
-
expect(listener.workerId).toEqual('WORKER_ID');
|
|
67
|
-
}));
|
|
68
|
-
});
|
|
69
|
-
describe('send_action_event', () => {
|
|
70
|
-
it('should send action events', () => {
|
|
71
|
-
const clientSpy = jest.spyOn(client.client, 'sendActionEvent').mockResolvedValue({
|
|
72
|
-
tenantId: 'TENANT_ID',
|
|
73
|
-
workerId: 'WORKER_ID',
|
|
74
|
-
});
|
|
75
|
-
client.send_action_event({
|
|
76
|
-
workerId: 'WORKER_ID',
|
|
77
|
-
actionId: 'ACTION_ID',
|
|
78
|
-
eventType: dispatcher_1.ActionEventType.STEP_EVENT_TYPE_COMPLETED,
|
|
79
|
-
eventPayload: '{"foo":"bar"}',
|
|
80
|
-
eventTimestamp: new Date(),
|
|
81
|
-
jobId: 'a',
|
|
82
|
-
jobRunId: 'b',
|
|
83
|
-
stepId: 'c',
|
|
84
|
-
stepRunId: 'd',
|
|
85
|
-
});
|
|
86
|
-
expect(clientSpy).toHaveBeenCalledWith({
|
|
87
|
-
workerId: 'WORKER_ID',
|
|
88
|
-
actionId: 'ACTION_ID',
|
|
89
|
-
eventType: dispatcher_1.ActionEventType.STEP_EVENT_TYPE_COMPLETED,
|
|
90
|
-
eventPayload: '{"foo":"bar"}',
|
|
91
|
-
jobId: 'a',
|
|
92
|
-
jobRunId: 'b',
|
|
93
|
-
stepId: 'c',
|
|
94
|
-
stepRunId: 'd',
|
|
95
|
-
eventTimestamp: expect.any(Object),
|
|
96
|
-
});
|
|
97
|
-
});
|
|
98
|
-
});
|
|
99
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const hatchet_error_1 = __importDefault(require("../../util/errors/hatchet-error"));
|
|
7
|
-
const event_client_1 = require("./event-client");
|
|
8
|
-
const hatchet_client_test_1 = require("../hatchet-client/hatchet-client.test");
|
|
9
|
-
let client;
|
|
10
|
-
describe('EventClient', () => {
|
|
11
|
-
it('should create a client', () => {
|
|
12
|
-
const x = new event_client_1.EventClient({
|
|
13
|
-
token: 'TOKEN',
|
|
14
|
-
host_port: 'HOST_PORT',
|
|
15
|
-
tls_config: {
|
|
16
|
-
cert_file: 'TLS_CERT_FILE',
|
|
17
|
-
key_file: 'TLS_KEY_FILE',
|
|
18
|
-
ca_file: 'TLS_ROOT_CA_FILE',
|
|
19
|
-
server_name: 'TLS_SERVER_NAME',
|
|
20
|
-
},
|
|
21
|
-
}, hatchet_client_test_1.mockChannel, hatchet_client_test_1.mockFactory);
|
|
22
|
-
expect(x).toBeDefined();
|
|
23
|
-
});
|
|
24
|
-
beforeEach(() => {
|
|
25
|
-
client = new event_client_1.EventClient({
|
|
26
|
-
token: 'TOKEN',
|
|
27
|
-
host_port: 'HOST_PORT',
|
|
28
|
-
tls_config: {
|
|
29
|
-
cert_file: 'TLS_CERT_FILE',
|
|
30
|
-
key_file: 'TLS_KEY_FILE',
|
|
31
|
-
ca_file: 'TLS_ROOT_CA_FILE',
|
|
32
|
-
server_name: 'TLS_SERVER_NAME',
|
|
33
|
-
},
|
|
34
|
-
}, hatchet_client_test_1.mockChannel, hatchet_client_test_1.mockFactory);
|
|
35
|
-
});
|
|
36
|
-
it('should push events', () => {
|
|
37
|
-
const clientSpy = jest.spyOn(client.client, 'push').mockResolvedValue({
|
|
38
|
-
tenantId: 'x',
|
|
39
|
-
eventId: 'y',
|
|
40
|
-
key: 'z',
|
|
41
|
-
eventTimestamp: new Date(),
|
|
42
|
-
payload: 'string',
|
|
43
|
-
});
|
|
44
|
-
client.push('type', { foo: 'bar' });
|
|
45
|
-
expect(clientSpy).toHaveBeenCalledWith({
|
|
46
|
-
key: 'type',
|
|
47
|
-
payload: '{"foo":"bar"}',
|
|
48
|
-
eventTimestamp: expect.any(Date),
|
|
49
|
-
});
|
|
50
|
-
});
|
|
51
|
-
it('should throw an error when push fails', () => {
|
|
52
|
-
const clientSpy = jest.spyOn(client.client, 'push');
|
|
53
|
-
clientSpy.mockImplementation(() => {
|
|
54
|
-
throw new Error('foo');
|
|
55
|
-
});
|
|
56
|
-
expect(() => {
|
|
57
|
-
client.push('type', { foo: 'bar' });
|
|
58
|
-
}).toThrow(new hatchet_error_1.default('foo'));
|
|
59
|
-
});
|
|
60
|
-
});
|
|
@@ -1,135 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.mockFactory = exports.mockChannel = void 0;
|
|
4
|
-
const nice_grpc_1 = require("nice-grpc");
|
|
5
|
-
const hatchet_client_1 = require("./hatchet-client");
|
|
6
|
-
exports.mockChannel = (0, nice_grpc_1.createChannel)('localhost:50051');
|
|
7
|
-
exports.mockFactory = (0, nice_grpc_1.createClientFactory)();
|
|
8
|
-
describe('Client', () => {
|
|
9
|
-
beforeEach(() => {
|
|
10
|
-
process.env.HATCHET_CLIENT_TOKEN = 'TOKEN_ENV';
|
|
11
|
-
});
|
|
12
|
-
it('should load from environment variables', () => {
|
|
13
|
-
const hatchet = new hatchet_client_1.HatchetClient({
|
|
14
|
-
token: 'TOKEN_ENV',
|
|
15
|
-
host_port: 'HOST_PORT',
|
|
16
|
-
log_level: 'OFF',
|
|
17
|
-
tls_config: {
|
|
18
|
-
cert_file: 'TLS_CERT_FILE',
|
|
19
|
-
key_file: 'TLS_KEY_FILE',
|
|
20
|
-
ca_file: 'TLS_ROOT_CA_FILE',
|
|
21
|
-
server_name: 'TLS_SERVER_NAME',
|
|
22
|
-
},
|
|
23
|
-
}, {
|
|
24
|
-
credentials: nice_grpc_1.ChannelCredentials.createInsecure(),
|
|
25
|
-
});
|
|
26
|
-
expect(hatchet.config).toEqual({
|
|
27
|
-
token: 'TOKEN_ENV',
|
|
28
|
-
host_port: 'HOST_PORT',
|
|
29
|
-
log_level: 'OFF',
|
|
30
|
-
tls_config: {
|
|
31
|
-
tls_strategy: 'tls',
|
|
32
|
-
cert_file: 'TLS_CERT_FILE',
|
|
33
|
-
key_file: 'TLS_KEY_FILE',
|
|
34
|
-
ca_file: 'TLS_ROOT_CA_FILE',
|
|
35
|
-
server_name: 'TLS_SERVER_NAME',
|
|
36
|
-
},
|
|
37
|
-
});
|
|
38
|
-
});
|
|
39
|
-
it('should throw an error if the config param is invalid', () => {
|
|
40
|
-
expect(() => new hatchet_client_1.HatchetClient({
|
|
41
|
-
host_port: 'HOST_PORT',
|
|
42
|
-
tls_config: {
|
|
43
|
-
tls_strategy: 'tls',
|
|
44
|
-
cert_file: 'TLS_CERT_FILE',
|
|
45
|
-
key_file: 'TLS_KEY_FILE',
|
|
46
|
-
ca_file: 'TLS_ROOT_CA_FILE',
|
|
47
|
-
// @ts-ignore
|
|
48
|
-
server_name: undefined,
|
|
49
|
-
},
|
|
50
|
-
})).toThrow();
|
|
51
|
-
});
|
|
52
|
-
it('should favor config param over yaml over env vars ', () => {
|
|
53
|
-
const hatchet = new hatchet_client_1.HatchetClient({
|
|
54
|
-
tls_config: {
|
|
55
|
-
cert_file: 'TLS_CERT_FILE',
|
|
56
|
-
key_file: 'TLS_KEY_FILE',
|
|
57
|
-
ca_file: 'TLS_ROOT_CA_FILE',
|
|
58
|
-
server_name: 'TLS_SERVER_NAME',
|
|
59
|
-
},
|
|
60
|
-
}, {
|
|
61
|
-
config_path: './fixtures/.hatchet.yaml',
|
|
62
|
-
credentials: nice_grpc_1.ChannelCredentials.createInsecure(),
|
|
63
|
-
});
|
|
64
|
-
expect(hatchet.config).toEqual({
|
|
65
|
-
token: 'TOKEN_YAML',
|
|
66
|
-
host_port: 'HOST_PORT_YAML',
|
|
67
|
-
log_level: 'INFO',
|
|
68
|
-
tls_config: {
|
|
69
|
-
tls_strategy: 'tls',
|
|
70
|
-
cert_file: 'TLS_CERT_FILE',
|
|
71
|
-
key_file: 'TLS_KEY_FILE',
|
|
72
|
-
ca_file: 'TLS_ROOT_CA_FILE',
|
|
73
|
-
server_name: 'TLS_SERVER_NAME',
|
|
74
|
-
},
|
|
75
|
-
});
|
|
76
|
-
});
|
|
77
|
-
describe('with_host_port', () => {
|
|
78
|
-
it('should set the host_port', () => {
|
|
79
|
-
const hatchet = hatchet_client_1.HatchetClient.with_host_port('HOST', 1234, {
|
|
80
|
-
token: 'TOKEN',
|
|
81
|
-
tls_config: {
|
|
82
|
-
tls_strategy: 'tls',
|
|
83
|
-
cert_file: 'TLS_CERT_FILE',
|
|
84
|
-
key_file: 'TLS_KEY_FILE',
|
|
85
|
-
ca_file: 'TLS_ROOT_CA_FILE',
|
|
86
|
-
server_name: 'TLS_SERVER_NAME',
|
|
87
|
-
},
|
|
88
|
-
}, {
|
|
89
|
-
credentials: nice_grpc_1.ChannelCredentials.createInsecure(),
|
|
90
|
-
});
|
|
91
|
-
expect(hatchet.config).toEqual({
|
|
92
|
-
token: 'TOKEN',
|
|
93
|
-
host_port: 'HOST:1234',
|
|
94
|
-
log_level: 'INFO',
|
|
95
|
-
tls_config: {
|
|
96
|
-
tls_strategy: 'tls',
|
|
97
|
-
cert_file: 'TLS_CERT_FILE',
|
|
98
|
-
key_file: 'TLS_KEY_FILE',
|
|
99
|
-
ca_file: 'TLS_ROOT_CA_FILE',
|
|
100
|
-
server_name: 'TLS_SERVER_NAME',
|
|
101
|
-
},
|
|
102
|
-
});
|
|
103
|
-
});
|
|
104
|
-
});
|
|
105
|
-
describe('Worker', () => {
|
|
106
|
-
let hatchet;
|
|
107
|
-
beforeEach(() => {
|
|
108
|
-
hatchet = new hatchet_client_1.HatchetClient({
|
|
109
|
-
token: 'TOKEN',
|
|
110
|
-
host_port: 'HOST_PORT',
|
|
111
|
-
log_level: 'OFF',
|
|
112
|
-
tls_config: {
|
|
113
|
-
cert_file: 'TLS_CERT_FILE',
|
|
114
|
-
key_file: 'TLS_KEY_FILE',
|
|
115
|
-
ca_file: 'TLS_ROOT_CA_FILE',
|
|
116
|
-
server_name: 'TLS_SERVER_NAME',
|
|
117
|
-
},
|
|
118
|
-
}, {
|
|
119
|
-
credentials: nice_grpc_1.ChannelCredentials.createInsecure(),
|
|
120
|
-
});
|
|
121
|
-
});
|
|
122
|
-
describe('run', () => {
|
|
123
|
-
xit('should start a worker', () => {
|
|
124
|
-
const worker = hatchet.run('workflow1');
|
|
125
|
-
expect(worker).toBeDefined();
|
|
126
|
-
});
|
|
127
|
-
});
|
|
128
|
-
describe('worker', () => {
|
|
129
|
-
it('should start a worker', () => {
|
|
130
|
-
const worker = hatchet.worker('workflow1');
|
|
131
|
-
expect(worker).toBeDefined();
|
|
132
|
-
});
|
|
133
|
-
});
|
|
134
|
-
});
|
|
135
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,256 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
-
};
|
|
14
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
const hatchet_client_1 = require("../hatchet-client");
|
|
16
|
-
const dispatcher_1 = require("@hatchet/protoc/dispatcher");
|
|
17
|
-
const action_listener_1 = require("../dispatcher/action-listener");
|
|
18
|
-
const nice_grpc_common_1 = require("nice-grpc-common");
|
|
19
|
-
const action_listener_test_1 = require("../dispatcher/action-listener.test");
|
|
20
|
-
const zod_1 = require("zod");
|
|
21
|
-
const sleep_1 = __importDefault(require("../../util/sleep"));
|
|
22
|
-
const nice_grpc_1 = require("nice-grpc");
|
|
23
|
-
const worker_1 = require("./worker");
|
|
24
|
-
const mockStart = {
|
|
25
|
-
tenantId: 'TENANT_ID',
|
|
26
|
-
jobId: 'job1',
|
|
27
|
-
jobName: 'Job One',
|
|
28
|
-
jobRunId: 'run1',
|
|
29
|
-
stepId: 'step1',
|
|
30
|
-
stepRunId: 'runStep1',
|
|
31
|
-
actionId: 'action1',
|
|
32
|
-
actionType: dispatcher_1.ActionType.START_STEP_RUN,
|
|
33
|
-
actionPayload: JSON.stringify('{"input": {"data": 1}}'),
|
|
34
|
-
};
|
|
35
|
-
const mockCancel = Object.assign(Object.assign({}, mockStart), { actionType: dispatcher_1.ActionType.CANCEL_STEP_RUN });
|
|
36
|
-
describe('Worker', () => {
|
|
37
|
-
let hatchet;
|
|
38
|
-
beforeEach(() => {
|
|
39
|
-
hatchet = new hatchet_client_1.HatchetClient({
|
|
40
|
-
token: 'TOKEN',
|
|
41
|
-
log_level: 'OFF',
|
|
42
|
-
host_port: 'HOST_PORT',
|
|
43
|
-
tls_config: {
|
|
44
|
-
cert_file: 'TLS_CERT_FILE',
|
|
45
|
-
key_file: 'TLS_KEY_FILE',
|
|
46
|
-
ca_file: 'TLS_ROOT_CA_FILE',
|
|
47
|
-
server_name: 'TLS_SERVER_NAME',
|
|
48
|
-
},
|
|
49
|
-
}, {
|
|
50
|
-
credentials: nice_grpc_1.ChannelCredentials.createInsecure(),
|
|
51
|
-
});
|
|
52
|
-
});
|
|
53
|
-
describe('register_workflow', () => {
|
|
54
|
-
it('should update the registry', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
55
|
-
const worker = new worker_1.Worker(hatchet, { name: 'WORKER_NAME' });
|
|
56
|
-
const putWorkflowSpy = jest.spyOn(worker.client.admin, 'put_workflow').mockResolvedValue();
|
|
57
|
-
const workflow = {
|
|
58
|
-
id: 'workflow1',
|
|
59
|
-
description: 'test',
|
|
60
|
-
on: {
|
|
61
|
-
event: 'user:create',
|
|
62
|
-
},
|
|
63
|
-
steps: [
|
|
64
|
-
{
|
|
65
|
-
name: 'step1',
|
|
66
|
-
run: (ctx) => {
|
|
67
|
-
return { test: 'test' };
|
|
68
|
-
},
|
|
69
|
-
},
|
|
70
|
-
],
|
|
71
|
-
};
|
|
72
|
-
yield worker.register_workflow(workflow);
|
|
73
|
-
expect(putWorkflowSpy).toHaveBeenCalledTimes(1);
|
|
74
|
-
expect(worker.action_registry).toEqual({
|
|
75
|
-
[`default:step1`]: workflow.steps[0].run,
|
|
76
|
-
});
|
|
77
|
-
}));
|
|
78
|
-
});
|
|
79
|
-
describe('handle_start_step_run', () => {
|
|
80
|
-
it('should start a step run', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
81
|
-
const worker = new worker_1.Worker(hatchet, { name: 'WORKER_NAME' });
|
|
82
|
-
const putWorkflowSpy = jest.spyOn(worker.client.admin, 'put_workflow').mockResolvedValue();
|
|
83
|
-
const getActionEventSpy = jest.spyOn(worker, 'get_action_event');
|
|
84
|
-
const sendActionEventSpy = jest
|
|
85
|
-
.spyOn(worker.client.dispatcher, 'send_action_event')
|
|
86
|
-
.mockResolvedValue({
|
|
87
|
-
tenantId: 'TENANT_ID',
|
|
88
|
-
workerId: 'WORKER_ID',
|
|
89
|
-
});
|
|
90
|
-
const startSpy = jest.fn().mockReturnValue({ data: 4 });
|
|
91
|
-
worker.action_registry = {
|
|
92
|
-
[mockStart.actionId]: startSpy,
|
|
93
|
-
};
|
|
94
|
-
worker.handle_start_step_run(mockStart);
|
|
95
|
-
yield (0, sleep_1.default)(100);
|
|
96
|
-
expect(startSpy).toHaveBeenCalledTimes(1);
|
|
97
|
-
expect(getActionEventSpy).toHaveBeenNthCalledWith(2, expect.anything(), dispatcher_1.ActionEventType.STEP_EVENT_TYPE_COMPLETED, { data: 4 });
|
|
98
|
-
expect(worker.futures[mockStart.stepRunId]).toBeUndefined();
|
|
99
|
-
expect(sendActionEventSpy).toHaveBeenCalledTimes(2);
|
|
100
|
-
}));
|
|
101
|
-
it('should fail gracefully', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
102
|
-
const worker = new worker_1.Worker(hatchet, { name: 'WORKER_NAME' });
|
|
103
|
-
const getActionEventSpy = jest.spyOn(worker, 'get_action_event');
|
|
104
|
-
const sendActionEventSpy = jest
|
|
105
|
-
.spyOn(worker.client.dispatcher, 'send_action_event')
|
|
106
|
-
.mockResolvedValue({
|
|
107
|
-
tenantId: 'TENANT_ID',
|
|
108
|
-
workerId: 'WORKER_ID',
|
|
109
|
-
});
|
|
110
|
-
const startSpy = jest.fn().mockRejectedValue(new Error('ERROR'));
|
|
111
|
-
worker.action_registry = {
|
|
112
|
-
[mockStart.actionId]: startSpy,
|
|
113
|
-
};
|
|
114
|
-
worker.handle_start_step_run(mockStart);
|
|
115
|
-
yield (0, sleep_1.default)(100);
|
|
116
|
-
expect(startSpy).toHaveBeenCalledTimes(1);
|
|
117
|
-
expect(getActionEventSpy).toHaveBeenNthCalledWith(2, expect.anything(), dispatcher_1.ActionEventType.STEP_EVENT_TYPE_FAILED, expect.anything());
|
|
118
|
-
expect(worker.futures[mockStart.stepRunId]).toBeUndefined();
|
|
119
|
-
expect(sendActionEventSpy).toHaveBeenCalledTimes(2);
|
|
120
|
-
}));
|
|
121
|
-
});
|
|
122
|
-
describe('handle_cancel_step_run', () => {
|
|
123
|
-
it('should cancel a step run', () => {
|
|
124
|
-
const worker = new worker_1.Worker(hatchet, { name: 'WORKER_NAME' });
|
|
125
|
-
const cancelSpy = jest.fn().mockReturnValue(undefined);
|
|
126
|
-
worker.futures = {
|
|
127
|
-
[mockCancel.stepRunId]: {
|
|
128
|
-
cancel: cancelSpy,
|
|
129
|
-
},
|
|
130
|
-
};
|
|
131
|
-
worker.handle_cancel_step_run(mockCancel);
|
|
132
|
-
expect(cancelSpy).toHaveBeenCalledTimes(1);
|
|
133
|
-
expect(worker.futures[mockCancel.stepRunId]).toBeUndefined();
|
|
134
|
-
});
|
|
135
|
-
});
|
|
136
|
-
describe('exit_gracefully', () => {
|
|
137
|
-
xit('should call exit_gracefully on SIGTERM', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
138
|
-
const worker = new worker_1.Worker(hatchet, { name: 'WORKER_NAME' });
|
|
139
|
-
// the spy is not working and the test is killing the test process
|
|
140
|
-
const exitSpy = jest.spyOn(worker, 'exit_gracefully').mockImplementationOnce(() => {
|
|
141
|
-
throw new Error('Simulated error');
|
|
142
|
-
});
|
|
143
|
-
process.emit('SIGTERM', 'SIGTERM');
|
|
144
|
-
expect(exitSpy).toHaveBeenCalledTimes(1);
|
|
145
|
-
}));
|
|
146
|
-
xit('should call exit_gracefully on SIGINT', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
147
|
-
const worker = new worker_1.Worker(hatchet, { name: 'WORKER_NAME' });
|
|
148
|
-
// This is killing the process (as it should) fix the spy at some point
|
|
149
|
-
const exitSpy = jest.spyOn(worker, 'exit_gracefully').mockResolvedValue();
|
|
150
|
-
process.emit('SIGINT', 'SIGINT');
|
|
151
|
-
expect(exitSpy).toHaveBeenCalledTimes(1);
|
|
152
|
-
}));
|
|
153
|
-
xit('should unregister the listener and exit', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
154
|
-
const worker = new worker_1.Worker(hatchet, { name: 'WORKER_NAME' });
|
|
155
|
-
jest.spyOn(process, 'exit').mockImplementation((number) => {
|
|
156
|
-
throw new Error(`EXIT ${number}`);
|
|
157
|
-
}); // This is killing the process (as it should) fix the spy at some point
|
|
158
|
-
const mockActionListener = new action_listener_1.ActionListener(hatchet.dispatcher, (0, action_listener_test_1.mockListener)([mockStart, mockStart, new nice_grpc_common_1.ServerError(nice_grpc_common_1.Status.CANCELLED, 'CANCELLED')]), 'WORKER_ID');
|
|
159
|
-
mockActionListener.unregister = jest.fn().mockResolvedValue((0, zod_1.never)());
|
|
160
|
-
worker.listener = mockActionListener;
|
|
161
|
-
expect(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
162
|
-
yield worker.exit_gracefully();
|
|
163
|
-
})).toThrow('EXIT 0');
|
|
164
|
-
expect(mockActionListener.unregister).toHaveBeenCalledTimes(1);
|
|
165
|
-
}));
|
|
166
|
-
it('should exit the process if handle_kill is true', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
167
|
-
const worker = new worker_1.Worker(hatchet, { name: 'WORKER_NAME' });
|
|
168
|
-
const exitSpy = jest.spyOn(process, 'exit').mockReturnValue(undefined);
|
|
169
|
-
yield worker.exit_gracefully();
|
|
170
|
-
expect(exitSpy).toHaveBeenCalledTimes(1);
|
|
171
|
-
}));
|
|
172
|
-
});
|
|
173
|
-
describe('start', () => {
|
|
174
|
-
xit('should get actions and start runs', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
175
|
-
const worker = new worker_1.Worker(hatchet, { name: 'WORKER_NAME' });
|
|
176
|
-
const startSpy = jest.spyOn(worker, 'handle_start_step_run').mockReturnValue();
|
|
177
|
-
const cancelSpy = jest.spyOn(worker, 'handle_cancel_step_run').mockReturnValue();
|
|
178
|
-
const mockActionListener = new action_listener_1.ActionListener(hatchet.dispatcher, (0, action_listener_test_1.mockListener)([mockStart, mockStart, new nice_grpc_common_1.ServerError(nice_grpc_common_1.Status.CANCELLED, 'CANCELLED')]), 'WORKER_ID');
|
|
179
|
-
const getActionListenerSpy = jest
|
|
180
|
-
.spyOn(worker.client.dispatcher, 'get_action_listener')
|
|
181
|
-
.mockResolvedValue(mockActionListener);
|
|
182
|
-
yield worker.start();
|
|
183
|
-
expect(getActionListenerSpy).toHaveBeenCalledTimes(1);
|
|
184
|
-
expect(startSpy).toHaveBeenCalledTimes(2);
|
|
185
|
-
expect(cancelSpy).toHaveBeenCalledTimes(0);
|
|
186
|
-
}));
|
|
187
|
-
it('should get actions and cancel runs', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
188
|
-
const worker = new worker_1.Worker(hatchet, { name: 'WORKER_NAME' });
|
|
189
|
-
const startSpy = jest.spyOn(worker, 'handle_start_step_run').mockReturnValue();
|
|
190
|
-
const cancelSpy = jest.spyOn(worker, 'handle_cancel_step_run').mockReturnValue();
|
|
191
|
-
const mockActionListner = new action_listener_1.ActionListener(hatchet.dispatcher, (0, action_listener_test_1.mockListener)([mockStart, mockCancel, new nice_grpc_common_1.ServerError(nice_grpc_common_1.Status.CANCELLED, 'CANCELLED')]), 'WORKER_ID');
|
|
192
|
-
const getActionListenerSpy = jest
|
|
193
|
-
.spyOn(worker.client.dispatcher, 'get_action_listener')
|
|
194
|
-
.mockResolvedValue(mockActionListner);
|
|
195
|
-
yield worker.start();
|
|
196
|
-
expect(getActionListenerSpy).toHaveBeenCalledTimes(1);
|
|
197
|
-
expect(startSpy).toHaveBeenCalledTimes(1);
|
|
198
|
-
expect(cancelSpy).toHaveBeenCalledTimes(1);
|
|
199
|
-
}));
|
|
200
|
-
it('should retry 5 times to start a worker then throw an error', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
201
|
-
const worker = new worker_1.Worker(hatchet, { name: 'WORKER_NAME' });
|
|
202
|
-
const startSpy = jest.spyOn(worker, 'handle_start_step_run').mockReturnValue();
|
|
203
|
-
const cancelSpy = jest.spyOn(worker, 'handle_cancel_step_run').mockReturnValue();
|
|
204
|
-
const mockActionListner = new action_listener_1.ActionListener(hatchet.dispatcher, (0, action_listener_test_1.mockListener)([mockStart, mockCancel, new nice_grpc_common_1.ServerError(nice_grpc_common_1.Status.CANCELLED, 'CANCELLED')]), 'WORKER_ID');
|
|
205
|
-
const getActionListenerSpy = jest
|
|
206
|
-
.spyOn(worker.client.dispatcher, 'get_action_listener')
|
|
207
|
-
.mockImplementationOnce(() => {
|
|
208
|
-
throw new Error('Simulated error');
|
|
209
|
-
})
|
|
210
|
-
.mockImplementationOnce(() => {
|
|
211
|
-
throw new Error('Simulated error');
|
|
212
|
-
})
|
|
213
|
-
.mockImplementationOnce(() => {
|
|
214
|
-
throw new Error('Simulated error');
|
|
215
|
-
})
|
|
216
|
-
.mockImplementationOnce(() => {
|
|
217
|
-
throw new Error('Simulated error');
|
|
218
|
-
})
|
|
219
|
-
.mockImplementationOnce(() => {
|
|
220
|
-
throw new Error('Simulated error');
|
|
221
|
-
})
|
|
222
|
-
.mockImplementationOnce(() => {
|
|
223
|
-
throw new Error('Simulated error');
|
|
224
|
-
});
|
|
225
|
-
yield worker.start();
|
|
226
|
-
expect(getActionListenerSpy).toHaveBeenCalledTimes(5);
|
|
227
|
-
expect(startSpy).toHaveBeenCalledTimes(0);
|
|
228
|
-
expect(cancelSpy).toHaveBeenCalledTimes(0);
|
|
229
|
-
}));
|
|
230
|
-
it('should successfully run after retrying < 5 times', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
231
|
-
const worker = new worker_1.Worker(hatchet, { name: 'WORKER_NAME' });
|
|
232
|
-
const startSpy = jest.spyOn(worker, 'handle_start_step_run').mockReturnValue();
|
|
233
|
-
const cancelSpy = jest.spyOn(worker, 'handle_cancel_step_run').mockReturnValue();
|
|
234
|
-
const mockActionLister = new action_listener_1.ActionListener(hatchet.dispatcher, (0, action_listener_test_1.mockListener)([mockStart, mockCancel, new nice_grpc_common_1.ServerError(nice_grpc_common_1.Status.CANCELLED, 'CANCELLED')]), 'WORKER_ID');
|
|
235
|
-
const getActionListenerSpy = jest
|
|
236
|
-
.spyOn(worker.client.dispatcher, 'get_action_listener')
|
|
237
|
-
.mockImplementationOnce(() => {
|
|
238
|
-
throw new Error('Simulated error');
|
|
239
|
-
})
|
|
240
|
-
.mockImplementationOnce(() => {
|
|
241
|
-
throw new Error('Simulated error');
|
|
242
|
-
})
|
|
243
|
-
.mockImplementationOnce(() => {
|
|
244
|
-
throw new Error('Simulated error');
|
|
245
|
-
})
|
|
246
|
-
.mockImplementationOnce(() => {
|
|
247
|
-
throw new Error('Simulated error');
|
|
248
|
-
})
|
|
249
|
-
.mockImplementationOnce(() => __awaiter(void 0, void 0, void 0, function* () { return mockActionLister; }));
|
|
250
|
-
yield worker.start();
|
|
251
|
-
expect(getActionListenerSpy).toHaveBeenCalledTimes(5);
|
|
252
|
-
expect(startSpy).toHaveBeenCalledTimes(1);
|
|
253
|
-
expect(cancelSpy).toHaveBeenCalledTimes(1);
|
|
254
|
-
}));
|
|
255
|
-
});
|
|
256
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const config_loader_1 = require("./config-loader");
|
|
4
|
-
fdescribe('ConfigLoader', () => {
|
|
5
|
-
beforeEach(() => {
|
|
6
|
-
process.env.HATCHET_CLIENT_HOST_PORT = 'HOST_PORT';
|
|
7
|
-
process.env.HATCHET_CLIENT_TLS_CERT_FILE = 'TLS_CERT_FILE';
|
|
8
|
-
process.env.HATCHET_CLIENT_TLS_KEY_FILE = 'TLS_KEY_FILE';
|
|
9
|
-
process.env.HATCHET_CLIENT_TLS_ROOT_CA_FILE = 'TLS_ROOT_CA_FILE';
|
|
10
|
-
process.env.HATCHET_CLIENT_TLS_SERVER_NAME = 'TLS_SERVER_NAME';
|
|
11
|
-
});
|
|
12
|
-
it('should load from environment variables', () => {
|
|
13
|
-
const config = config_loader_1.ConfigLoader.load_client_config();
|
|
14
|
-
expect(config).toEqual({
|
|
15
|
-
host_port: 'HOST_PORT',
|
|
16
|
-
log_level: 'INFO',
|
|
17
|
-
tls_config: {
|
|
18
|
-
tls_strategy: 'tls',
|
|
19
|
-
cert_file: 'TLS_CERT_FILE',
|
|
20
|
-
key_file: 'TLS_KEY_FILE',
|
|
21
|
-
ca_file: 'TLS_ROOT_CA_FILE',
|
|
22
|
-
server_name: 'TLS_SERVER_NAME',
|
|
23
|
-
},
|
|
24
|
-
});
|
|
25
|
-
});
|
|
26
|
-
it('should throw an error if the file is not found', () => {
|
|
27
|
-
expect(() => config_loader_1.ConfigLoader.load_client_config({
|
|
28
|
-
path: './fixtures/not-found.yaml',
|
|
29
|
-
})).toThrow();
|
|
30
|
-
});
|
|
31
|
-
xit('should throw an error if the yaml file fails validation', () => {
|
|
32
|
-
expect(() =>
|
|
33
|
-
// This test is failing because there is no invalid state of the yaml file, need to update with tls and mtls settings
|
|
34
|
-
config_loader_1.ConfigLoader.load_client_config({
|
|
35
|
-
path: './fixtures/.hatchet-invalid.yaml',
|
|
36
|
-
})).toThrow();
|
|
37
|
-
});
|
|
38
|
-
it('should favor yaml config over env vars', () => {
|
|
39
|
-
const config = config_loader_1.ConfigLoader.load_client_config({
|
|
40
|
-
path: './fixtures/.hatchet.yaml',
|
|
41
|
-
});
|
|
42
|
-
expect(config).toEqual({
|
|
43
|
-
token: 'TOKEN_YAML',
|
|
44
|
-
host_port: 'HOST_PORT_YAML',
|
|
45
|
-
log_level: 'INFO',
|
|
46
|
-
tls_config: {
|
|
47
|
-
tls_strategy: 'tls',
|
|
48
|
-
cert_file: 'TLS_CERT_FILE_YAML',
|
|
49
|
-
key_file: 'TLS_KEY_FILE_YAML',
|
|
50
|
-
ca_file: 'TLS_ROOT_CA_FILE_YAML',
|
|
51
|
-
server_name: 'TLS_SERVER_NAME_YAML',
|
|
52
|
-
},
|
|
53
|
-
});
|
|
54
|
-
});
|
|
55
|
-
xit('should attempt to load the root .hatchet.yaml config', () => {
|
|
56
|
-
// i'm not sure the best way to test this, maybe spy on readFileSync called with
|
|
57
|
-
const config = config_loader_1.ConfigLoader.load_client_config({
|
|
58
|
-
path: './fixtures/.hatchet.yaml',
|
|
59
|
-
});
|
|
60
|
-
expect(config).toEqual({
|
|
61
|
-
token: 'TOKEN_YAML',
|
|
62
|
-
host_port: 'HOST_PORT_YAML',
|
|
63
|
-
tls_config: {
|
|
64
|
-
tls_strategy: 'tls',
|
|
65
|
-
cert_file: 'TLS_CERT_FILE_YAML',
|
|
66
|
-
key_file: 'TLS_KEY_FILE_YAML',
|
|
67
|
-
ca_file: 'TLS_ROOT_CA_FILE_YAML',
|
|
68
|
-
server_name: 'TLS_SERVER_NAME_YAML',
|
|
69
|
-
},
|
|
70
|
-
});
|
|
71
|
-
});
|
|
72
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
-
};
|
|
14
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
const hatchet_promise_1 = __importDefault(require("./hatchet-promise"));
|
|
16
|
-
describe('HatchetPromise', () => {
|
|
17
|
-
it('should resolve the original promise if not canceled', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
18
|
-
const hatchetPromise = new hatchet_promise_1.default(new Promise((resolve) => {
|
|
19
|
-
setTimeout(() => resolve('RESOLVED'), 500);
|
|
20
|
-
}));
|
|
21
|
-
const result = yield hatchetPromise.promise;
|
|
22
|
-
expect(result).toEqual('RESOLVED');
|
|
23
|
-
}));
|
|
24
|
-
it('should resolve the cancel promise if canceled', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
25
|
-
const hatchetPromise = new hatchet_promise_1.default(new Promise((resolve) => {
|
|
26
|
-
setTimeout(() => resolve('RESOLVED'), 500);
|
|
27
|
-
}));
|
|
28
|
-
const result = hatchetPromise.promise;
|
|
29
|
-
setTimeout(() => {
|
|
30
|
-
hatchetPromise.cancel();
|
|
31
|
-
}, 100);
|
|
32
|
-
try {
|
|
33
|
-
yield result;
|
|
34
|
-
expect(true).toEqual(false); // this should not be reached
|
|
35
|
-
}
|
|
36
|
-
catch (e) {
|
|
37
|
-
expect(e).toEqual(undefined);
|
|
38
|
-
}
|
|
39
|
-
}));
|
|
40
|
-
});
|