@temporalio/testing 1.2.0 → 1.4.0

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.
@@ -1,7 +1,7 @@
1
1
  import * as grpc from '@grpc/grpc-js';
2
2
  import { Connection as BaseConnection, ConnectionOptions } from '@temporalio/client';
3
3
  import { ConnectionCtorOptions as BaseConnectionCtorOptions } from '@temporalio/client/lib/connection';
4
- import { temporal } from '../generated-protos';
4
+ import { temporal } from '@temporalio/proto';
5
5
  export declare type TestService = temporal.api.testservice.v1.TestService;
6
6
  export declare const TestService: typeof temporal.api.testservice.v1.TestService;
7
7
  interface ConnectionCtorOptions extends BaseConnectionCtorOptions {
@@ -26,8 +26,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
26
26
  exports.Connection = exports.TestService = void 0;
27
27
  const grpc = __importStar(require("@grpc/grpc-js"));
28
28
  const client_1 = require("@temporalio/client");
29
- const generated_protos_1 = require("../generated-protos");
30
- exports.TestService = generated_protos_1.temporal.api.testservice.v1.TestService;
29
+ const proto_1 = require("@temporalio/proto");
30
+ exports.TestService = proto_1.temporal.api.testservice.v1.TestService;
31
31
  /**
32
32
  * A Connection class that can be used to interact with both the test server's TestService and WorkflowService
33
33
  */
@@ -59,4 +59,4 @@ class Connection extends client_1.Connection {
59
59
  }
60
60
  exports.Connection = Connection;
61
61
  Connection.TestServiceClient = grpc.makeGenericClientConstructor({}, 'TestService', {});
62
- //# sourceMappingURL=test-service-client.js.map
62
+ //# sourceMappingURL=connection.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"connection.js","sourceRoot":"","sources":["../src/connection.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,oDAAsC;AACtC,+CAAqF;AAErF,6CAA6C;AAG9B,mBAAW,GAAK,gBAAQ,CAAC,GAAG,CAAC,WAAW,CAAC,EAAE,aAAC;AAM3D;;GAEG;AACH,MAAa,UAAW,SAAQ,mBAAc;IA2B5C,YAAsB,OAA8B;QAClD,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,WAAW,GAAG,OAAO,CAAC,WAAW,CAAC;IACzC,CAAC;IA1BS,MAAM,CAAC,iBAAiB,CAAC,OAA2B;QAC5D,MAAM,WAAW,GAAG,mBAAc,CAAC,iBAAiB,CAAC,OAAO,CAAC,CAAC;QAC9D,MAAM,OAAO,GAAG,IAAI,CAAC,yBAAyB,CAAC;YAC7C,WAAW,EAAE,yCAAyC;YACtD,MAAM,EAAE,WAAW,CAAC,MAAM;YAC1B,kBAAkB,EAAE,WAAW,CAAC,kBAAkB;YAClD,YAAY,EAAE,WAAW,CAAC,OAAO,CAAC,YAAY;SAC/C,CAAC,CAAC;QACH,MAAM,WAAW,GAAG,mBAAW,CAAC,MAAM,CAAC,OAAO,EAAE,KAAK,EAAE,KAAK,CAAC,CAAC;QAC9D,OAAO,EAAE,GAAG,WAAW,EAAE,WAAW,EAAE,CAAC;IACzC,CAAC;IAED,MAAM,CAAC,IAAI,CAAC,OAA2B;QACrC,MAAM,WAAW,GAAG,IAAI,CAAC,iBAAiB,CAAC,OAAO,CAAC,CAAC;QACpD,OAAO,IAAI,IAAI,CAAC,WAAW,CAAC,CAAC;IAC/B,CAAC;IAED,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,OAA2B;QAC9C,MAAM,GAAG,GAAG,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QAC/B,MAAM,GAAG,CAAC,eAAe,EAAE,CAAC;QAC5B,OAAO,GAAG,CAAC;IACb,CAAC;;AAzBH,gCA+BC;AA9BwB,4BAAiB,GAAG,IAAI,CAAC,4BAA4B,CAAC,EAAE,EAAE,aAAa,EAAE,EAAE,CAAC,CAAC"}
package/lib/index.d.ts CHANGED
@@ -8,60 +8,36 @@
8
8
  * @module
9
9
  */
10
10
  /// <reference types="node" />
11
- /// <reference types="node" />
12
11
  import * as activity from '@temporalio/activity';
13
- import { AsyncCompletionClient, WorkflowClient as BaseWorkflowClient, WorkflowClientOptions as BaseWorkflowClientOptions, WorkflowResultOptions as BaseWorkflowResultOptions, WorkflowStartOptions as BaseWorkflowStartOptions } from '@temporalio/client';
14
- import { ActivityFunction, Workflow, WorkflowResultType } from '@temporalio/common';
15
- import { NativeConnection, Logger } from '@temporalio/worker';
16
- import { ChildProcess, StdioOptions } from 'child_process';
12
+ import { AsyncCompletionClient, Client, ClientOptions, ConnectionLike, WorkflowClient, WorkflowClientOptions, WorkflowResultOptions } from '@temporalio/client';
13
+ import { ActivityFunction } from '@temporalio/common';
14
+ import { NativeConnection } from '@temporalio/worker';
15
+ import { EphemeralServer, EphemeralServerConfig, TemporaliteConfig, TimeSkippingServerConfig } from '@temporalio/core-bridge';
17
16
  import events from 'events';
18
- import { Connection, TestService } from './test-service-client';
19
- export declare const DEFAULT_TEST_SERVER_PATH: string;
20
- /**
21
- * Options passed to {@link WorkflowClient.result}, these are the same as the
22
- * {@link BaseWorkflowResultOptions} with an additional option that controls
23
- * whether to toggle time skipping in the Test server while waiting on a
24
- * Workflow's result.
25
- */
26
- export interface WorkflowResultOptions extends BaseWorkflowResultOptions {
27
- /**
28
- * If set to `true`, waiting for the result does not enable time skipping
29
- */
30
- runInNormalTime?: boolean;
17
+ import { Connection, TestService } from './connection';
18
+ export { TimeSkippingServerConfig, TemporaliteConfig, EphemeralServerExecutable } from '@temporalio/core-bridge';
19
+ export { EphemeralServerConfig };
20
+ export interface TimeSkippingWorkflowClientOptions extends WorkflowClientOptions {
21
+ connection: Connection;
22
+ enableTimeSkipping: boolean;
31
23
  }
32
- /**
33
- * Options passed to {@link WorkflowClient.execute}, these are the same as the
34
- * {@link BaseWorkflowStartOptions} with an additional option that controls
35
- * whether to toggle time skipping in the Test server while waiting on a
36
- * Workflow's result.
37
- */
38
- export declare type WorkflowStartOptions<T extends Workflow> = BaseWorkflowStartOptions<T> & {
39
- /**
40
- * If set to `true`, waiting for the result does not enable time skipping
41
- */
42
- runInNormalTime?: boolean;
43
- };
44
- export interface WorkflowClientOptions extends BaseWorkflowClientOptions {
24
+ export interface TestEnvClientOptions extends ClientOptions {
45
25
  connection: Connection;
26
+ enableTimeSkipping: boolean;
46
27
  }
47
28
  /**
48
29
  * A client with the exact same API as the "normal" client with 1 exception,
49
30
  * When this client waits on a Workflow's result, it will enable time skipping
50
31
  * in the test server.
51
32
  */
52
- export declare class WorkflowClient extends BaseWorkflowClient {
33
+ export declare class TimeSkippingWorkflowClient extends WorkflowClient {
53
34
  protected readonly testService: TestService;
54
- constructor(options: WorkflowClientOptions);
55
- /**
56
- * Execute a Workflow and wait for completion.
57
- *
58
- * @see {@link BaseWorkflowClient.execute}
59
- */
60
- execute<T extends Workflow>(workflowTypeOrFunc: string | T, options: WorkflowStartOptions<T>): Promise<WorkflowResultType<T>>;
35
+ protected readonly enableTimeSkipping: boolean;
36
+ constructor(options: TimeSkippingWorkflowClientOptions);
61
37
  /**
62
38
  * Gets the result of a Workflow execution.
63
39
  *
64
- * @see {@link BaseWorkflowClient.result}
40
+ * @see {@link WorkflowClient.result}
65
41
  */
66
42
  result<T>(workflowId: string, runId?: string | undefined, opts?: WorkflowResultOptions | undefined): Promise<T>;
67
43
  }
@@ -72,27 +48,32 @@ export declare class WorkflowClient extends BaseWorkflowClient {
72
48
  * retryable `ApplicationFailure`s.
73
49
  */
74
50
  export declare const workflowInterceptorModules: string[];
75
- export interface TestServerSpawnerOptions {
76
- /**
77
- * @default {@link DEFAULT_TEST_SERVER_PATH}
78
- */
79
- path?: string;
80
- /**
81
- * @default ignore
82
- */
83
- stdio?: StdioOptions;
84
- }
85
51
  /**
86
- * A generic callback that returns a child process
52
+ * Subset of the "normal" client options that are used to create a client for the test environment.
87
53
  */
88
- export declare type TestServerSpawner = (port: number) => ChildProcess;
54
+ export declare type ClientOptionsForTestEnv = Omit<ClientOptions, 'namespace' | 'connection'>;
89
55
  /**
90
56
  * Options for {@link TestWorkflowEnvironment.create}
91
57
  */
92
- export interface TestWorkflowEnvironmentOptions {
93
- testServer?: TestServerSpawner | TestServerSpawnerOptions;
94
- logger?: Logger;
95
- }
58
+ declare type TestWorkflowEnvironmentOptions = {
59
+ server?: EphemeralServerConfig;
60
+ client?: ClientOptionsForTestEnv;
61
+ };
62
+ /**
63
+ * Options for {@link TestWorkflowEnvironment.createTimeSkipping}
64
+ */
65
+ export declare type TimeSkippingTestWorkflowEnvironmentOptions = {
66
+ server?: Omit<TimeSkippingServerConfig, 'type'>;
67
+ client?: ClientOptionsForTestEnv;
68
+ };
69
+ /**
70
+ * Options for {@link TestWorkflowEnvironment.createLocal}
71
+ */
72
+ export declare type LocalTestWorkflowEnvironmentOptions = {
73
+ server?: Omit<TemporaliteConfig, 'type'>;
74
+ client?: ClientOptionsForTestEnv;
75
+ };
76
+ export declare type TestWorkflowEnvironmentOptionsWithDefaults = Required<TestWorkflowEnvironmentOptions>;
96
77
  /**
97
78
  * An execution environment for running Workflow integration tests.
98
79
  *
@@ -100,17 +81,31 @@ export interface TestWorkflowEnvironmentOptions {
100
81
  * By default, the Java test server is used which supports time skipping.
101
82
  */
102
83
  export declare class TestWorkflowEnvironment {
103
- protected readonly serverProc: ChildProcess;
84
+ readonly options: TestWorkflowEnvironmentOptionsWithDefaults;
85
+ readonly supportsTimeSkipping: boolean;
86
+ protected readonly server: EphemeralServer;
104
87
  /**
105
- * Get an extablished {@link Connection} to the test server
88
+ * Namespace used in this environment (taken from {@link TestWorkflowEnvironmentOptions})
106
89
  */
107
- readonly connection: Connection;
90
+ readonly namespace?: string;
91
+ /**
92
+ * Get an established {@link Connection} to the ephemeral server
93
+ */
94
+ readonly connection: ConnectionLike;
95
+ /**
96
+ * A {@link TestEnvClient} for interacting with the ephemeral server
97
+ */
98
+ readonly client: Client;
108
99
  /**
109
100
  * An {@link AsyncCompletionClient} for interacting with the test server
101
+ *
102
+ * @deprecated - use `client.activity` instead
110
103
  */
111
104
  readonly asyncCompletionClient: AsyncCompletionClient;
112
105
  /**
113
- * A {@link WorkflowClient} for interacting with the test server
106
+ * A {@link TimeSkippingWorkflowClient} for interacting with the test server
107
+ *
108
+ * @deprecated - use `client.workflow` instead
114
109
  */
115
110
  readonly workflowClient: WorkflowClient;
116
111
  /**
@@ -119,9 +114,47 @@ export declare class TestWorkflowEnvironment {
119
114
  * Use this connection when creating Workers for testing.
120
115
  */
121
116
  readonly nativeConnection: NativeConnection;
122
- protected constructor(serverProc: ChildProcess, connection: Connection, nativeConnection: NativeConnection);
117
+ protected constructor(options: TestWorkflowEnvironmentOptionsWithDefaults, supportsTimeSkipping: boolean, server: EphemeralServer, connection: Connection, nativeConnection: NativeConnection);
118
+ /**
119
+ * Start a time skipping workflow environment.
120
+ *
121
+ * By default, this environment will automatically skip to the next events in time when a workflow handle's `result`
122
+ * is awaited on (which includes {@link WorkflowClient.execute}). Before the result is awaited on, time can be
123
+ * manually skipped forward using {@link sleep}. The currently known time can be obtained via {@link currentTimeMs}.
124
+ *
125
+ * Internally, this environment lazily downloads a test-server binary for the current OS/arch from the [Java SDK
126
+ * releases](https://github.com/temporalio/sdk-java/releases) into the temp directory if it is not already there.
127
+ * Then the executable is started and will be killed when {@link teardown} is called.
128
+ *
129
+ * Users can reuse this environment for testing multiple independent workflows, but not concurrently. Time skipping,
130
+ * which is automatically done when awaiting a workflow result and manually done on sleep, is global to the
131
+ * environment, not to the workflow under test.
132
+ *
133
+ * We highly recommend, running tests serially when using a single environment or creating a separate environment per
134
+ * test.
135
+ *
136
+ * In the future, the test server implementation may be changed to another implementation.
137
+ */
138
+ static createTimeSkipping(opts?: TimeSkippingTestWorkflowEnvironmentOptions): Promise<TestWorkflowEnvironment>;
139
+ /**
140
+ * Start a full Temporal server locally, downloading if necessary.
141
+ *
142
+ * This environment is good for testing full server capabilities, but does not support time skipping like
143
+ * {@link createTimeSkipping} does. {@link supportsTimeSkipping} will always return `false` for this environment.
144
+ * {@link sleep} will sleep the actual amount of time and {@link currentTimeMs} will return the current time.
145
+ *
146
+ * Internally, this uses [Temporalite](https://github.com/temporalio/temporalite). Which is a self-contained binary
147
+ * for Temporal using Sqlite persistence. This will download Temporalite to a temporary directory by default if it
148
+ * has not already been downloaded before and {@link LocalTestWorkflowEnvironmentOptions.server.executable.type} is
149
+ * `'cached-download'`.
150
+ *
151
+ * In the future, the Temporalite implementation may be changed to another implementation.
152
+ */
153
+ static createLocal(opts?: LocalTestWorkflowEnvironmentOptions): Promise<TestWorkflowEnvironment>;
123
154
  /**
124
155
  * Create a new test environment
156
+ *
157
+ * @deprecated - use {@link createTimeSkipping} or {@link createLocal}
125
158
  */
126
159
  static create(opts?: TestWorkflowEnvironmentOptions): Promise<TestWorkflowEnvironment>;
127
160
  /**
@@ -129,15 +162,19 @@ export declare class TestWorkflowEnvironment {
129
162
  */
130
163
  teardown(): Promise<void>;
131
164
  /**
132
- * Wait for `durationMs` in "test server time".
133
- *
134
- * The test server toggles between skipped time and normal time depending on what it needs to execute.
165
+ * Wait for `durationMs` in "server time".
135
166
  *
136
- * This method is likely to resolve in less than `durationMs` of "real time".
167
+ * This awaits using regular setTimeout in regular environments, or manually skips time in time-skipping environments.
137
168
  *
138
169
  * Useful for simulating events far into the future like completion of long running activities.
139
170
  *
140
- * @param durationMs {@link https://www.npmjs.com/package/ms | ms} formatted string or number of milliseconds
171
+ * **Time skippping**:
172
+ *
173
+ * The time skippping server toggles between skipped time and normal time depending on what it needs to execute.
174
+ *
175
+ * This method is _likely_ to resolve in less than `durationMs` of "real time".
176
+ *
177
+ * @param durationMs number of milliseconds or {@link https://www.npmjs.com/package/ms | ms-formatted string}
141
178
  *
142
179
  * @example
143
180
  *
@@ -169,6 +206,13 @@ export declare class TestWorkflowEnvironment {
169
206
  * ```
170
207
  */
171
208
  sleep: (durationMs: number | string) => Promise<void>;
209
+ /**
210
+ * Get the current time known to this environment.
211
+ *
212
+ * For non-time-skipping environments this is simply the system time. For time-skipping environments this is whatever
213
+ * time has been skipped to.
214
+ */
215
+ currentTimeMs(): Promise<number>;
172
216
  }
173
217
  /**
174
218
  * Used as the default activity info for Activities executed in the {@link MockActivityEnvironment}
package/lib/index.js CHANGED
@@ -35,58 +35,72 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
35
35
  return (mod && mod.__esModule) ? mod : { "default": mod };
36
36
  };
37
37
  Object.defineProperty(exports, "__esModule", { value: true });
38
- exports.MockActivityEnvironment = exports.defaultActivityInfo = exports.TestWorkflowEnvironment = exports.workflowInterceptorModules = exports.WorkflowClient = exports.DEFAULT_TEST_SERVER_PATH = void 0;
38
+ exports.MockActivityEnvironment = exports.defaultActivityInfo = exports.TestWorkflowEnvironment = exports.workflowInterceptorModules = exports.TimeSkippingWorkflowClient = void 0;
39
39
  const activity = __importStar(require("@temporalio/activity"));
40
40
  const client_1 = require("@temporalio/client");
41
41
  const common_1 = require("@temporalio/common");
42
+ const time_1 = require("@temporalio/common/lib/time");
42
43
  const worker_1 = require("@temporalio/worker");
44
+ const core_bridge_1 = require("@temporalio/core-bridge");
43
45
  const path_1 = __importDefault(require("path"));
44
- const os_1 = __importDefault(require("os"));
45
46
  const abort_controller_1 = require("abort-controller");
46
- const child_process_1 = require("child_process");
47
47
  const events_1 = __importDefault(require("events"));
48
- const child_process_2 = require("./child-process");
49
- const get_port_1 = __importDefault(require("get-port"));
50
- const test_service_client_1 = require("./test-service-client");
51
- const TEST_SERVER_EXECUTABLE_NAME = os_1.default.platform() === 'win32' ? 'test-server.exe' : 'test-server';
52
- exports.DEFAULT_TEST_SERVER_PATH = path_1.default.join(__dirname, `../${TEST_SERVER_EXECUTABLE_NAME}`);
48
+ const connection_1 = require("./connection");
49
+ const internal_non_workflow_1 = require("@temporalio/common/lib/internal-non-workflow");
50
+ const ms_1 = __importDefault(require("ms"));
53
51
  /**
54
52
  * A client with the exact same API as the "normal" client with 1 exception,
55
53
  * When this client waits on a Workflow's result, it will enable time skipping
56
54
  * in the test server.
57
55
  */
58
- class WorkflowClient extends client_1.WorkflowClient {
56
+ class TimeSkippingWorkflowClient extends client_1.WorkflowClient {
59
57
  constructor(options) {
60
58
  super(options);
59
+ this.enableTimeSkipping = options.enableTimeSkipping;
61
60
  this.testService = options.connection.testService;
62
61
  }
63
- /**
64
- * Execute a Workflow and wait for completion.
65
- *
66
- * @see {@link BaseWorkflowClient.execute}
67
- */
68
- async execute(workflowTypeOrFunc, options) {
69
- return super.execute(workflowTypeOrFunc, options);
70
- }
71
62
  /**
72
63
  * Gets the result of a Workflow execution.
73
64
  *
74
- * @see {@link BaseWorkflowClient.result}
65
+ * @see {@link WorkflowClient.result}
75
66
  */
76
67
  async result(workflowId, runId, opts) {
77
- if (opts?.runInNormalTime) {
78
- return await super.result(workflowId, runId, opts);
68
+ if (this.enableTimeSkipping) {
69
+ await this.testService.unlockTimeSkipping({});
70
+ try {
71
+ return await super.result(workflowId, runId, opts);
72
+ }
73
+ finally {
74
+ await this.testService.lockTimeSkipping({});
75
+ }
79
76
  }
80
- await this.testService.unlockTimeSkipping({});
81
- try {
77
+ else {
82
78
  return await super.result(workflowId, runId, opts);
83
79
  }
84
- finally {
85
- await this.testService.lockTimeSkipping({});
86
- }
87
80
  }
88
81
  }
89
- exports.WorkflowClient = WorkflowClient;
82
+ exports.TimeSkippingWorkflowClient = TimeSkippingWorkflowClient;
83
+ /**
84
+ * A client with the exact same API as the "normal" client with one exception:
85
+ * when `TestEnvClient.workflow` (an instance of {@link TimeSkippingWorkflowClient}) waits on a Workflow's result, it will enable time skipping
86
+ * in the Test Server.
87
+ */
88
+ class TestEnvClient extends client_1.Client {
89
+ constructor(options) {
90
+ super(options);
91
+ const { workflow, loadedDataConverter, interceptors, ...base } = this.options;
92
+ // Recreate the client (this isn't optimal but it's better than adding public methods just for testing).
93
+ // NOTE: we cast to "any" to work around `workflow` being a readonly attribute.
94
+ this.workflow = new TimeSkippingWorkflowClient({
95
+ ...base,
96
+ ...workflow,
97
+ connection: options.connection,
98
+ dataConverter: loadedDataConverter,
99
+ interceptors: interceptors.workflow,
100
+ enableTimeSkipping: options.enableTimeSkipping,
101
+ });
102
+ }
103
+ }
90
104
  /**
91
105
  * Convenience workflow interceptors
92
106
  *
@@ -94,14 +108,13 @@ exports.WorkflowClient = WorkflowClient;
94
108
  * retryable `ApplicationFailure`s.
95
109
  */
96
110
  exports.workflowInterceptorModules = [path_1.default.join(__dirname, 'assert-to-failure-interceptor')];
97
- function addDefaults({ testServer, logger, }) {
111
+ function addDefaults(opts) {
98
112
  return {
99
- testServerSpawner: typeof testServer === 'function'
100
- ? testServer
101
- : (port) => (0, child_process_1.spawn)(testServer?.path || exports.DEFAULT_TEST_SERVER_PATH, [`${port}`], {
102
- stdio: testServer?.stdio || 'ignore',
103
- }),
104
- logger: logger ?? new worker_1.DefaultLogger('INFO'),
113
+ server: {
114
+ type: 'time-skipping',
115
+ },
116
+ client: {},
117
+ ...opts,
105
118
  };
106
119
  }
107
120
  /**
@@ -111,18 +124,24 @@ function addDefaults({ testServer, logger, }) {
111
124
  * By default, the Java test server is used which supports time skipping.
112
125
  */
113
126
  class TestWorkflowEnvironment {
114
- constructor(serverProc, connection, nativeConnection) {
115
- this.serverProc = serverProc;
127
+ constructor(options, supportsTimeSkipping, server, connection, nativeConnection) {
128
+ this.options = options;
129
+ this.supportsTimeSkipping = supportsTimeSkipping;
130
+ this.server = server;
116
131
  /**
117
- * Wait for `durationMs` in "test server time".
132
+ * Wait for `durationMs` in "server time".
118
133
  *
119
- * The test server toggles between skipped time and normal time depending on what it needs to execute.
120
- *
121
- * This method is likely to resolve in less than `durationMs` of "real time".
134
+ * This awaits using regular setTimeout in regular environments, or manually skips time in time-skipping environments.
122
135
  *
123
136
  * Useful for simulating events far into the future like completion of long running activities.
124
137
  *
125
- * @param durationMs {@link https://www.npmjs.com/package/ms | ms} formatted string or number of milliseconds
138
+ * **Time skippping**:
139
+ *
140
+ * The time skippping server toggles between skipped time and normal time depending on what it needs to execute.
141
+ *
142
+ * This method is _likely_ to resolve in less than `durationMs` of "real time".
143
+ *
144
+ * @param durationMs number of milliseconds or {@link https://www.npmjs.com/package/ms | ms-formatted string}
126
145
  *
127
146
  * @example
128
147
  *
@@ -154,42 +173,81 @@ class TestWorkflowEnvironment {
154
173
  * ```
155
174
  */
156
175
  this.sleep = async (durationMs) => {
157
- await this.connection.testService.unlockTimeSkippingWithSleep({ duration: (0, common_1.msToTs)(durationMs) });
176
+ if (this.supportsTimeSkipping) {
177
+ await this.connection.testService.unlockTimeSkippingWithSleep({ duration: (0, time_1.msToTs)(durationMs) });
178
+ }
179
+ else {
180
+ await new Promise((resolve) => setTimeout(resolve, typeof durationMs === 'string' ? (0, ms_1.default)(durationMs) : durationMs));
181
+ }
158
182
  };
159
183
  this.connection = connection;
160
184
  this.nativeConnection = nativeConnection;
161
- this.workflowClient = new WorkflowClient({ connection });
162
- this.asyncCompletionClient = new client_1.AsyncCompletionClient({ connection });
185
+ this.namespace = options.server.type === 'temporalite' ? options.server.namespace : undefined;
186
+ this.client = new TestEnvClient({
187
+ connection,
188
+ namespace: this.namespace,
189
+ enableTimeSkipping: options.server.type === 'time-skipping',
190
+ ...options.client,
191
+ });
192
+ // eslint-disable-next-line deprecation/deprecation
193
+ this.asyncCompletionClient = this.client.activity;
194
+ // eslint-disable-next-line deprecation/deprecation
195
+ this.workflowClient = this.client.workflow;
196
+ }
197
+ /**
198
+ * Start a time skipping workflow environment.
199
+ *
200
+ * By default, this environment will automatically skip to the next events in time when a workflow handle's `result`
201
+ * is awaited on (which includes {@link WorkflowClient.execute}). Before the result is awaited on, time can be
202
+ * manually skipped forward using {@link sleep}. The currently known time can be obtained via {@link currentTimeMs}.
203
+ *
204
+ * Internally, this environment lazily downloads a test-server binary for the current OS/arch from the [Java SDK
205
+ * releases](https://github.com/temporalio/sdk-java/releases) into the temp directory if it is not already there.
206
+ * Then the executable is started and will be killed when {@link teardown} is called.
207
+ *
208
+ * Users can reuse this environment for testing multiple independent workflows, but not concurrently. Time skipping,
209
+ * which is automatically done when awaiting a workflow result and manually done on sleep, is global to the
210
+ * environment, not to the workflow under test.
211
+ *
212
+ * We highly recommend, running tests serially when using a single environment or creating a separate environment per
213
+ * test.
214
+ *
215
+ * In the future, the test server implementation may be changed to another implementation.
216
+ */
217
+ static async createTimeSkipping(opts) {
218
+ // eslint-disable-next-line deprecation/deprecation
219
+ return await this.create({ server: { type: 'time-skipping', ...opts?.server }, client: opts?.client });
220
+ }
221
+ /**
222
+ * Start a full Temporal server locally, downloading if necessary.
223
+ *
224
+ * This environment is good for testing full server capabilities, but does not support time skipping like
225
+ * {@link createTimeSkipping} does. {@link supportsTimeSkipping} will always return `false` for this environment.
226
+ * {@link sleep} will sleep the actual amount of time and {@link currentTimeMs} will return the current time.
227
+ *
228
+ * Internally, this uses [Temporalite](https://github.com/temporalio/temporalite). Which is a self-contained binary
229
+ * for Temporal using Sqlite persistence. This will download Temporalite to a temporary directory by default if it
230
+ * has not already been downloaded before and {@link LocalTestWorkflowEnvironmentOptions.server.executable.type} is
231
+ * `'cached-download'`.
232
+ *
233
+ * In the future, the Temporalite implementation may be changed to another implementation.
234
+ */
235
+ static async createLocal(opts) {
236
+ // eslint-disable-next-line deprecation/deprecation
237
+ return await this.create({ server: { type: 'temporalite', ...opts?.server }, client: opts?.client });
163
238
  }
164
239
  /**
165
240
  * Create a new test environment
241
+ *
242
+ * @deprecated - use {@link createTimeSkipping} or {@link createLocal}
166
243
  */
167
244
  static async create(opts) {
168
- const port = await (0, get_port_1.default)();
169
- const { testServerSpawner, logger } = addDefaults(opts ?? {});
170
- const child = testServerSpawner(port);
171
- const address = `127.0.0.1:${port}`;
172
- const connPromise = test_service_client_1.Connection.connect({ address });
173
- try {
174
- await Promise.race([
175
- connPromise,
176
- (0, child_process_2.waitOnChild)(child).then(() => {
177
- throw new Error('Test server child process exited prematurely');
178
- }),
179
- ]);
180
- }
181
- catch (err) {
182
- try {
183
- await (0, child_process_2.kill)(child);
184
- }
185
- catch (error) {
186
- logger.error('Failed to kill test server child process', { error });
187
- }
188
- throw err;
189
- }
190
- const conn = await connPromise;
245
+ const optsWithDefaults = addDefaults((0, internal_non_workflow_1.filterNullAndUndefined)(opts ?? {}));
246
+ const server = await worker_1.Runtime.instance().createEphemeralServer(optsWithDefaults.server);
247
+ const address = (0, core_bridge_1.getEphemeralServerTarget)(server);
191
248
  const nativeConnection = await worker_1.NativeConnection.connect({ address });
192
- return new this(child, conn, nativeConnection);
249
+ const connection = await connection_1.Connection.connect({ address });
250
+ return new this(optsWithDefaults, optsWithDefaults.server.type === 'time-skipping', server, connection, nativeConnection);
193
251
  }
194
252
  /**
195
253
  * Kill the test server process and close the connection to it
@@ -197,8 +255,22 @@ class TestWorkflowEnvironment {
197
255
  async teardown() {
198
256
  await this.connection.close();
199
257
  await this.nativeConnection.close();
200
- // TODO: the server should return exit code 0
201
- await (0, child_process_2.kill)(this.serverProc, 'SIGINT', { validReturnCodes: [0, 130] });
258
+ await worker_1.Runtime.instance().shutdownEphemeralServer(this.server);
259
+ }
260
+ /**
261
+ * Get the current time known to this environment.
262
+ *
263
+ * For non-time-skipping environments this is simply the system time. For time-skipping environments this is whatever
264
+ * time has been skipped to.
265
+ */
266
+ async currentTimeMs() {
267
+ if (this.supportsTimeSkipping) {
268
+ const { time } = await this.connection.testService.getCurrentTime({});
269
+ return (0, time_1.tsToMs)(time);
270
+ }
271
+ else {
272
+ return Date.now();
273
+ }
202
274
  }
203
275
  }
204
276
  exports.TestWorkflowEnvironment = TestWorkflowEnvironment;
package/lib/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;GAQG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEH,+DAAiD;AACjD,+CAM4B;AAC5B,+CAA8G;AAC9G,+CAA6E;AAC7E,gDAAwB;AACxB,4CAAoB;AACpB,uDAAmD;AACnD,iDAAkE;AAClE,oDAA4B;AAC5B,mDAAoD;AACpD,wDAA+B;AAC/B,+DAAgE;AAEhE,MAAM,2BAA2B,GAAG,YAAE,CAAC,QAAQ,EAAE,KAAK,OAAO,CAA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;gBACxB,MAAM,CAAC,IAAI,yBAAgB,CAAC,MAAM,CAAC,CAAC,CAAC;YACvC,CAAC,CAAC;QACJ,CAAC,CAAC,CAAC;QACH,MAAM,iBAAiB,GAAG,CAAC,OAAiB,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE,OAAO,CAAC,CAAC;QACjF,IAAI,CAAC,OAAO,GAAG,IAAI,QAAQ,CAAC,OAAO,CACjC,EAAE,GAAG,2BAAmB,EAAE,GAAG,IAAI,EAAE,EACnC,OAAO,EACP,eAAe,CAAC,MAAM,EACtB,iBAAiB,CAClB,CAAC;QACF,OAAO,CAAC,KAAK,CAAC,GAAG,EAAE;YACjB,+BAA+B;QACjC,CAAC,CAAC,CAAC;IACL,CAAC;IAED;;OAEG;IACI,GAAG,CAAuD,EAAK,EAAE,GAAG,IAAO;QAChF,OAAO,QAAQ,CAAC,iBAAiB,CAAC,GAAG,CAAC,IAAI,CAAC,OAAO,EAAE,EAAE,EAAE,GAAG,IAAI,CAAC,CAAC;IACnE,CAAC;CACF;AA/BD,0DA+BC"}
package/lib/utils.js CHANGED
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.createNamespace = exports.waitOnNamespace = void 0;
4
- const internal_workflow_common_1 = require("@temporalio/internal-workflow-common");
4
+ const time_1 = require("@temporalio/common/lib/time");
5
5
  async function waitOnNamespace(connection, namespace, maxAttempts = 100, retryIntervalSecs = 1) {
6
6
  const runId = '12345678-dead-beef-1234-1234567890ab';
7
7
  for (let attempt = 1; attempt <= maxAttempts; ++attempt) {
@@ -28,7 +28,7 @@ async function createNamespace(connection, namespace, maxAttempts = 100, retryIn
28
28
  try {
29
29
  await connection.workflowService.registerNamespace({
30
30
  namespace,
31
- workflowExecutionRetentionPeriod: (0, internal_workflow_common_1.msToTs)('1 day'),
31
+ workflowExecutionRetentionPeriod: (0, time_1.msToTs)('1 day'),
32
32
  });
33
33
  break;
34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