@fluidframework/test-utils 2.0.0-internal.3.0.0 → 2.0.0-internal.3.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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
package/src/testFluidObject.ts
CHANGED
|
@@ -5,19 +5,23 @@
|
|
|
5
5
|
|
|
6
6
|
import { defaultFluidObjectRequestHandler } from "@fluidframework/aqueduct";
|
|
7
7
|
import {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
8
|
+
IRequest,
|
|
9
|
+
IResponse,
|
|
10
|
+
IFluidHandle,
|
|
11
|
+
IFluidRouter,
|
|
12
|
+
FluidObject,
|
|
13
|
+
IProvideFluidRouter,
|
|
14
14
|
} from "@fluidframework/core-interfaces";
|
|
15
|
-
import {
|
|
15
|
+
import {
|
|
16
|
+
FluidObjectHandle,
|
|
17
|
+
FluidDataStoreRuntime,
|
|
18
|
+
mixinRequestHandler,
|
|
19
|
+
} from "@fluidframework/datastore";
|
|
16
20
|
import { SharedMap, ISharedMap } from "@fluidframework/map";
|
|
17
21
|
import {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
22
|
+
IFluidDataStoreContext,
|
|
23
|
+
IFluidDataStoreFactory,
|
|
24
|
+
IFluidDataStoreChannel,
|
|
21
25
|
} from "@fluidframework/runtime-definitions";
|
|
22
26
|
import { IFluidDataStoreRuntime, IChannelFactory } from "@fluidframework/datastore-definitions";
|
|
23
27
|
import { assert } from "@fluidframework/common-utils";
|
|
@@ -29,89 +33,91 @@ import { ITestFluidObject } from "./interfaces";
|
|
|
29
33
|
* It exposes the IFluidDataStoreContext and IFluidDataStoreRuntime.
|
|
30
34
|
*/
|
|
31
35
|
export class TestFluidObject implements ITestFluidObject, IFluidRouter {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
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
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
36
|
+
public static async load(
|
|
37
|
+
runtime: IFluidDataStoreRuntime,
|
|
38
|
+
channel: IFluidDataStoreChannel,
|
|
39
|
+
context: IFluidDataStoreContext,
|
|
40
|
+
factoryEntries: Map<string, IChannelFactory>,
|
|
41
|
+
existing: boolean,
|
|
42
|
+
) {
|
|
43
|
+
const fluidObject = new TestFluidObject(runtime, channel, context, factoryEntries);
|
|
44
|
+
await fluidObject.initialize(existing);
|
|
45
|
+
|
|
46
|
+
return fluidObject;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
public get ITestFluidObject() {
|
|
50
|
+
return this;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
public get IFluidLoadable() {
|
|
54
|
+
return this;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
public get IFluidRouter() {
|
|
58
|
+
return this;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
public get handle(): IFluidHandle<this> {
|
|
62
|
+
return this.innerHandle;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
public root!: ISharedMap;
|
|
66
|
+
private readonly innerHandle: IFluidHandle<this>;
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Creates a new TestFluidObject.
|
|
70
|
+
* @param runtime - The data store runtime.
|
|
71
|
+
* @param context - The data store context.
|
|
72
|
+
* @param factoryEntries - A list of id to IChannelFactory mapping. For each item in the list,
|
|
73
|
+
* a shared object is created which can be retrieved by calling getSharedObject() with the id;
|
|
74
|
+
*/
|
|
75
|
+
constructor(
|
|
76
|
+
public readonly runtime: IFluidDataStoreRuntime,
|
|
77
|
+
public readonly channel: IFluidDataStoreChannel,
|
|
78
|
+
public readonly context: IFluidDataStoreContext,
|
|
79
|
+
private readonly factoryEntriesMap: Map<string, IChannelFactory>,
|
|
80
|
+
) {
|
|
81
|
+
this.innerHandle = new FluidObjectHandle(this, "", runtime.objectsRoutingContext);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Retrieves a shared object with the given id.
|
|
86
|
+
* @param id - The id of the shared object to retrieve.
|
|
87
|
+
*/
|
|
88
|
+
public async getSharedObject<T = any>(id: string): Promise<T> {
|
|
89
|
+
if (this.factoryEntriesMap === undefined) {
|
|
90
|
+
throw new Error("Shared objects were not provided during creation.");
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
for (const key of this.factoryEntriesMap.keys()) {
|
|
94
|
+
if (key === id) {
|
|
95
|
+
const handle = this.root.get<IFluidHandle>(id);
|
|
96
|
+
return handle?.get() as unknown as T;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
throw new Error(`Shared object with id ${id} not found.`);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
public async request(request: IRequest): Promise<IResponse> {
|
|
104
|
+
return defaultFluidObjectRequestHandler(this, request);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
private async initialize(existing: boolean) {
|
|
108
|
+
if (!existing) {
|
|
109
|
+
this.root = SharedMap.create(this.runtime, "root");
|
|
110
|
+
|
|
111
|
+
this.factoryEntriesMap.forEach((sharedObjectFactory: IChannelFactory, key: string) => {
|
|
112
|
+
const sharedObject = this.runtime.createChannel(key, sharedObjectFactory.type);
|
|
113
|
+
this.root.set(key, sharedObject.handle);
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
this.root.bindToContext();
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
this.root = (await this.runtime.getChannel("root")) as ISharedMap;
|
|
120
|
+
}
|
|
115
121
|
}
|
|
116
122
|
|
|
117
123
|
export type ChannelFactoryRegistry = Iterable<[string | undefined, IChannelFactory]>;
|
|
@@ -141,63 +147,73 @@ export type ChannelFactoryRegistry = Iterable<[string | undefined, IChannelFacto
|
|
|
141
147
|
* ```
|
|
142
148
|
*/
|
|
143
149
|
export class TestFluidObjectFactory implements IFluidDataStoreFactory {
|
|
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
|
-
|
|
150
|
+
public get IFluidDataStoreFactory() {
|
|
151
|
+
return this;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* Creates a new TestFluidObjectFactory.
|
|
156
|
+
* @param factoryEntries - A list of id to IChannelFactory mapping. It creates a data store runtime with each
|
|
157
|
+
* IChannelFactory. Entries with string ids are passed to the Fluid object so that it can create a shared object
|
|
158
|
+
* for it.
|
|
159
|
+
*/
|
|
160
|
+
constructor(
|
|
161
|
+
private readonly factoryEntries: ChannelFactoryRegistry,
|
|
162
|
+
public readonly type = "TestFluidObjectFactory",
|
|
163
|
+
) {}
|
|
164
|
+
|
|
165
|
+
public async instantiateDataStore(
|
|
166
|
+
context: IFluidDataStoreContext,
|
|
167
|
+
existing: boolean,
|
|
168
|
+
): Promise<FluidDataStoreRuntime> {
|
|
169
|
+
const dataTypes = new Map<string, IChannelFactory>();
|
|
170
|
+
|
|
171
|
+
// Add SharedMap's factory which will be used to create the root map.
|
|
172
|
+
const sharedMapFactory = SharedMap.getFactory();
|
|
173
|
+
dataTypes.set(sharedMapFactory.type, sharedMapFactory);
|
|
174
|
+
|
|
175
|
+
// Add the object factories to the list to be sent to data store runtime.
|
|
176
|
+
for (const entry of this.factoryEntries) {
|
|
177
|
+
const factory = entry[1];
|
|
178
|
+
dataTypes.set(factory.type, factory);
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
// Create a map from the factory entries with entries that don't have the id as undefined. This will be
|
|
182
|
+
// passed to the Fluid object.
|
|
183
|
+
const factoryEntriesMapForObject = new Map<string, IChannelFactory>();
|
|
184
|
+
for (const entry of this.factoryEntries) {
|
|
185
|
+
const id = entry[0];
|
|
186
|
+
if (id !== undefined) {
|
|
187
|
+
factoryEntriesMapForObject.set(id, entry[1]);
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
const runtimeClass = mixinRequestHandler(
|
|
192
|
+
async (request: IRequest, rt: FluidDataStoreRuntime) => {
|
|
193
|
+
const maybeRouter: FluidObject<IProvideFluidRouter> | undefined =
|
|
194
|
+
await rt.entryPoint?.get();
|
|
195
|
+
assert(
|
|
196
|
+
maybeRouter?.IFluidRouter !== undefined,
|
|
197
|
+
"entryPoint should have been initialized by now",
|
|
198
|
+
);
|
|
199
|
+
return maybeRouter.IFluidRouter.request(request);
|
|
200
|
+
},
|
|
201
|
+
);
|
|
202
|
+
|
|
203
|
+
return new runtimeClass(
|
|
204
|
+
context,
|
|
205
|
+
dataTypes,
|
|
206
|
+
existing,
|
|
207
|
+
async (dataStoreRuntime: IFluidDataStoreRuntime) =>
|
|
208
|
+
TestFluidObject.load(
|
|
209
|
+
dataStoreRuntime,
|
|
210
|
+
// This works because 'runtime' is an instance of runtimeClass (which is a FluidDataStoreRuntime and
|
|
211
|
+
// thus implements IFluidDataStoreChannel) which passes itself as the parameter to this function.
|
|
212
|
+
dataStoreRuntime as FluidDataStoreRuntime,
|
|
213
|
+
context,
|
|
214
|
+
factoryEntriesMapForObject,
|
|
215
|
+
existing,
|
|
216
|
+
),
|
|
217
|
+
);
|
|
218
|
+
}
|
|
203
219
|
}
|