@fluidframework/test-utils 2.0.0-dev.2.2.0.111723 → 2.0.0-dev.3.1.0.125672

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (68) hide show
  1. package/.eslintrc.js +8 -7
  2. package/README.md +41 -11
  3. package/api-extractor.json +2 -2
  4. package/dist/DriverWrappers.d.ts.map +1 -1
  5. package/dist/DriverWrappers.js.map +1 -1
  6. package/dist/TestConfigs.d.ts.map +1 -1
  7. package/dist/TestConfigs.js +3 -2
  8. package/dist/TestConfigs.js.map +1 -1
  9. package/dist/TestSummaryUtils.d.ts +8 -3
  10. package/dist/TestSummaryUtils.d.ts.map +1 -1
  11. package/dist/TestSummaryUtils.js +23 -23
  12. package/dist/TestSummaryUtils.js.map +1 -1
  13. package/dist/containerUtils.d.ts +38 -0
  14. package/dist/containerUtils.d.ts.map +1 -0
  15. package/dist/containerUtils.js +58 -0
  16. package/dist/containerUtils.js.map +1 -0
  17. package/dist/index.d.ts +5 -4
  18. package/dist/index.d.ts.map +1 -1
  19. package/dist/index.js +4 -3
  20. package/dist/index.js.map +1 -1
  21. package/dist/interfaces.d.ts.map +1 -1
  22. package/dist/interfaces.js.map +1 -1
  23. package/dist/loaderContainerTracker.d.ts +0 -4
  24. package/dist/loaderContainerTracker.d.ts.map +1 -1
  25. package/dist/loaderContainerTracker.js +39 -38
  26. package/dist/loaderContainerTracker.js.map +1 -1
  27. package/dist/localCodeLoader.d.ts.map +1 -1
  28. package/dist/localCodeLoader.js.map +1 -1
  29. package/dist/localLoader.d.ts.map +1 -1
  30. package/dist/localLoader.js.map +1 -1
  31. package/dist/packageVersion.d.ts +1 -1
  32. package/dist/packageVersion.js +1 -1
  33. package/dist/packageVersion.js.map +1 -1
  34. package/dist/retry.d.ts.map +1 -1
  35. package/dist/retry.js.map +1 -1
  36. package/dist/testContainerRuntimeFactory.d.ts +2 -2
  37. package/dist/testContainerRuntimeFactory.d.ts.map +1 -1
  38. package/dist/testContainerRuntimeFactory.js +3 -3
  39. package/dist/testContainerRuntimeFactory.js.map +1 -1
  40. package/dist/testFluidObject.d.ts.map +1 -1
  41. package/dist/testFluidObject.js +7 -3
  42. package/dist/testFluidObject.js.map +1 -1
  43. package/dist/testObjectProvider.d.ts +2 -0
  44. package/dist/testObjectProvider.d.ts.map +1 -1
  45. package/dist/testObjectProvider.js +15 -10
  46. package/dist/testObjectProvider.js.map +1 -1
  47. package/dist/timeoutUtils.d.ts +11 -0
  48. package/dist/timeoutUtils.d.ts.map +1 -1
  49. package/dist/timeoutUtils.js +121 -11
  50. package/dist/timeoutUtils.js.map +1 -1
  51. package/package.json +39 -35
  52. package/prettier.config.cjs +1 -1
  53. package/src/DriverWrappers.ts +40 -37
  54. package/src/TestConfigs.ts +9 -7
  55. package/src/TestSummaryUtils.ts +126 -120
  56. package/src/containerUtils.ts +61 -0
  57. package/src/index.ts +27 -21
  58. package/src/interfaces.ts +10 -7
  59. package/src/loaderContainerTracker.ts +627 -576
  60. package/src/localCodeLoader.ts +85 -77
  61. package/src/localLoader.ts +24 -24
  62. package/src/packageVersion.ts +1 -1
  63. package/src/retry.ts +31 -25
  64. package/src/testContainerRuntimeFactory.ts +59 -56
  65. package/src/testFluidObject.ts +168 -152
  66. package/src/testObjectProvider.ts +433 -383
  67. package/src/timeoutUtils.ts +196 -39
  68. package/tsconfig.json +9 -12
@@ -4,15 +4,23 @@
4
4
  */
5
5
 
6
6
  import { IContainer, IHostLoader, IFluidCodeDetails } from "@fluidframework/container-definitions";
7
- import { ITelemetryGenericEvent, ITelemetryBaseLogger, ITelemetryBaseEvent } from "@fluidframework/common-definitions";
8
7
  import {
9
- ILoaderProps,
10
- Loader,
11
- waitContainerToCatchUp as waitContainerToCatchUp_original,
8
+ ITelemetryGenericEvent,
9
+ ITelemetryBaseLogger,
10
+ ITelemetryBaseEvent,
11
+ } from "@fluidframework/common-definitions";
12
+ import {
13
+ ILoaderProps,
14
+ Loader,
15
+ waitContainerToCatchUp as waitContainerToCatchUp_original,
12
16
  } from "@fluidframework/container-loader";
13
17
  import { IContainerRuntimeOptions } from "@fluidframework/container-runtime";
14
18
  import { IRequestHeader } from "@fluidframework/core-interfaces";
