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