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