15
- import { IDocumentServiceFactory, IResolvedUrl, IUrlResolver } from "@fluidframework/driver-definitions";
19
+ import {
20
+ IDocumentServiceFactory,
21
+ IResolvedUrl,
22
+ IUrlResolver,
23
+ } from "@fluidframework/driver-definitions";
16
24
  import { ensureFluidResolvedUrl } from "@fluidframework/driver-utils";
17
25
  import { ITestDriver, TestDriverTypes } from "@fluidframework/test-driver-definitions";
18
26
  import { v4 as uuid } from "uuid";
@@ -23,81 +31,90 @@ import { createAndAttachContainer } from "./localLoader";
23
31
  import { ChannelFactoryRegistry } from "./testFluidObject";
24
32
 
25
33
  const defaultCodeDetails: IFluidCodeDetails = {
26
- package: "defaultTestPackage",
27
- config: {},
34
+ package: "defaultTestPackage",
35
+ config: {},
28
36
  };
29
37
 
30
38
  export interface IOpProcessingController {
31
- processIncoming(...containers: IContainer[]): Promise<void>;
32
- processOutgoing(...containers: IContainer[]): Promise<void>;
33
- pauseProcessing(...containers: IContainer[]): Promise<void>;
34
- resumeProcessing(...containers: IContainer[]): void;
39
+ processIncoming(...containers: IContainer[]): Promise<void>;
40
+ processOutgoing(...containers: IContainer[]): Promise<void>;
41
+ pauseProcessing(...containers: IContainer[]): Promise<void>;
42
+ resumeProcessing(...containers: IContainer[]): void;
35
43
  }
36
44
 
37
45
  export interface ITestObjectProvider {
38
- createFluidEntryPoint: (testContainerConfig?: ITestContainerConfig) => fluidEntryPoint;
39
- createLoader(
40
- packageEntries: Iterable<[IFluidCodeDetails, fluidEntryPoint]>,
41
- loaderProps?: Partial<ILoaderProps>,
42
- ): IHostLoader;
43
- createContainer(entryPoint: fluidEntryPoint, loaderProps?: Partial<ILoaderProps>): Promise<IContainer>;
44
- loadContainer(
45
- entryPoint: fluidEntryPoint,
46
- loaderProps?: Partial<ILoaderProps>,
47
- requestHeader?: IRequestHeader,
48
- ): Promise<IContainer>;
49
-
50
- /**
51
- * Used to create a test Container. The Loader/ContainerRuntime/DataRuntime might be different versioned.
52
- * In generateLocalCompatTest(), this Container and its runtime will be arbitrarily-versioned.
53
- */
54
- makeTestLoader(testContainerConfig?: ITestContainerConfig): IHostLoader;
55
- makeTestContainer(testContainerConfig?: ITestContainerConfig): Promise<IContainer>;
56
- loadTestContainer(testContainerConfig?: ITestContainerConfig, requestHeader?: IRequestHeader): Promise<IContainer>;
57
- /**
58
- *
59
- * @param url - Resolved container URL
60
- */
61
- updateDocumentId(url: IResolvedUrl | undefined): void;
62
-
63
- logger: ITelemetryBaseLogger;
64
- documentServiceFactory: IDocumentServiceFactory;
65
- urlResolver: IUrlResolver;
66
- defaultCodeDetails: IFluidCodeDetails;
67
- opProcessingController: IOpProcessingController;
68
-
69
- ensureSynchronized(timeoutDuration?: number): Promise<void>;
70
- reset(): void;
71
-
72
- documentId: string;
73
- driver: ITestDriver;
46
+ createFluidEntryPoint: (testContainerConfig?: ITestContainerConfig) => fluidEntryPoint;
47
+ createLoader(
48
+ packageEntries: Iterable<[IFluidCodeDetails, fluidEntryPoint]>,
49
+ loaderProps?: Partial<ILoaderProps>,
50
+ ): IHostLoader;
51
+ createContainer(
52
+ entryPoint: fluidEntryPoint,
53
+ loaderProps?: Partial<ILoaderProps>,
54
+ ): Promise<IContainer>;
55
+ loadContainer(
56
+ entryPoint: fluidEntryPoint,
57
+ loaderProps?: Partial<ILoaderProps>,
58
+ requestHeader?: IRequestHeader,
59
+ ): Promise<IContainer>;
60
+
61
+ /**
62
+ * Used to create a test Container. The Loader/ContainerRuntime/DataRuntime might be different versioned.
63
+ * In generateLocalCompatTest(), this Container and its runtime will be arbitrarily-versioned.
64
+ */
65
+ makeTestLoader(testContainerConfig?: ITestContainerConfig): IHostLoader;
66
+ makeTestContainer(testContainerConfig?: ITestContainerConfig): Promise<IContainer>;
67
+ loadTestContainer(
68
+ testContainerConfig?: ITestContainerConfig,
69
+ requestHeader?: IRequestHeader,
70
+ ): Promise<IContainer>;
71
+ /**
72
+ *
73
+ * @param url - Resolved container URL
74
+ */
75
+ updateDocumentId(url: IResolvedUrl | undefined): void;
76
+
77
+ logger: ITelemetryBaseLogger;
78
+ documentServiceFactory: IDocumentServiceFactory;
79
+ urlResolver: IUrlResolver;
80
+ defaultCodeDetails: IFluidCodeDetails;
81
+ opProcessingController: IOpProcessingController;
82
+
83
+ ensureSynchronized(timeoutDuration?: number): Promise<void>;
84
+ reset(): void;
85
+
86
+ documentId: string;
87
+ driver: ITestDriver;
74
88
  }
