@fluidframework/task-manager 2.0.0-rc.2.0.2 → 2.0.0-rc.3.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +23 -0
- package/api-report/task-manager.api.md +5 -5
- package/dist/interfaces.d.ts +3 -3
- package/dist/interfaces.js.map +1 -1
- package/dist/legacy.d.ts +17 -0
- package/dist/packageVersion.d.ts +1 -1
- package/dist/packageVersion.js +1 -1
- package/dist/packageVersion.js.map +1 -1
- package/dist/public.d.ts +12 -0
- package/dist/taskManager.d.ts +4 -3
- package/dist/taskManager.d.ts.map +1 -1
- package/dist/taskManager.js +22 -22
- package/dist/taskManager.js.map +1 -1
- package/dist/taskManagerFactory.d.ts +1 -1
- package/dist/taskManagerFactory.d.ts.map +1 -1
- package/dist/taskManagerFactory.js +1 -1
- package/dist/taskManagerFactory.js.map +1 -1
- package/internal.d.ts +11 -0
- package/legacy.d.ts +11 -0
- package/lib/interfaces.d.ts +3 -3
- package/lib/interfaces.js.map +1 -1
- package/lib/legacy.d.ts +17 -0
- package/lib/packageVersion.d.ts +1 -1
- package/lib/packageVersion.js +1 -1
- package/lib/packageVersion.js.map +1 -1
- package/lib/public.d.ts +12 -0
- package/lib/taskManager.d.ts +4 -3
- package/lib/taskManager.d.ts.map +1 -1
- package/lib/taskManager.js +4 -4
- package/lib/taskManager.js.map +1 -1
- package/lib/taskManagerFactory.d.ts +1 -1
- package/lib/taskManagerFactory.d.ts.map +1 -1
- package/lib/taskManagerFactory.js +1 -1
- package/lib/taskManagerFactory.js.map +1 -1
- package/package.json +36 -47
- package/src/interfaces.ts +3 -3
- package/src/packageVersion.ts +1 -1
- package/src/taskManager.ts +11 -13
- package/src/taskManagerFactory.ts +4 -3
- package/api-extractor-cjs.json +0 -8
- package/dist/task-manager-alpha.d.ts +0 -27
- package/dist/task-manager-beta.d.ts +0 -29
- package/dist/task-manager-public.d.ts +0 -29
- package/dist/task-manager-untrimmed.d.ts +0 -335
- package/lib/task-manager-alpha.d.ts +0 -27
- package/lib/task-manager-beta.d.ts +0 -29
- package/lib/task-manager-public.d.ts +0 -29
- package/lib/task-manager-untrimmed.d.ts +0 -335
- package/lib/test/dirname.cjs +0 -16
- package/lib/test/dirname.cjs.map +0 -1
- package/lib/test/taskManager.fuzz.spec.js +0 -203
- package/lib/test/taskManager.fuzz.spec.js.map +0 -1
- package/lib/test/taskManager.spec.js +0 -845
- package/lib/test/taskManager.spec.js.map +0 -1
- package/lib/test/types/validateTaskManagerPrevious.generated.js +0 -12
- package/lib/test/types/validateTaskManagerPrevious.generated.js.map +0 -1
- /package/{dist → lib}/tsdoc-metadata.json +0 -0
|
@@ -1,335 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Contains a distributed data structure, {@link ITaskManager}, to track the queues of clients that want to
|
|
3
|
-
* exclusively run tasks.
|
|
4
|
-
*
|
|
5
|
-
* @packageDocumentation
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
import { IChannelAttributes } from '@fluidframework/datastore-definitions';
|
|
9
|
-
import { IChannelFactory } from '@fluidframework/datastore-definitions';
|
|
10
|
-
import { IChannelStorageService } from '@fluidframework/datastore-definitions';
|
|
11
|
-
import { IFluidDataStoreRuntime } from '@fluidframework/datastore-definitions';
|
|
12
|
-
import { IFluidSerializer } from '@fluidframework/shared-object-base';
|
|
13
|
-
import { ISequencedDocumentMessage } from '@fluidframework/protocol-definitions';
|
|
14
|
-
import { ISharedObject } from '@fluidframework/shared-object-base';
|
|
15
|
-
import { ISharedObjectEvents } from '@fluidframework/shared-object-base';
|
|
16
|
-
import { ISummaryTreeWithStats } from '@fluidframework/runtime-definitions';
|
|
17
|
-
import { SharedObject } from '@fluidframework/shared-object-base';
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* A distributed data structure that tracks queues of clients that want to exclusively run a task.
|
|
21
|
-
*
|
|
22
|
-
* @example Creation
|
|
23
|
-
*
|
|
24
|
-
* To create a {@link TaskManager}, call the static create method:
|
|
25
|
-
*
|
|
26
|
-
* ```typescript
|
|
27
|
-
* const taskManager = TaskManager.create(this.runtime, id);
|
|
28
|
-
* ```
|
|
29
|
-
*
|
|
30
|
-
* @example Usage
|
|
31
|
-
*
|
|
32
|
-
* To volunteer for a task, use the {@link ITaskManager.volunteerForTask} method.
|
|
33
|
-
* This returns a Promise that will resolve once the client has acquired exclusive rights to run the task,
|
|
34
|
-
* or reject if the client is removed from the queue without acquiring the rights.
|
|
35
|
-
*
|
|
36
|
-
* ```typescript
|
|
37
|
-
* taskManager.volunteerForTask("NameOfTask")
|
|
38
|
-
* .then(() => { doTheTask(); })
|
|
39
|
-
* .catch((err) => { console.error(err); });
|
|
40
|
-
* ```
|
|
41
|
-
*
|
|
42
|
-
* Alternatively, you can indefinitely volunteer for a task with the synchronous {@link ITaskManager.subscribeToTask}
|
|
43
|
-
* method. This method does not return a value, therefore you need to rely on eventing to know when you have acquired
|
|
44
|
-
* the rights to run the task (see below).
|
|
45
|
-
*
|
|
46
|
-
* ```typescript
|
|
47
|
-
* taskManager.subscribeToTask("NameOfTask");
|
|
48
|
-
* ```
|
|
49
|
-
*
|
|
50
|
-
* To check if the local client is currently subscribed to a task, use the {@link ITaskManager.subscribed} method.
|
|
51
|
-
*
|
|
52
|
-
* ```typescript
|
|
53
|
-
* if (taskManager.subscribed("NameOfTask")) {
|
|
54
|
-
* console.log("This client is currently subscribed to the task.");
|
|
55
|
-
* }
|
|
56
|
-
* ```
|
|
57
|
-
*
|
|
58
|
-
* To release the rights to the task, use the {@link ITaskManager.abandon} method.
|
|
59
|
-
* The next client in the queue will then get the rights to run the task.
|
|
60
|
-
*
|
|
61
|
-
* ```typescript
|
|
62
|
-
* taskManager.abandon("NameOfTask");
|
|
63
|
-
* ```
|
|
64
|
-
*
|
|
65
|
-
* To inspect your state in the queue, you can use the {@link ITaskManager.queued} and {@link ITaskManager.assigned}
|
|
66
|
-
* methods.
|
|
67
|
-
*
|
|
68
|
-
* ```typescript
|
|
69
|
-
* if (taskManager.queued("NameOfTask")) {
|
|
70
|
-
* console.log("This client is somewhere in the queue, potentially even having the task assignment.");
|
|
71
|
-
* }
|
|
72
|
-
*
|
|
73
|
-
* if (taskManager.assigned("NameOfTask")) {
|
|
74
|
-
* console.log("This client currently has the rights to run the task");
|
|
75
|
-
* }
|
|
76
|
-
* ```
|
|
77
|
-
*
|
|
78
|
-
* To signal to other connected clients that a task is completed, use the {@link ITaskManager.complete} method.
|
|
79
|
-
* This will release all clients from the queue and emit the "completed" event.
|
|
80
|
-
*
|
|
81
|
-
* ```typescript
|
|
82
|
-
* taskManager.complete("NameOfTask");
|
|
83
|
-
* ```
|
|
84
|
-
*
|
|
85
|
-
* @example Eventing
|
|
86
|
-
*
|
|
87
|
-
* `ITaskManager` will emit events when a task is assigned to the client, when the task assignment is lost,
|
|
88
|
-
* and when a task was completed by another client.
|
|
89
|
-
*
|
|
90
|
-
* ```typescript
|
|
91
|
-
* taskManager.on("assigned", (taskId: string) => {
|
|
92
|
-
* console.log(`Client was assigned task: ${taskId}`);
|
|
93
|
-
* });
|
|
94
|
-
*
|
|
95
|
-
* taskManager.on("lost", (taskId: string) => {
|
|
96
|
-
* console.log(`Client released task: ${taskId}`);
|
|
97
|
-
* });
|
|
98
|
-
*
|
|
99
|
-
* taskManager.on("completed", (taskId: string) => {
|
|
100
|
-
* console.log(`Another client completed task: ${taskId}`);
|
|
101
|
-
* });
|
|
102
|
-
* ```
|
|
103
|
-
*
|
|
104
|
-
* These can be useful if the logic to volunteer for a task is separated from the logic to perform the task, such as
|
|
105
|
-
* when using {@link ITaskManager.subscribeToTask}.
|
|
106
|
-
*
|
|
107
|
-
* See {@link ITaskManagerEvents} for more details.
|
|
108
|
-
* @internal
|
|
109
|
-
*/
|
|
110
|
-
export declare interface ITaskManager extends ISharedObject<ITaskManagerEvents> {
|
|
111
|
-
/**
|
|
112
|
-
* Volunteer for the task. Returns a promise that resolves `true` if the task is assigned to the local client and
|
|
113
|
-
* `false` if the task was completed by another client. It rejects if the local client abandoned the task or
|
|
114
|
-
* disconnected while in queue.
|
|
115
|
-
* @param taskId - Identifier for the task
|
|
116
|
-
*/
|
|
117
|
-
volunteerForTask(taskId: string): Promise<boolean>;
|
|
118
|
-
/**
|
|
119
|
-
* Continuously volunteer for the task. Watch the "assigned" event to determine if the task is assigned.
|
|
120
|
-
* The local client will automatically re-enter the queue if it disconnects.
|
|
121
|
-
* @param taskId - Identifier for the task
|
|
122
|
-
*/
|
|
123
|
-
subscribeToTask(taskId: string): void;
|
|
124
|
-
/**
|
|
125
|
-
* Exit the queue, releasing the task if currently assigned.
|
|
126
|
-
* @param taskId - Identifier for the task
|
|
127
|
-
*/
|
|
128
|
-
abandon(taskId: string): void;
|
|
129
|
-
/**
|
|
130
|
-
* Check whether this client is the current assignee for the task and there is no outstanding abandon op that
|
|
131
|
-
* would abandon the assignment.
|
|
132
|
-
* @param taskId - Identifier for the task
|
|
133
|
-
*/
|
|
134
|
-
assigned(taskId: string): boolean;
|
|
135
|
-
/**
|
|
136
|
-
* Check whether this client is either the current assignee, in queue, or we expect they will be in queue after
|
|
137
|
-
* outstanding ops have been ack'd.
|
|
138
|
-
* @param taskId - Identifier for the task
|
|
139
|
-
*/
|
|
140
|
-
queued(taskId: string): boolean;
|
|
141
|
-
/**
|
|
142
|
-
* Check whether this client is currently subscribed to the task.
|
|
143
|
-
* @param taskId - Identifier for the task
|
|
144
|
-
*/
|
|
145
|
-
subscribed(taskId: string): boolean;
|
|
146
|
-
/**
|
|
147
|
-
* Marks a task as completed and releases all clients from its queue.
|
|
148
|
-
* @param taskId - Identifier for the task
|
|
149
|
-
*/
|
|
150
|
-
complete(taskId: string): void;
|
|
151
|
-
/**
|
|
152
|
-
* Check whether this client can currently volunteer for a task.
|
|
153
|
-
*/
|
|
154
|
-
canVolunteer(): boolean;
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
/**
|
|
158
|
-
* Events emitted by {@link TaskManager}.
|
|
159
|
-
* @internal
|
|
160
|
-
*/
|
|
161
|
-
export declare interface ITaskManagerEvents extends ISharedObjectEvents {
|
|
162
|
-
/**
|
|
163
|
-
* Fires when a task has been exclusively assigned to the client.
|
|
164
|
-
*
|
|
165
|
-
* @remarks Does not account for known pending ops, but instead only reflects the current state.
|
|
166
|
-
*
|
|
167
|
-
* @eventProperty
|
|
168
|
-
*/
|
|
169
|
-
(event: "assigned", listener: TaskEventListener): any;
|
|
170
|
-
/**
|
|
171
|
-
* Fires when a task the client is queued for is completed.
|
|
172
|
-
*
|
|
173
|
-
* @eventProperty
|
|
174
|
-
*/
|
|
175
|
-
(event: "completed", listener: TaskEventListener): any;
|
|
176
|
-
/**
|
|
177
|
-
* Fires when the task assignment is lost by the local client.
|
|
178
|
-
*
|
|
179
|
-
* @remarks This could be due to the client disconnecting or by manually calling {@link ITaskManager.abandon}.
|
|
180
|
-
*
|
|
181
|
-
* @eventProperty
|
|
182
|
-
*/
|
|
183
|
-
(event: "lost", listener: TaskEventListener): any;
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
/**
|
|
187
|
-
* Describes the event listener format for {@link ITaskManagerEvents} events.
|
|
188
|
-
*
|
|
189
|
-
* @param taskId - The unique identifier of the related task.
|
|
190
|
-
* @internal
|
|
191
|
-
*/
|
|
192
|
-
export declare type TaskEventListener = (taskId: string) => void;
|
|
193
|
-
|
|
194
|
-
/**
|
|
195
|
-
* {@inheritDoc ITaskManager}
|
|
196
|
-
*
|
|
197
|
-
* @sealed
|
|
198
|
-
* @internal
|
|
199
|
-
*/
|
|
200
|
-
export declare class TaskManager extends SharedObject<ITaskManagerEvents> implements ITaskManager {
|
|
201
|
-
/**
|
|
202
|
-
* Create a new TaskManager
|
|
203
|
-
*
|
|
204
|
-
* @param runtime - data store runtime the new task queue belongs to
|
|
205
|
-
* @param id - optional name of the task queue
|
|
206
|
-
* @returns newly create task queue (but not attached yet)
|
|
207
|
-
*/
|
|
208
|
-
static create(runtime: IFluidDataStoreRuntime, id?: string): TaskManager;
|
|
209
|
-
/**
|
|
210
|
-
* Get a factory for TaskManager to register with the data store.
|
|
211
|
-
*
|
|
212
|
-
* @returns a factory that creates and load TaskManager
|
|
213
|
-
*/
|
|
214
|
-
static getFactory(): IChannelFactory;
|
|
215
|
-
/**
|
|
216
|
-
* Mapping of taskId to a queue of clientIds that are waiting on the task. Maintains the consensus state of the
|
|
217
|
-
* queue, even if we know we've submitted an op that should eventually modify the queue.
|
|
218
|
-
*/
|
|
219
|
-
private readonly taskQueues;
|
|
220
|
-
private readonly opWatcher;
|
|
221
|
-
private readonly queueWatcher;
|
|
222
|
-
private readonly abandonWatcher;
|
|
223
|
-
private readonly connectionWatcher;
|
|
224
|
-
private readonly completedWatcher;
|
|
225
|
-
private messageId;
|
|
226
|
-
/**
|
|
227
|
-
* Tracks the most recent pending op for a given task
|
|
228
|
-
*/
|
|
229
|
-
private readonly latestPendingOps;
|
|
230
|
-
/**
|
|
231
|
-
* Tracks tasks that are this client is currently subscribed to.
|
|
232
|
-
*/
|
|
233
|
-
private readonly subscribedTasks;
|
|
234
|
-
/**
|
|
235
|
-
* Map to track tasks that have pending complete ops.
|
|
236
|
-
*/
|
|
237
|
-
private readonly pendingCompletedTasks;
|
|
238
|
-
/**
|
|
239
|
-
* Returns the clientId. Will return a placeholder if the runtime is detached and not yet assigned a clientId.
|
|
240
|
-
*/
|
|
241
|
-
private get clientId();
|
|
242
|
-
/**
|
|
243
|
-
* Returns a ReadOnlyInfo object to determine current read/write permissions.
|
|
244
|
-
*/
|
|
245
|
-
private get readOnlyInfo();
|
|
246
|
-
/**
|
|
247
|
-
* Constructs a new task manager. If the object is non-local an id and service interfaces will
|
|
248
|
-
* be provided
|
|
249
|
-
*
|
|
250
|
-
* @param runtime - data store runtime the task queue belongs to
|
|
251
|
-
* @param id - optional name of the task queue
|
|
252
|
-
*/
|
|
253
|
-
constructor(id: string, runtime: IFluidDataStoreRuntime, attributes: IChannelAttributes);
|
|
254
|
-
private submitVolunteerOp;
|
|
255
|
-
private submitAbandonOp;
|
|
256
|
-
private submitCompleteOp;
|
|
257
|
-
/**
|
|
258
|
-
* {@inheritDoc ITaskManager.volunteerForTask}
|
|
259
|
-
*/
|
|
260
|
-
volunteerForTask(taskId: string): Promise<boolean>;
|
|
261
|
-
/**
|
|
262
|
-
* {@inheritDoc ITaskManager.subscribeToTask}
|
|
263
|
-
*/
|
|
264
|
-
subscribeToTask(taskId: string): void;
|
|
265
|
-
/**
|
|
266
|
-
* {@inheritDoc ITaskManager.abandon}
|
|
267
|
-
*/
|
|
268
|
-
abandon(taskId: string): void;
|
|
269
|
-
/**
|
|
270
|
-
* {@inheritDoc ITaskManager.assigned}
|
|
271
|
-
*/
|
|
272
|
-
assigned(taskId: string): boolean;
|
|
273
|
-
/**
|
|
274
|
-
* {@inheritDoc ITaskManager.queued}
|
|
275
|
-
*/
|
|
276
|
-
queued(taskId: string): boolean;
|
|
277
|
-
/**
|
|
278
|
-
* {@inheritDoc ITaskManager.subscribed}
|
|
279
|
-
*/
|
|
280
|
-
subscribed(taskId: string): boolean;
|
|
281
|
-
/**
|
|
282
|
-
* {@inheritDoc ITaskManager.complete}
|
|
283
|
-
*/
|
|
284
|
-
complete(taskId: string): void;
|
|
285
|
-
/**
|
|
286
|
-
* {@inheritDoc ITaskManager.canVolunteer}
|
|
287
|
-
*/
|
|
288
|
-
canVolunteer(): boolean;
|
|
289
|
-
/**
|
|
290
|
-
* Create a summary for the task manager
|
|
291
|
-
*
|
|
292
|
-
* @returns the summary of the current state of the task manager
|
|
293
|
-
*/
|
|
294
|
-
protected summarizeCore(serializer: IFluidSerializer): ISummaryTreeWithStats;
|
|
295
|
-
/**
|
|
296
|
-
* {@inheritDoc @fluidframework/shared-object-base#SharedObject.loadCore}
|
|
297
|
-
*/
|
|
298
|
-
protected loadCore(storage: IChannelStorageService): Promise<void>;
|
|
299
|
-
/***/
|
|
300
|
-
protected initializeLocalCore(): void;
|
|
301
|
-
/**
|
|
302
|
-
* {@inheritDoc @fluidframework/shared-object-base#SharedObject.onDisconnect}
|
|
303
|
-
*/
|
|
304
|
-
protected onDisconnect(): void;
|
|
305
|
-
/**
|
|
306
|
-
* {@inheritDoc @fluidframework/shared-object-base#SharedObject.onConnect}
|
|
307
|
-
*/
|
|
308
|
-
protected onConnect(): void;
|
|
309
|
-
/**
|
|
310
|
-
* Override resubmit core to avoid resubmission on reconnect. On disconnect we accept our removal from the
|
|
311
|
-
* queues, and leave it up to the user to decide whether they want to attempt to re-enter a queue on reconnect.
|
|
312
|
-
*/
|
|
313
|
-
protected reSubmitCore(): void;
|
|
314
|
-
/**
|
|
315
|
-
* Process a task manager operation
|
|
316
|
-
*
|
|
317
|
-
* @param message - the message to prepare
|
|
318
|
-
* @param local - whether the message was sent by the local client
|
|
319
|
-
* @param localOpMetadata - For local client messages, this is the metadata that was submitted with the message.
|
|
320
|
-
* For messages from a remote client, this will be undefined.
|
|
321
|
-
*/
|
|
322
|
-
protected processCore(message: ISequencedDocumentMessage, local: boolean, localOpMetadata: unknown): void;
|
|
323
|
-
private addClientToQueue;
|
|
324
|
-
private removeClientFromQueue;
|
|
325
|
-
private removeClientFromAllQueues;
|
|
326
|
-
/**
|
|
327
|
-
* Will replace all instances of the placeholderClientId with the current clientId. This should only be called when
|
|
328
|
-
* transitioning from detached to attached and this.runtime.clientId is defined.
|
|
329
|
-
*/
|
|
330
|
-
private replacePlaceholderInAllQueues;
|
|
331
|
-
private scrubClientsNotInQuorum;
|
|
332
|
-
protected applyStashedOp(content: any): void;
|
|
333
|
-
}
|
|
334
|
-
|
|
335
|
-
export { }
|
package/lib/test/dirname.cjs
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/*!
|
|
3
|
-
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
4
|
-
* Licensed under the MIT License.
|
|
5
|
-
*/
|
|
6
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
-
exports._dirname = void 0;
|
|
8
|
-
// Problem:
|
|
9
|
-
// - `__dirname` is not defined in ESM
|
|
10
|
-
// - `import.meta.url` is not defined in CJS
|
|
11
|
-
// Solution:
|
|
12
|
-
// - Export '__dirname' from a .cjs file in the same directory.
|
|
13
|
-
//
|
|
14
|
-
// Note that *.cjs files are always CommonJS, but can be imported from ESM.
|
|
15
|
-
exports._dirname = __dirname;
|
|
16
|
-
//# sourceMappingURL=dirname.cjs.map
|
package/lib/test/dirname.cjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"dirname.cjs","sourceRoot":"","sources":["../../src/test/dirname.cts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,WAAW;AACX,wCAAwC;AACxC,8CAA8C;AAC9C,YAAY;AACZ,iEAAiE;AACjE,EAAE;AACF,2EAA2E;AAC9D,QAAA,QAAQ,GAAG,SAAS,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\n// Problem:\n// - `__dirname` is not defined in ESM\n// - `import.meta.url` is not defined in CJS\n// Solution:\n// - Export '__dirname' from a .cjs file in the same directory.\n//\n// Note that *.cjs files are always CommonJS, but can be imported from ESM.\nexport const _dirname = __dirname;\n"]}
|
|
@@ -1,203 +0,0 @@
|
|
|
1
|
-
/*!
|
|
2
|
-
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
|
-
* Licensed under the MIT License.
|
|
4
|
-
*/
|
|
5
|
-
import * as path from "path";
|
|
6
|
-
import { strict as assert } from "assert";
|
|
7
|
-
import { combineReducersAsync as combineReducers, createWeightedAsyncGenerator as createWeightedGenerator, makeRandom, takeAsync as take, } from "@fluid-private/stochastic-test-utils";
|
|
8
|
-
import { createDDSFuzzSuite } from "@fluid-private/test-dds-utils";
|
|
9
|
-
import { FlushMode } from "@fluidframework/runtime-definitions";
|
|
10
|
-
import { TaskManagerFactory } from "../taskManagerFactory.js";
|
|
11
|
-
import { _dirname } from "./dirname.cjs";
|
|
12
|
-
const defaultOptions = {
|
|
13
|
-
taskPoolSize: 3,
|
|
14
|
-
taskStringLength: 5,
|
|
15
|
-
validateInterval: 10,
|
|
16
|
-
testCount: 10,
|
|
17
|
-
operations: 100,
|
|
18
|
-
};
|
|
19
|
-
function makeOperationGenerator(optionsParam) {
|
|
20
|
-
const options = { ...defaultOptions, ...(optionsParam ?? {}) };
|
|
21
|
-
const taskIdPoolRandom = makeRandom(0);
|
|
22
|
-
const dedupe = (arr) => Array.from(new Set(arr));
|
|
23
|
-
const taskIdPool = dedupe(Array.from({ length: options.taskPoolSize }, () => taskIdPoolRandom.string(defaultOptions.taskStringLength)));
|
|
24
|
-
async function volunteer(state) {
|
|
25
|
-
return {
|
|
26
|
-
type: "volunteer",
|
|
27
|
-
taskId: state.taskId,
|
|
28
|
-
};
|
|
29
|
-
}
|
|
30
|
-
async function abandon(state) {
|
|
31
|
-
return {
|
|
32
|
-
type: "abandon",
|
|
33
|
-
taskId: state.taskId,
|
|
34
|
-
};
|
|
35
|
-
}
|
|
36
|
-
async function subscribe(state) {
|
|
37
|
-
return {
|
|
38
|
-
type: "subscribe",
|
|
39
|
-
taskId: state.taskId,
|
|
40
|
-
};
|
|
41
|
-
}
|
|
42
|
-
async function complete(state) {
|
|
43
|
-
return {
|
|
44
|
-
type: "complete",
|
|
45
|
-
taskId: state.taskId,
|
|
46
|
-
};
|
|
47
|
-
}
|
|
48
|
-
const canVolunteer = ({ client }) => client.channel.canVolunteer();
|
|
49
|
-
const isQueued = ({ client, taskId }) => client.channel.queued(taskId);
|
|
50
|
-
const isAssigned = ({ client, taskId }) => client.channel.assigned(taskId);
|
|
51
|
-
const clientBaseOperationGenerator = createWeightedGenerator([
|
|
52
|
-
[volunteer, 1, canVolunteer],
|
|
53
|
-
[abandon, 1, isQueued],
|
|
54
|
-
[subscribe, 1],
|
|
55
|
-
[complete, 1, isAssigned],
|
|
56
|
-
]);
|
|
57
|
-
return async (state) => clientBaseOperationGenerator({
|
|
58
|
-
...state,
|
|
59
|
-
taskId: state.random.pick(taskIdPool),
|
|
60
|
-
});
|
|
61
|
-
}
|
|
62
|
-
function logCurrentState(state, loggingInfo) {
|
|
63
|
-
for (const client of state.clients) {
|
|
64
|
-
const taskManager = client.channel;
|
|
65
|
-
assert(taskManager);
|
|
66
|
-
if (loggingInfo.taskManagerNames.includes(client.containerRuntime.clientId)) {
|
|
67
|
-
console.log(`TaskManager ${taskManager.id} (CanVolunteer: ${taskManager.canVolunteer()}):`);
|
|
68
|
-
console.log(taskManager.taskQueues.get(loggingInfo.taskId));
|
|
69
|
-
console.log("\n");
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
function makeReducer(loggingInfo) {
|
|
74
|
-
const withLogging = (baseReducer) => async (state, operation) => {
|
|
75
|
-
if (loggingInfo !== undefined && operation.taskId === loggingInfo.taskId) {
|
|
76
|
-
logCurrentState(state, loggingInfo);
|
|
77
|
-
console.log("-".repeat(20));
|
|
78
|
-
console.log("Next operation:", JSON.stringify(operation, undefined, 4));
|
|
79
|
-
}
|
|
80
|
-
await baseReducer(state, operation);
|
|
81
|
-
};
|
|
82
|
-
const reducer = combineReducers({
|
|
83
|
-
volunteer: async ({ client }, { taskId }) => {
|
|
84
|
-
// Note: this is fire-and-forget as `volunteerForTask` resolves/rejects its returned
|
|
85
|
-
// promise based on server responses, which will occur on later operations (and
|
|
86
|
-
// processing those operations will raise the error directly)
|
|
87
|
-
client.channel.volunteerForTask(taskId).catch((e) => {
|
|
88
|
-
// We expect an error to be thrown if we are disconnected while volunteering
|
|
89
|
-
const expectedErrors = [
|
|
90
|
-
"Disconnected before acquiring task assignment",
|
|
91
|
-
"Abandoned before acquiring task assignment",
|
|
92
|
-
];
|
|
93
|
-
if (!expectedErrors.includes(e.message)) {
|
|
94
|
-
throw e;
|
|
95
|
-
}
|
|
96
|
-
});
|
|
97
|
-
},
|
|
98
|
-
abandon: async ({ client }, { taskId }) => {
|
|
99
|
-
client.channel.abandon(taskId);
|
|
100
|
-
},
|
|
101
|
-
subscribe: async ({ client }, { taskId }) => {
|
|
102
|
-
client.channel.subscribeToTask(taskId);
|
|
103
|
-
},
|
|
104
|
-
complete: async ({ client }, { taskId }) => {
|
|
105
|
-
client.channel.complete(taskId);
|
|
106
|
-
},
|
|
107
|
-
});
|
|
108
|
-
return withLogging(reducer);
|
|
109
|
-
}
|
|
110
|
-
function assertEqualTaskManagers(a, b) {
|
|
111
|
-
const queue1 = a.taskQueues;
|
|
112
|
-
const queue2 = b.taskQueues;
|
|
113
|
-
assert.strictEqual(queue1.size, queue2.size, "The number of tasks queues are not the same");
|
|
114
|
-
for (const [key, val] of queue1) {
|
|
115
|
-
const testVal = queue2.get(key);
|
|
116
|
-
if (testVal === undefined) {
|
|
117
|
-
assert(val === undefined, "Task queues are not both undefined");
|
|
118
|
-
continue;
|
|
119
|
-
}
|
|
120
|
-
assert.strictEqual(testVal.length, val.length, "Task queues are not the same size");
|
|
121
|
-
if (testVal.length > 0) {
|
|
122
|
-
testVal.forEach((task, index) => {
|
|
123
|
-
assert.strictEqual(task, val[index], `Task queues are not identical`);
|
|
124
|
-
});
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
describe("TaskManager fuzz testing", () => {
|
|
129
|
-
const model = {
|
|
130
|
-
workloadName: "default configuration",
|
|
131
|
-
generatorFactory: () => take(100, makeOperationGenerator()),
|
|
132
|
-
reducer:
|
|
133
|
-
// makeReducer supports a param for logging output which tracks the provided intervalId over time:
|
|
134
|
-
// { taskManagerNames: ["A", "B", "C"], taskId: "" },
|
|
135
|
-
makeReducer(),
|
|
136
|
-
validateConsistency: assertEqualTaskManagers,
|
|
137
|
-
factory: new TaskManagerFactory(),
|
|
138
|
-
};
|
|
139
|
-
createDDSFuzzSuite(model, {
|
|
140
|
-
validationStrategy: { type: "fixedInterval", interval: defaultOptions.validateInterval },
|
|
141
|
-
// AB#3985: TaskManager has some eventual consistency issue with reconnect enabled.
|
|
142
|
-
// To make this configuration similar to pre-generic DDS fuzz harness refactor, this constant
|
|
143
|
-
// should be 0.2.
|
|
144
|
-
// Leaving the tests enabled without reconnect on mimics previous behavior (and provides more coverage
|
|
145
|
-
// than skipping them)
|
|
146
|
-
reconnectProbability: 0,
|
|
147
|
-
detachedStartOptions: {
|
|
148
|
-
numOpsBeforeAttach: 5,
|
|
149
|
-
// similar to reconnect there are eventual consistency errors when we enter attaching before rehydrate
|
|
150
|
-
// when fixed, detachedStartOptions can be removed from this config, and attachingBeforeRehydrateDisable
|
|
151
|
-
// can be completely removed, as it is only used by this test. Rather than file more bugs. I'll just combine
|
|
152
|
-
// this with AB#3985, as it looks like the dds has fundamental issue around lifecycle handling
|
|
153
|
-
attachingBeforeRehydrateDisable: true,
|
|
154
|
-
},
|
|
155
|
-
clientJoinOptions: {
|
|
156
|
-
maxNumberOfClients: 6,
|
|
157
|
-
clientAddProbability: 0.05,
|
|
158
|
-
stashableClientProbability: 0.2,
|
|
159
|
-
},
|
|
160
|
-
defaultTestCount: defaultOptions.testCount,
|
|
161
|
-
saveFailures: { directory: path.join(_dirname, "../../src/test/results") },
|
|
162
|
-
// Uncomment this line to replay a specific seed:
|
|
163
|
-
// replay: 0,
|
|
164
|
-
// This can be useful for quickly minimizing failure json while attempting to root-cause a failure.
|
|
165
|
-
});
|
|
166
|
-
});
|
|
167
|
-
describe("TaskManager fuzz testing with rebasing", () => {
|
|
168
|
-
const model = {
|
|
169
|
-
workloadName: "default configuration and rebasing",
|
|
170
|
-
generatorFactory: () => take(100, makeOperationGenerator()),
|
|
171
|
-
reducer:
|
|
172
|
-
// makeReducer supports a param for logging output which tracks the provided intervalId over time:
|
|
173
|
-
// { taskManagerNames: ["A", "B", "C"], taskId: "" },
|
|
174
|
-
makeReducer(),
|
|
175
|
-
validateConsistency: assertEqualTaskManagers,
|
|
176
|
-
factory: new TaskManagerFactory(),
|
|
177
|
-
};
|
|
178
|
-
createDDSFuzzSuite(model, {
|
|
179
|
-
validationStrategy: { type: "fixedInterval", interval: defaultOptions.validateInterval },
|
|
180
|
-
// AB#5185: enabling rebasing indicates some unknown eventual consistency issue
|
|
181
|
-
skip: [5, 7],
|
|
182
|
-
rebaseProbability: 0.15,
|
|
183
|
-
containerRuntimeOptions: {
|
|
184
|
-
flushMode: FlushMode.TurnBased,
|
|
185
|
-
enableGroupedBatching: true,
|
|
186
|
-
},
|
|
187
|
-
clientJoinOptions: {
|
|
188
|
-
maxNumberOfClients: 6,
|
|
189
|
-
clientAddProbability: 0.05,
|
|
190
|
-
stashableClientProbability: 0.2,
|
|
191
|
-
},
|
|
192
|
-
defaultTestCount: defaultOptions.testCount,
|
|
193
|
-
saveFailures: { directory: path.join(_dirname, "../../src/test/results") },
|
|
194
|
-
// AB#5341: enabling 'start from detached' within the fuzz harness demonstrates eventual consistency failures.
|
|
195
|
-
detachedStartOptions: {
|
|
196
|
-
numOpsBeforeAttach: 0,
|
|
197
|
-
},
|
|
198
|
-
// Uncomment this line to replay a specific seed:
|
|
199
|
-
// replay: 0,
|
|
200
|
-
// This can be useful for quickly minimizing failure json while attempting to root-cause a failure.
|
|
201
|
-
});
|
|
202
|
-
});
|
|
203
|
-
//# sourceMappingURL=taskManager.fuzz.spec.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"taskManager.fuzz.spec.js","sourceRoot":"","sources":["../../src/test/taskManager.fuzz.spec.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAC7B,OAAO,EAAE,MAAM,IAAI,MAAM,EAAE,MAAM,QAAQ,CAAC;AAC1C,OAAO,EACN,oBAAoB,IAAI,eAAe,EACvC,4BAA4B,IAAI,uBAAuB,EAEvD,UAAU,EAEV,SAAS,IAAI,IAAI,GACjB,MAAM,sCAAsC,CAAC;AAC9C,OAAO,EAAE,kBAAkB,EAAkC,MAAM,+BAA+B,CAAC;AACnG,OAAO,EAAE,SAAS,EAAE,MAAM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A+D;QACzE,YAAY,EAAE,oCAAoC;QAClD,gBAAgB,EAAE,GAAG,EAAE,CAAC,IAAI,CAAC,GAAG,EAAE,sBAAsB,EAAE,CAAC;QAC3D,OAAO;QACN,kGAAkG;QAClG,qDAAqD;QACrD,WAAW,EAAE;QACd,mBAAmB,EAAE,uBAAuB;QAC5C,OAAO,EAAE,IAAI,kBAAkB,EAAE;KACjC,CAAC;IAEF,kBAAkB,CAAC,KAAK,EAAE;QACzB,kBAAkB,EAAE,EAAE,IAAI,EAAE,eAAe,EAAE,QAAQ,EAAE,cAAc,CAAC,gBAAgB,EAAE;QACxF,+EAA+E;QAC/E,IAAI,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC;QACZ,iBAAiB,EAAE,IAAI;QACvB,uBAAuB,EAAE;YACxB,SAAS,EAAE,SAAS,CAAC,SAAS;YAC9B,qBAAqB,EAAE,IAAI;SAC3B;QACD,iBAAiB,EAAE;YAClB,kBAAkB,EAAE,CAAC;YACrB,oBAAoB,EAAE,IAAI;YAC1B,0BAA0B,EAAE,GAAG;SAC/B;QACD,gBAAgB,EAAE,cAAc,CAAC,SAAS;QAC1C,YAAY,EAAE,EAAE,SAAS,EAAE,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,wBAAwB,CAAC,EAAE;QAC1E,8GAA8G;QAC9G,oBAAoB,EAAE;YACrB,kBAAkB,EAAE,CAAC;SACrB;QACD,iDAAiD;QACjD,aAAa;QACb,mGAAmG;KACnG,CAAC,CAAC;AACJ,CAAC,CAAC,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport * as path from \"path\";\nimport { strict as assert } from \"assert\";\nimport {\n\tcombineReducersAsync as combineReducers,\n\tcreateWeightedAsyncGenerator as createWeightedGenerator,\n\tAsyncGenerator as Generator,\n\tmakeRandom,\n\tAsyncReducer as Reducer,\n\ttakeAsync as take,\n} from \"@fluid-private/stochastic-test-utils\";\nimport { createDDSFuzzSuite, DDSFuzzModel, DDSFuzzTestState } from \"@fluid-private/test-dds-utils\";\nimport { FlushMode } from \"@fluidframework/runtime-definitions\";\nimport { TaskManagerFactory } from \"../taskManagerFactory.js\";\nimport { ITaskManager } from \"../interfaces.js\";\nimport { _dirname } from \"./dirname.cjs\";\n\ntype FuzzTestState = DDSFuzzTestState<TaskManagerFactory>;\n\ninterface TaskOperation {\n\t/** The Id of the task that the operation applies to. */\n\ttaskId: string;\n}\n\ninterface Volunteer extends TaskOperation {\n\ttype: \"volunteer\";\n}\n\ninterface Abandon extends TaskOperation {\n\ttype: \"abandon\";\n}\n\ninterface Subscribe extends TaskOperation {\n\ttype: \"subscribe\";\n}\n\ninterface Complete extends TaskOperation {\n\ttype: \"complete\";\n}\n\ntype Operation = Volunteer | Abandon | Subscribe | Complete;\n\ninterface OperationGenerationConfig {\n\t/**\n\t * Number of task ids to be generated\n\t */\n\ttaskPoolSize?: number;\n\t/**\n\t * Length of taskId strings\n\t */\n\ttaskStringLength?: number;\n\t/**\n\t * Number of ops in between each synchronization/validation of the TaskManagers\n\t */\n\tvalidateInterval?: number;\n\t/**\n\t * Number of tests to generate\n\t */\n\ttestCount?: number;\n\t/**\n\t * Number of operations to perform in each test\n\t */\n\toperations?: number;\n}\n\nconst defaultOptions: Required<OperationGenerationConfig> = {\n\ttaskPoolSize: 3,\n\ttaskStringLength: 5,\n\tvalidateInterval: 10,\n\ttestCount: 10,\n\toperations: 100,\n};\n\nfunction makeOperationGenerator(\n\toptionsParam?: OperationGenerationConfig,\n): Generator<Operation, FuzzTestState> {\n\tconst options = { ...defaultOptions, ...(optionsParam ?? {}) };\n\ttype OpSelectionState = FuzzTestState & {\n\t\ttaskId: string;\n\t};\n\n\tconst taskIdPoolRandom = makeRandom(0);\n\tconst dedupe = <T>(arr: T[]): T[] => Array.from(new Set(arr));\n\tconst taskIdPool = dedupe(\n\t\tArray.from({ length: options.taskPoolSize }, () =>\n\t\t\ttaskIdPoolRandom.string(defaultOptions.taskStringLength),\n\t\t),\n\t);\n\n\tasync function volunteer(state: OpSelectionState): Promise<Volunteer> {\n\t\treturn {\n\t\t\ttype: \"volunteer\",\n\t\t\ttaskId: state.taskId,\n\t\t};\n\t}\n\n\tasync function abandon(state: OpSelectionState): Promise<Abandon> {\n\t\treturn {\n\t\t\ttype: \"abandon\",\n\t\t\ttaskId: state.taskId,\n\t\t};\n\t}\n\n\tasync function subscribe(state: OpSelectionState): Promise<Subscribe> {\n\t\treturn {\n\t\t\ttype: \"subscribe\",\n\t\t\ttaskId: state.taskId,\n\t\t};\n\t}\n\n\tasync function complete(state: OpSelectionState): Promise<Complete> {\n\t\treturn {\n\t\t\ttype: \"complete\",\n\t\t\ttaskId: state.taskId,\n\t\t};\n\t}\n\n\tconst canVolunteer = ({ client }: OpSelectionState): boolean => client.channel.canVolunteer();\n\tconst isQueued = ({ client, taskId }: OpSelectionState): boolean =>\n\t\tclient.channel.queued(taskId);\n\tconst isAssigned = ({ client, taskId }: OpSelectionState): boolean =>\n\t\tclient.channel.assigned(taskId);\n\n\tconst clientBaseOperationGenerator = createWeightedGenerator<Operation, OpSelectionState>([\n\t\t[volunteer, 1, canVolunteer],\n\t\t[abandon, 1, isQueued],\n\t\t[subscribe, 1],\n\t\t[complete, 1, isAssigned],\n\t]);\n\n\treturn async (state: FuzzTestState) =>\n\t\tclientBaseOperationGenerator({\n\t\t\t...state,\n\t\t\ttaskId: state.random.pick(taskIdPool),\n\t\t});\n}\n\ninterface LoggingInfo {\n\t/** ids of the Task Managers to track over time */\n\ttaskManagerNames: string[];\n\t/** ids of tasks to track over time */\n\ttaskId: string;\n}\n\nfunction logCurrentState(state: FuzzTestState, loggingInfo: LoggingInfo): void {\n\tfor (const client of state.clients) {\n\t\tconst taskManager = client.channel;\n\t\tassert(taskManager);\n\t\tif (loggingInfo.taskManagerNames.includes(client.containerRuntime.clientId)) {\n\t\t\tconsole.log(\n\t\t\t\t`TaskManager ${taskManager.id} (CanVolunteer: ${taskManager.canVolunteer()}):`,\n\t\t\t);\n\t\t\tconsole.log((taskManager as any).taskQueues.get(loggingInfo.taskId));\n\t\t\tconsole.log(\"\\n\");\n\t\t}\n\t}\n}\n\nfunction makeReducer(loggingInfo?: LoggingInfo): Reducer<Operation, FuzzTestState> {\n\tconst withLogging =\n\t\t<T>(baseReducer: Reducer<T, FuzzTestState>): Reducer<T, FuzzTestState> =>\n\t\tasync (state, operation) => {\n\t\t\tif (loggingInfo !== undefined && (operation as any).taskId === loggingInfo.taskId) {\n\t\t\t\tlogCurrentState(state, loggingInfo);\n\t\t\t\tconsole.log(\"-\".repeat(20));\n\t\t\t\tconsole.log(\"Next operation:\", JSON.stringify(operation, undefined, 4));\n\t\t\t}\n\t\t\tawait baseReducer(state, operation);\n\t\t};\n\n\tconst reducer = combineReducers<Operation, FuzzTestState>({\n\t\tvolunteer: async ({ client }, { taskId }) => {\n\t\t\t// Note: this is fire-and-forget as `volunteerForTask` resolves/rejects its returned\n\t\t\t// promise based on server responses, which will occur on later operations (and\n\t\t\t// processing those operations will raise the error directly)\n\t\t\tclient.channel.volunteerForTask(taskId).catch((e: Error) => {\n\t\t\t\t// We expect an error to be thrown if we are disconnected while volunteering\n\t\t\t\tconst expectedErrors = [\n\t\t\t\t\t\"Disconnected before acquiring task assignment\",\n\t\t\t\t\t\"Abandoned before acquiring task assignment\",\n\t\t\t\t];\n\t\t\t\tif (!expectedErrors.includes(e.message)) {\n\t\t\t\t\tthrow e;\n\t\t\t\t}\n\t\t\t});\n\t\t},\n\t\tabandon: async ({ client }, { taskId }) => {\n\t\t\tclient.channel.abandon(taskId);\n\t\t},\n\t\tsubscribe: async ({ client }, { taskId }) => {\n\t\t\tclient.channel.subscribeToTask(taskId);\n\t\t},\n\t\tcomplete: async ({ client }, { taskId }) => {\n\t\t\tclient.channel.complete(taskId);\n\t\t},\n\t});\n\n\treturn withLogging(reducer);\n}\n\nfunction assertEqualTaskManagers(a: ITaskManager, b: ITaskManager) {\n\tconst queue1 = (a as any).taskQueues;\n\tconst queue2 = (b as any).taskQueues;\n\tassert.strictEqual(queue1.size, queue2.size, \"The number of tasks queues are not the same\");\n\tfor (const [key, val] of queue1) {\n\t\tconst testVal = queue2.get(key);\n\t\tif (testVal === undefined) {\n\t\t\tassert(val === undefined, \"Task queues are not both undefined\");\n\t\t\tcontinue;\n\t\t}\n\t\tassert.strictEqual(testVal.length, val.length, \"Task queues are not the same size\");\n\t\tif (testVal.length > 0) {\n\t\t\ttestVal.forEach((task: string, index: number) => {\n\t\t\t\tassert.strictEqual(task, val[index], `Task queues are not identical`);\n\t\t\t});\n\t\t}\n\t}\n}\n\ndescribe(\"TaskManager fuzz testing\", () => {\n\tconst model: DDSFuzzModel<TaskManagerFactory, Operation, FuzzTestState> = {\n\t\tworkloadName: \"default configuration\",\n\t\tgeneratorFactory: () => take(100, makeOperationGenerator()),\n\t\treducer:\n\t\t\t// makeReducer supports a param for logging output which tracks the provided intervalId over time:\n\t\t\t// { taskManagerNames: [\"A\", \"B\", \"C\"], taskId: \"\" },\n\t\t\tmakeReducer(),\n\t\tvalidateConsistency: assertEqualTaskManagers,\n\t\tfactory: new TaskManagerFactory(),\n\t};\n\n\tcreateDDSFuzzSuite(model, {\n\t\tvalidationStrategy: { type: \"fixedInterval\", interval: defaultOptions.validateInterval },\n\t\t// AB#3985: TaskManager has some eventual consistency issue with reconnect enabled.\n\t\t// To make this configuration similar to pre-generic DDS fuzz harness refactor, this constant\n\t\t// should be 0.2.\n\t\t// Leaving the tests enabled without reconnect on mimics previous behavior (and provides more coverage\n\t\t// than skipping them)\n\t\treconnectProbability: 0,\n\t\tdetachedStartOptions: {\n\t\t\tnumOpsBeforeAttach: 5,\n\t\t\t// similar to reconnect there are eventual consistency errors when we enter attaching before rehydrate\n\t\t\t// when fixed, detachedStartOptions can be removed from this config, and attachingBeforeRehydrateDisable\n\t\t\t// can be completely removed, as it is only used by this test. Rather than file more bugs. I'll just combine\n\t\t\t// this with AB#3985, as it looks like the dds has fundamental issue around lifecycle handling\n\t\t\tattachingBeforeRehydrateDisable: true,\n\t\t},\n\t\tclientJoinOptions: {\n\t\t\tmaxNumberOfClients: 6,\n\t\t\tclientAddProbability: 0.05,\n\t\t\tstashableClientProbability: 0.2,\n\t\t},\n\t\tdefaultTestCount: defaultOptions.testCount,\n\t\tsaveFailures: { directory: path.join(_dirname, \"../../src/test/results\") },\n\t\t// Uncomment this line to replay a specific seed:\n\t\t// replay: 0,\n\t\t// This can be useful for quickly minimizing failure json while attempting to root-cause a failure.\n\t});\n});\n\ndescribe(\"TaskManager fuzz testing with rebasing\", () => {\n\tconst model: DDSFuzzModel<TaskManagerFactory, Operation, FuzzTestState> = {\n\t\tworkloadName: \"default configuration and rebasing\",\n\t\tgeneratorFactory: () => take(100, makeOperationGenerator()),\n\t\treducer:\n\t\t\t// makeReducer supports a param for logging output which tracks the provided intervalId over time:\n\t\t\t// { taskManagerNames: [\"A\", \"B\", \"C\"], taskId: \"\" },\n\t\t\tmakeReducer(),\n\t\tvalidateConsistency: assertEqualTaskManagers,\n\t\tfactory: new TaskManagerFactory(),\n\t};\n\n\tcreateDDSFuzzSuite(model, {\n\t\tvalidationStrategy: { type: \"fixedInterval\", interval: defaultOptions.validateInterval },\n\t\t// AB#5185: enabling rebasing indicates some unknown eventual consistency issue\n\t\tskip: [5, 7],\n\t\trebaseProbability: 0.15,\n\t\tcontainerRuntimeOptions: {\n\t\t\tflushMode: FlushMode.TurnBased,\n\t\t\tenableGroupedBatching: true,\n\t\t},\n\t\tclientJoinOptions: {\n\t\t\tmaxNumberOfClients: 6,\n\t\t\tclientAddProbability: 0.05,\n\t\t\tstashableClientProbability: 0.2,\n\t\t},\n\t\tdefaultTestCount: defaultOptions.testCount,\n\t\tsaveFailures: { directory: path.join(_dirname, \"../../src/test/results\") },\n\t\t// AB#5341: enabling 'start from detached' within the fuzz harness demonstrates eventual consistency failures.\n\t\tdetachedStartOptions: {\n\t\t\tnumOpsBeforeAttach: 0,\n\t\t},\n\t\t// Uncomment this line to replay a specific seed:\n\t\t// replay: 0,\n\t\t// This can be useful for quickly minimizing failure json while attempting to root-cause a failure.\n\t});\n});\n"]}
|