75
89
 
76
90
  export enum DataObjectFactoryType {
77
- Primed, // default
78
- Test,
91
+ Primed, // default
92
+ Test,
79
93
  }
80
94
 
81
95
  export interface ITestContainerConfig {
82
- /** TestFluidDataObject instead of PrimedDataStore */
83
- fluidDataObjectType?: DataObjectFactoryType;
96
+ /** TestFluidDataObject instead of PrimedDataStore */
97
+ fluidDataObjectType?: DataObjectFactoryType;
98
+
99
+ /** An array of channel name and DDS factory pair to create on container creation time */
100
+ registry?: ChannelFactoryRegistry;
84
101
 
85
- /** An array of channel name and DDS factory pair to create on container creation time */
86
- registry?: ChannelFactoryRegistry;
102
+ /** Container runtime options for the container instance */
103
+ runtimeOptions?: IContainerRuntimeOptions;
87
104
 
88
- /** Container runtime options for the container instance */
89
- runtimeOptions?: IContainerRuntimeOptions;
105
+ /** Whether this runtime should be instantiated using a mixed-in attributor class */
106
+ enableAttribution?: boolean;
90
107
 
91
- /** Loader options for the loader used to create containers */
92
- loaderProps?: Partial<ILoaderProps>;
108
+ /** Loader options for the loader used to create containers */
109
+ loaderProps?: Partial<ILoaderProps>;
93
110
  }
94
111
 
95
112
  export const createDocumentId = (): string => uuid();
96
113
 
97
114
  interface IDocumentIdStrategy {
98
- get(): string;
99
- update(resolvedUrl?: IResolvedUrl): void;
100
- reset(): void;
115
+ get(): string;
116
+ update(resolvedUrl?: IResolvedUrl): void;
117
+ reset(): void;
101
118
  }
102
119
 
103
120
  /**
@@ -105,25 +122,29 @@ interface IDocumentIdStrategy {
105
122
  * a new container ID and accessing the container in multi-instance test cases.
106
123
  */
107
124
  function getDocumentIdStrategy(type?: TestDriverTypes): IDocumentIdStrategy {
108
- let documentId = createDocumentId();
109
- switch (type) {
110
- case "odsp":
111
- return {
112
- get: () => documentId,
113
- update: () => { }, // do not update the document ID in odsp test cases
114
- reset: () => { documentId = createDocumentId(); },
115
- };
116
- default:
117
- return {
118
- get: () => documentId,
119
- update: (resolvedUrl?: IResolvedUrl) => {
120
- // Extract the document ID from the resolved container's URL and reset the ID property
121
- ensureFluidResolvedUrl(resolvedUrl);
122
- documentId = resolvedUrl.id ?? documentId;
123
- },
124
- reset: () => { documentId = createDocumentId(); },
125
- };
126
- }
125
+ let documentId = createDocumentId();
126
+ switch (type) {
127
+ case "odsp":
128
+ return {
129
+ get: () => documentId,
130
+ update: () => {}, // do not update the document ID in odsp test cases
131
+ reset: () => {
132
+ documentId = createDocumentId();
133
+ },
134
+ };
135
+ default:
136
+ return {
137
+ get: () => documentId,
138
+ update: (resolvedUrl?: IResolvedUrl) => {
139
+ // Extract the document ID from the resolved container's URL and reset the ID property
140
+ ensureFluidResolvedUrl(resolvedUrl);
141
+ documentId = resolvedUrl.id ?? documentId;
142
+ },
143
+ reset: () => {
144
+ documentId = createDocumentId();
145
+ },
146
+ };
147
+ }
127
148
  }
128
149
 
129
150
  /**
@@ -133,316 +154,345 @@ function getDocumentIdStrategy(type?: TestDriverTypes): IDocumentIdStrategy {
133
154
  * any expected events that have not occurred.
134
155
  */
135
156
  export class EventAndErrorTrackingLogger extends TelemetryLogger {
136
- /** Even if these error events are logged, tests should still be allowed to pass */
137
- private readonly allowedErrors: string[] = [
138
- // This log was removed in current version as unnecessary, but it's still present in previous versions
139
- "fluid:telemetry:Container:NoRealStorageInDetachedContainer",
140
- ];
141
-
142
- constructor(private readonly baseLogger: ITelemetryBaseLogger) {
143
- super();
144
- }
145
-
146
- private readonly expectedEvents: ({ index: number; event: ITelemetryGenericEvent | undefined; } | undefined)[] = [];
147
- private readonly unexpectedErrors: ITelemetryBaseEvent[] = [];
148
-
149
- public registerExpectedEvent(... orderedExpectedEvents: ITelemetryGenericEvent[]) {
150
- if (this.expectedEvents.length !== 0) {
151
- // we don't have to error here. just no reason not to. given the events must be
152
- // ordered it could be tricky to figure out problems around multiple registrations.
153
- throw new Error(
154
- "Expected events already registered.\n"
155
- + "Call reportAndClearTrackedEvents to clear them before registering more");
156
- }
157
- this.expectedEvents.push(... orderedExpectedEvents.map((event, index) => ({ index, event })));
158
- }
159
-
160
- send(event: ITelemetryBaseEvent): void {
161
- const ee = this.expectedEvents[0]?.event;
162
- if (ee?.eventName === event.eventName) {
163
- let matches = true;
164
- for (const key of Object.keys(ee)) {
165
- if (ee[key] !== event[key]) {
166
- matches = false;
167
- break;
168
- }
169
- }
170
- if (matches) {
171
- // we found an expected event
172
- // so remove it from the list of expected events
173
- // and if it is an error, change it to generic
174
- // this helps keep our telemetry clear of
175
- // expected errors.
176
- this.expectedEvents.shift();
177
- if (event.category === "error") {
178
- event.category = "generic";
179
- }
180
- }
181
- }
182
- if (event.category === "error") {
183
- if (this.allowedErrors.includes(event.eventName)) {
184
- event.category = "generic";
185
- } else {
186
- this.unexpectedErrors.push(event);
187
- }
188
- }
189
-
190
- this.baseLogger.send(event);
191
- }
192
-
193
- public reportAndClearTrackedEvents() {
194
- const expectedNotFound = this.expectedEvents.splice(0, this.expectedEvents.length);
195
- const unexpectedErrors = this.unexpectedErrors.splice(0, this.unexpectedErrors.length);
196
- return {
197
- expectedNotFound,
198
- unexpectedErrors,
199
- };
200
- }
157
+ /** Even if these error events are logged, tests should still be allowed to pass */
158
+ private readonly allowedErrors: string[] = [
159
+ // This log was removed in current version as unnecessary, but it's still present in previous versions
160
+ "fluid:telemetry:Container:NoRealStorageInDetachedContainer",
161
+ ];
162
+
163
+ constructor(private readonly baseLogger: ITelemetryBaseLogger) {
164
+ super();
165
+ }
166
+
167
+ private readonly expectedEvents: (
168
+ | { index: number; event: ITelemetryGenericEvent | undefined }
169
+ | undefined
170
+ )[] = [];
171
+ private readonly unexpectedErrors: ITelemetryBaseEvent[] = [];
172
+
173
+ public registerExpectedEvent(...orderedExpectedEvents: ITelemetryGenericEvent[]) {
174
+ if (this.expectedEvents.length !== 0) {
175
+ // we don't have to error here. just no reason not to. given the events must be
176
+ // ordered it could be tricky to figure out problems around multiple registrations.
177
+ throw new Error(
178
+ "Expected events already registered.\n" +
179
+ "Call reportAndClearTrackedEvents to clear them before registering more",
180
+ );
181
+ }
182
+ this.expectedEvents.push(
183
+ ...orderedExpectedEvents.map((event, index) => ({ index, event })),
184
+ );
185
+ }
186
+
187
+ send(event: ITelemetryBaseEvent): void {
188
+ const ee = this.expectedEvents[0]?.event;
189
+ if (ee?.eventName === event.eventName) {
190
+ let matches = true;
191
+ for (const key of Object.keys(ee)) {
192
+ if (ee[key] !== event[key]) {
193
+ matches = false;
194
+ break;
195
+ }
196
+ }
197
+ if (matches) {
198
+ // we found an expected event
199
+ // so remove it from the list of expected events
200
+ // and if it is an error, change it to generic
201
+ // this helps keep our telemetry clear of
202
+ // expected errors.
203
+ this.expectedEvents.shift();
204
+ if (event.category === "error") {
205
+ event.category = "generic";
206
+ }
207
+ }
208
+ }
209
+ if (event.category === "error") {
210
+ if (this.allowedErrors.includes(event.eventName)) {
211
+ event.category = "generic";
212
+ } else {
213
+ this.unexpectedErrors.push(event);
214
+ }
215
+ }
216
+
217
+ this.baseLogger.send(event);
218
+ }
219
+
220
+ public reportAndClearTrackedEvents() {
221
+ const expectedNotFound = this.expectedEvents.splice(0, this.expectedEvents.length);
222
+ const unexpectedErrors = this.unexpectedErrors.splice(0, this.unexpectedErrors.length);
223
+ return {
224
+ expectedNotFound,
225
+ unexpectedErrors,
226
+ };
227
+ }
201
228
  }
202
229
 
203
230
  /**
204
231
  * Shared base class for test object provider. Contain code for loader and container creation and loading
205
232
  */
206
233
  export class TestObjectProvider implements ITestObjectProvider {
207
- private _loaderContainerTracker = new LoaderContainerTracker();
208
- private _documentServiceFactory: IDocumentServiceFactory | undefined;
209
- private _urlResolver: IUrlResolver | undefined;
210
- private _logger: EventAndErrorTrackingLogger | undefined;
211
- private readonly _documentIdStrategy: IDocumentIdStrategy;
212
- // Since documentId doesn't change we can only create/make one container. Call the load functions instead.
213
- private _documentCreated = false;
214
-
215
- /**
216
- * Manage objects for loading and creating container, including the driver, loader, and OpProcessingController
217
- * @param createFluidEntryPoint - callback to create a fluidEntryPoint, with an optional set of channel name
218
- * and factory for TestFluidObject
219
- */
220
- constructor(
221
- public readonly LoaderConstructor: typeof Loader,
222
- public readonly driver: ITestDriver,
223
- public readonly createFluidEntryPoint: (testContainerConfig?: ITestContainerConfig) => fluidEntryPoint,
224
- ) {
225
- this._documentIdStrategy = getDocumentIdStrategy(driver.type);
226
- }
227
-
228
- get logger(): EventAndErrorTrackingLogger {
229
- if (this._logger === undefined) {
230
- this._logger = new EventAndErrorTrackingLogger(
231
- ChildLogger.create(getTestLogger?.(), undefined,
232
- {
233
- all: {
234
- driverType: this.driver.type,
235
- driverEndpointName: this.driver.endpointName,
236
- driverTenantName: this.driver.tenantName,
237
- driverUserIndex: this.driver.userIndex,
238
- },
239
- }));
240
- }
241
- return this._logger;
242
- }
243
-
244
- set logger(logger: EventAndErrorTrackingLogger) {
245
- this._logger = logger;
246
- }
247
-
248
- get documentServiceFactory() {
249
- if (!this._documentServiceFactory) {
250
- this._documentServiceFactory = this.driver.createDocumentServiceFactory();
251
- }
252
- return this._documentServiceFactory;
253
- }
254
-
255
- get urlResolver() {
256
- if (!this._urlResolver) {
257
- this._urlResolver = this.driver.createUrlResolver();
258
- }
259
- return this._urlResolver;
260
- }
261
-
262
- get documentId() {
263
- return this._documentIdStrategy.get();
264
- }
265
-
266
- get defaultCodeDetails() {
267
- return defaultCodeDetails;
268
- }
269
-
270
- get opProcessingController(): IOpProcessingController {
271
- return this._loaderContainerTracker;
272
- }
273
-
274
- /**
275
- * Create a loader. Containers created/loaded through this loader will be added to the OpProcessingController.
276
- *
277
- * Only the version of the loader will vary based on compat config. The version of
278
- * containerRuntime/dataRuntime used in fluidEntryPoint will be used as is from what is passed in.
279
- *
280
- * @param packageEntries - list of code details and fluidEntryPoint pairs.
281
- */
282
- public createLoader(
283
- packageEntries: Iterable<[IFluidCodeDetails, fluidEntryPoint]>,
284
- loaderProps?: Partial<ILoaderProps>,
285
- ) {
286
- const multiSinkLogger = new MultiSinkLogger();
287
- multiSinkLogger.addLogger(this.logger);
288
- if (loaderProps?.logger !== undefined) {
289
- multiSinkLogger.addLogger(loaderProps.logger);
290
- }
291
-
292
- const loader = new this.LoaderConstructor({
293
- ... loaderProps,
294
- logger: multiSinkLogger,
295
- codeLoader: loaderProps?.codeLoader ?? new LocalCodeLoader(packageEntries),
296
- urlResolver: loaderProps?.urlResolver ?? this.urlResolver,
297
- documentServiceFactory: loaderProps?.documentServiceFactory ?? this.documentServiceFactory,
298
- });
299
- this._loaderContainerTracker.add(loader);
300
- return loader;
301
- }
302
-
303
- /**
304
- * Create a container using a default document id and code details.
305
- * Container created is automatically added to the OpProcessingController to manage op flow
306
- *
307
- * Only the version of the loader will vary based on compat config. The version of
308
- * containerRuntime/dataRuntime used in fluidEntryPoint will be used as is from what is passed in.
309
- *
310
- * @param packageEntries - list of code details and fluidEntryPoint pairs.
311
- */
312
- public async createContainer(entryPoint: fluidEntryPoint, loaderProps?: Partial<ILoaderProps>) {
313
- if (this._documentCreated) {
314
- throw new Error(
315
- "Only one container/document can be created. To load the container/document use loadContainer");
316
- }
317
- const loader = this.createLoader([[defaultCodeDetails, entryPoint]], loaderProps);
318
- const container = await createAndAttachContainer(
319
- defaultCodeDetails,
320
- loader,
321
- this.driver.createCreateNewRequest(this.documentId),
322
- );
323
- this._documentCreated = true;
324
- // r11s driver will generate a new ID for the new container.
325
- // update the document ID with the actual ID of the attached container.
326
- this._documentIdStrategy.update(container.resolvedUrl);
327
- return container;
328
- }
329
-
330
- public async loadContainer(
331
- entryPoint: fluidEntryPoint,
332
- loaderProps?: Partial<ILoaderProps>,
333
- requestHeader?: IRequestHeader): Promise<IContainer> {
334
- const loader = this.createLoader([[defaultCodeDetails, entryPoint]], loaderProps);
335
- return loader.resolve({ url: await this.driver.createContainerUrl(this.documentId), headers: requestHeader });
336
- }
337
-
338
- /**
339
- * Make a test loader. Containers created/loaded through this loader will be added to the OpProcessingController.
340
- * The version of the loader/containerRuntime/dataRuntime may vary based on compat config of the current run
341
- * @param testContainerConfig - optional configuring the test Container
342
- */
343
- public makeTestLoader(testContainerConfig?: ITestContainerConfig) {
344
- return this.createLoader(
345
- [[defaultCodeDetails, this.createFluidEntryPoint(testContainerConfig)]],
346
- testContainerConfig?.loaderProps,
347
- );
348
- }
349
-
350
- /**
351
- * Make a container using a default document id and code details
352
- * Container loaded is automatically added to the OpProcessingController to manage op flow
353
- * @param testContainerConfig - optional configuring the test Container
354
- */
355
- public async makeTestContainer(testContainerConfig?: ITestContainerConfig): Promise<IContainer> {
356
- if (this._documentCreated) {
357
- throw new Error(
358
- "Only one container/document can be created. To load the container/document use loadTestContainer");
359
- }
360
- const loader = this.makeTestLoader(testContainerConfig);
361
- const container =
362
- await createAndAttachContainer(
363
- defaultCodeDetails,
364
- loader,
365
- this.driver.createCreateNewRequest(this.documentId));
366
- this._documentCreated = true;
367
- // r11s driver will generate a new ID for the new container.
368
- // update the document ID with the actual ID of the attached container.
369
- this._documentIdStrategy.update(container.resolvedUrl);
370
- return container;
371
- }
372
-
373
- /**
374
- * Load a container using a default document id and code details.
375
- * IContainer loaded is automatically added to the OpProcessingController to manage op flow
376
- * @param testContainerConfig - optional configuring the test Container
377
- * @param requestHeader - optional headers to be supplied to the loader
378
- */
379
- public async loadTestContainer(
380
- testContainerConfig?: ITestContainerConfig,
381
- requestHeader?: IRequestHeader,
382
- ): Promise<IContainer> {
383
- const loader = this.makeTestLoader(testContainerConfig);
384
- const container = await loader.resolve({
385
- url: await this.driver.createContainerUrl(this.documentId),
386
- headers: requestHeader,
387
- });
388
- await this.waitContainerToCatchUp(container);
389
-
390
- return container;
391
- }
392
-
393
- public reset() {
394
- this._loaderContainerTracker.reset();
395
- this._documentServiceFactory = undefined;
396
- this._urlResolver = undefined;
397
- this._documentIdStrategy.reset();
398
- const logError = getUnexpectedLogErrorException(this._logger);
399
- if (logError) {
400
- throw logError;
401
- }
402
- this._logger = undefined;
403
- this._documentCreated = false;
404
- }
405
-
406
- public async ensureSynchronized(timeoutDuration?: number): Promise<void> {
407
- // eslint-disable-next-line @typescript-eslint/strict-boolean-expressions
408
- return !timeoutDuration
409
- ? this._loaderContainerTracker.ensureSynchronized()
410
- : this._loaderContainerTracker.ensureSynchronizedWithTimeout?.(timeoutDuration);
411
- }
412
-
413
- public async waitContainerToCatchUp(container: IContainer) {
414
- // The original waitContainerToCatchUp() from container loader uses either Container.resume()
415
- // or Container.connect() as part of its implementation. However, resume() was deprecated
416
- // and eventually replaced with connect(). To avoid issues during LTS compatibility testing
417
- // with older container versions issues, we use resume() when connect() is unavailable.
418
- if ((container as any).connect === undefined) {
419
- (container as any).connect = (container as any).resume;
420
- }
421
-
422
- return waitContainerToCatchUp_original(container);
423
- }
424
-
425
- updateDocumentId(resolvedUrl: IResolvedUrl | undefined) {
426
- this._documentIdStrategy.update(resolvedUrl);
427
- }
428
-
429
- public resetLoaderContainerTracker(syncSummarizerClients: boolean = false) {
430
- this._loaderContainerTracker.reset();
431
- this._loaderContainerTracker = new LoaderContainerTracker(syncSummarizerClients);
432
- }
234
+ private _loaderContainerTracker = new LoaderContainerTracker();
235
+ private _documentServiceFactory: IDocumentServiceFactory | undefined;
236
+ private _urlResolver: IUrlResolver | undefined;
237
+ private _logger: EventAndErrorTrackingLogger | undefined;
238
+ private readonly _documentIdStrategy: IDocumentIdStrategy;
239
+ // Since documentId doesn't change we can only create/make one container. Call the load functions instead.
240
+ private _documentCreated = false;
241
+
242
+ /**
243
+ * Manage objects for loading and creating container, including the driver, loader, and OpProcessingController
244
+ * @param createFluidEntryPoint - callback to create a fluidEntryPoint, with an optional set of channel name
245
+ * and factory for TestFluidObject
246
+ */
247
+ constructor(
248
+ public readonly LoaderConstructor: typeof Loader,
249
+ public readonly driver: ITestDriver,
250
+ public readonly createFluidEntryPoint: (
251
+ testContainerConfig?: ITestContainerConfig,
252
+ ) => fluidEntryPoint,
253
+ ) {
254
+ this._documentIdStrategy = getDocumentIdStrategy(driver.type);
255
+ }
256
+
257
+ get logger(): EventAndErrorTrackingLogger {
258
+ if (this._logger === undefined) {
259
+ this._logger = new EventAndErrorTrackingLogger(
260
+ ChildLogger.create(getTestLogger?.(), undefined, {
261
+ all: {
262
+ driverType: this.driver.type,
263
+ driverEndpointName: this.driver.endpointName,
264
+ driverTenantName: this.driver.tenantName,
265
+ driverUserIndex: this.driver.userIndex,
266
+ },
267
+ }),
268
+ );
269
+ }
270
+ return this._logger;
271
+ }
272
+
273
+ set logger(logger: EventAndErrorTrackingLogger) {
274
+ this._logger = logger;
275
+ }
276
+
277
+ get documentServiceFactory() {
278
+ if (!this._documentServiceFactory) {
279
+ this._documentServiceFactory = this.driver.createDocumentServiceFactory();
280
+ }
281
+ return this._documentServiceFactory;
282
+ }
283
+
284
+ get urlResolver() {
285
+ if (!this._urlResolver) {
286
+ this._urlResolver = this.driver.createUrlResolver();
287
+ }
288
+ return this._urlResolver;
289
+ }
290
+
291
+ get documentId() {
292
+ return this._documentIdStrategy.get();
293
+ }
294
+
295
+ get defaultCodeDetails() {
296
+ return defaultCodeDetails;
297
+ }
298
+
299
+ get opProcessingController(): IOpProcessingController {
300
+ return this._loaderContainerTracker;
301
+ }
302
+
303
+ /**
304
+ * Create a loader. Containers created/loaded through this loader will be added to the OpProcessingController.
305
+ *
306
+ * Only the version of the loader will vary based on compat config. The version of
307
+ * containerRuntime/dataRuntime used in fluidEntryPoint will be used as is from what is passed in.
308
+ *
309
+ * @param packageEntries - list of code details and fluidEntryPoint pairs.
310
+ */
311
+ public createLoader(
312
+ packageEntries: Iterable<[IFluidCodeDetails, fluidEntryPoint]>,
313
+ loaderProps?: Partial<ILoaderProps>,
314
+ ) {
315
+ const multiSinkLogger = new MultiSinkLogger();
316
+ multiSinkLogger.addLogger(this.logger);
317
+ if (loaderProps?.logger !== undefined) {
318
+ multiSinkLogger.addLogger(loaderProps.logger);
319
+ }
320
+
321
+ const loader = new this.LoaderConstructor({
322
+ ...loaderProps,
323
+ logger: multiSinkLogger,
324
+ codeLoader: loaderProps?.codeLoader ?? new LocalCodeLoader(packageEntries),
325
+ urlResolver: loaderProps?.urlResolver ?? this.urlResolver,
326
+ documentServiceFactory:
327
+ loaderProps?.documentServiceFactory ?? this.documentServiceFactory,
328
+ });
329
+ this._loaderContainerTracker.add(loader);
330
+ return loader;
331
+ }
332
+
333
+ /**
334
+ * Create a container using a default document id and code details.
335
+ * Container created is automatically added to the OpProcessingController to manage op flow
336
+ *
337
+ * Only the version of the loader will vary based on compat config. The version of
338
+ * containerRuntime/dataRuntime used in fluidEntryPoint will be used as is from what is passed in.
339
+ *
340
+ * @param packageEntries - list of code details and fluidEntryPoint pairs.
341
+ */
342
+ public async createContainer(entryPoint: fluidEntryPoint, loaderProps?: Partial<ILoaderProps>) {
343
+ if (this._documentCreated) {
344
+ throw new Error(
345
+ "Only one container/document can be created. To load the container/document use loadContainer",
346
+ );
347
+ }
348
+ const loader = this.createLoader([[defaultCodeDetails, entryPoint]], loaderProps);
349
+ const container = await createAndAttachContainer(
350
+ defaultCodeDetails,
351
+ loader,
352
+ this.driver.createCreateNewRequest(this.documentId),
353
+ );
354
+ this._documentCreated = true;
355
+ // r11s driver will generate a new ID for the new container.
356
+ // update the document ID with the actual ID of the attached container.
357
+ this._documentIdStrategy.update(container.resolvedUrl);
358
+ return container;
359
+ }
360
+
361
+ public async loadContainer(
362
+ entryPoint: fluidEntryPoint,
363
+ loaderProps?: Partial<ILoaderProps>,
364
+ requestHeader?: IRequestHeader,
365
+ ): Promise<IContainer> {
366
+ const loader = this.createLoader([[defaultCodeDetails, entryPoint]], loaderProps);
367
+ return loader.resolve({
368
+ url: await this.driver.createContainerUrl(this.documentId),
369
+ headers: requestHeader,
370
+ });
371
+ }
372
+
373
+ /**
374
+ * Make a test loader. Containers created/loaded through this loader will be added to the OpProcessingController.
375
+ * The version of the loader/containerRuntime/dataRuntime may vary based on compat config of the current run
376
+ * @param testContainerConfig - optional configuring the test Container
377
+ */
378
+ public makeTestLoader(testContainerConfig?: ITestContainerConfig) {
379
+ return this.createLoader(
380
+ [[defaultCodeDetails, this.createFluidEntryPoint(testContainerConfig)]],
381
+ testContainerConfig?.loaderProps,
382
+ );
383
+ }
384
+
385
+ /**
386
+ * Make a container using a default document id and code details
387
+ * Container loaded is automatically added to the OpProcessingController to manage op flow
388
+ * @param testContainerConfig - optional configuring the test Container
389
+ */
390
+ public async makeTestContainer(
391
+ testContainerConfig?: ITestContainerConfig,
392
+ ): Promise<IContainer> {
393
+ if (this._documentCreated) {
394
+ throw new Error(
395
+ "Only one container/document can be created. To load the container/document use loadTestContainer",
396
+ );
397
+ }
398
+ const loader = this.makeTestLoader(testContainerConfig);
399
+ const container = await createAndAttachContainer(
400
+ defaultCodeDetails,
401
+ loader,
402
+ this.driver.createCreateNewRequest(this.documentId),
403
+ );
404
+ this._documentCreated = true;
405
+ // r11s driver will generate a new ID for the new container.
406
+ // update the document ID with the actual ID of the attached container.
407
+ this._documentIdStrategy.update(container.resolvedUrl);
408
+ return container;
409
+ }
410
+
411
+ /**
412
+ * Load a container using a default document id and code details.
413
+ * IContainer loaded is automatically added to the OpProcessingController to manage op flow
414
+ * @param testContainerConfig - optional configuring the test Container
415
+ * @param requestHeader - optional headers to be supplied to the loader
416
+ */
417
+ public async loadTestContainer(
418
+ testContainerConfig?: ITestContainerConfig,
419
+ requestHeader?: IRequestHeader,
420
+ ): Promise<IContainer> {
421
+ const loader = this.makeTestLoader(testContainerConfig);
422
+ const container = await loader.resolve({
423
+ url: await this.driver.createContainerUrl(this.documentId),
424
+ headers: requestHeader,
425
+ });
426
+ await this.waitContainerToCatchUp(container);
427
+
428
+ return container;
429
+ }
430
+
431
+ public reset() {
432
+ this._loaderContainerTracker.reset();
433
+ this._documentServiceFactory = undefined;
434
+ this._urlResolver = undefined;
435
+ this._documentIdStrategy.reset();
436
+ const logError = getUnexpectedLogErrorException(this._logger);
437
+ if (logError) {
438
+ throw logError;
439
+ }
440
+ this._logger = undefined;
441
+ this._documentCreated = false;
442
+ }
443
+
444
+ public async ensureSynchronized(timeoutDuration?: number): Promise<void> {
445
+ return this._loaderContainerTracker.ensureSynchronizedWithTimeout
446
+ ? this._loaderContainerTracker.ensureSynchronizedWithTimeout(timeoutDuration)
447
+ : this._loaderContainerTracker.ensureSynchronized();
448
+ }
449
+
450
+ public async waitContainerToCatchUp(container: IContainer) {
451
+ // The original waitContainerToCatchUp() from container loader uses either Container.resume()
452
+ // or Container.connect() as part of its implementation. However, resume() was deprecated
453
+ // and eventually replaced with connect(). To avoid issues during LTS compatibility testing
454
+ // with older container versions issues, we use resume() when connect() is unavailable.
455
+ if ((container as any).connect === undefined) {
456
+ (container as any).connect = (container as any).resume;
457
+ }
458
+
459
+ return waitContainerToCatchUp_original(container);
460
+ }
461
+
462
+ updateDocumentId(resolvedUrl: IResolvedUrl | undefined) {
463
+ this._documentIdStrategy.update(resolvedUrl);
464
+ }
465
+
466
+ public resetLoaderContainerTracker(syncSummarizerClients: boolean = false) {
467
+ this._loaderContainerTracker.reset();
468
+ this._loaderContainerTracker = new LoaderContainerTracker(syncSummarizerClients);
469
+ }
433
470
  }
434
471
 
435
- export function getUnexpectedLogErrorException(logger: EventAndErrorTrackingLogger | undefined, prefix?: string) {
436
- if (logger === undefined) {
437
- return;
438
- }
439
- const results = logger.reportAndClearTrackedEvents();
440
- if (results.unexpectedErrors.length > 0) {
441
- return new Error(
442
- `${prefix ?? ""}Unexpected Errors in Logs:\n${JSON.stringify(results.unexpectedErrors, undefined, 2)}`);
443
- }
444
- if (results.expectedNotFound.length > 0) {
445
- return new Error(
446
- `${prefix ?? ""}Expected Events not found:\n${JSON.stringify(results.expectedNotFound, undefined, 2)}`);
447
- }
472
+ export function getUnexpectedLogErrorException(
473
+ logger: EventAndErrorTrackingLogger | undefined,
474
+ prefix?: string,
475
+ ) {
476
+ if (logger === undefined) {
477
+ return;
478
+ }
479
+ const results = logger.reportAndClearTrackedEvents();
480
+ if (results.unexpectedErrors.length > 0) {
481
+ return new Error(
482
+ `${prefix ?? ""}Unexpected Errors in Logs:\n${JSON.stringify(
483
+ results.unexpectedErrors,
484
+ undefined,
485
+ 2,
486
+ )}`,
487
+ );
488
+ }
489
+ if (results.expectedNotFound.length > 0) {
490
+ return new Error(
491
+ `${prefix ?? ""}Expected Events not found:\n${JSON.stringify(
492
+ results.expectedNotFound,
493
+ undefined,
494
+ 2,
495
+ )}`,
496
+ );
497
+ }
448
498
  }