@fluidframework/azure-end-to-end-tests 1.1.0-101037
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 +18 -0
- package/LICENSE +21 -0
- package/README.md +8 -0
- package/dist/packageVersion.js +12 -0
- package/dist/packageVersion.js.map +1 -0
- package/dist/test/AzureClientFactory.js +43 -0
- package/dist/test/AzureClientFactory.js.map +1 -0
- package/dist/test/AzureTokenFactory.js +17 -0
- package/dist/test/AzureTokenFactory.js.map +1 -0
- package/dist/test/TestDataObject.js +50 -0
- package/dist/test/TestDataObject.js.map +1 -0
- package/dist/test/audience.spec.js +102 -0
- package/dist/test/audience.spec.js.map +1 -0
- package/dist/test/containerCopy.spec.js +142 -0
- package/dist/test/containerCopy.spec.js.map +1 -0
- package/dist/test/containerCreate.spec.js +112 -0
- package/dist/test/containerCreate.spec.js.map +1 -0
- package/dist/test/ddsTests.spec.js +180 -0
- package/dist/test/ddsTests.spec.js.map +1 -0
- package/dist/test/utils.js +40 -0
- package/dist/test/utils.js.map +1 -0
- package/package.json +97 -0
- package/src/packageVersion.ts +9 -0
- package/src/test/AzureClientFactory.ts +46 -0
- package/src/test/AzureTokenFactory.ts +19 -0
- package/src/test/TestDataObject.ts +68 -0
- package/src/test/audience.spec.ts +138 -0
- package/src/test/containerCopy.spec.ts +184 -0
- package/src/test/containerCreate.spec.ts +152 -0
- package/src/test/ddsTests.spec.ts +246 -0
- package/src/test/tsconfig.json +17 -0
- package/src/test/utils.ts +48 -0
|
@@ -0,0 +1,246 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
import { strict as assert } from "assert";
|
|
6
|
+
import { IFluidHandle } from "@fluidframework/core-interfaces";
|
|
7
|
+
import { ContainerSchema } from "@fluidframework/fluid-static";
|
|
8
|
+
import { SharedMap } from "@fluidframework/map";
|
|
9
|
+
import { timeoutPromise } from "@fluidframework/test-utils";
|
|
10
|
+
import { AzureClient } from "@fluidframework/azure-client";
|
|
11
|
+
import { createAzureClient } from "./AzureClientFactory";
|
|
12
|
+
import { TestDataObject, CounterTestDataObject } from "./TestDataObject";
|
|
13
|
+
import { mapWait } from "./utils";
|
|
14
|
+
|
|
15
|
+
describe("Fluid data updates", () => {
|
|
16
|
+
const connectTimeoutMs = 1000;
|
|
17
|
+
let client: AzureClient;
|
|
18
|
+
let schema: ContainerSchema;
|
|
19
|
+
|
|
20
|
+
beforeEach(() => {
|
|
21
|
+
client = createAzureClient();
|
|
22
|
+
schema = {
|
|
23
|
+
initialObjects: {
|
|
24
|
+
map1: SharedMap,
|
|
25
|
+
},
|
|
26
|
+
};
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Scenario: test when an Azure Client container is created,
|
|
31
|
+
* it can set the initial objects.
|
|
32
|
+
*
|
|
33
|
+
* Expected behavior: an error should not be thrown nor should a rejected promise
|
|
34
|
+
* be returned.
|
|
35
|
+
*/
|
|
36
|
+
it("can set DDSes as initial objects for a container", async () => {
|
|
37
|
+
const { container: newContainer } = await client.createContainer(schema);
|
|
38
|
+
const containerId = await newContainer.attach();
|
|
39
|
+
|
|
40
|
+
await timeoutPromise((resolve) => newContainer.once("connected", () => resolve()), {
|
|
41
|
+
durationMs: connectTimeoutMs,
|
|
42
|
+
errorMsg: "container connect() timeout",
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
const resources = client.getContainer(containerId, schema);
|
|
46
|
+
await assert.doesNotReject(
|
|
47
|
+
resources,
|
|
48
|
+
() => true,
|
|
49
|
+
"container cannot be retrieved from Azure Fluid Relay",
|
|
50
|
+
);
|
|
51
|
+
|
|
52
|
+
const { container } = await resources;
|
|
53
|
+
assert.deepStrictEqual(
|
|
54
|
+
Object.keys(container.initialObjects),
|
|
55
|
+
Object.keys(schema.initialObjects),
|
|
56
|
+
);
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Scenario: test if initialObjects passed into the container functions correctly.
|
|
61
|
+
*
|
|
62
|
+
* Expected behavior: initialObjects value loaded in two different containers should mirror
|
|
63
|
+
* each other after value is changed.
|
|
64
|
+
*/
|
|
65
|
+
it("can change DDSes within initialObjects value", async () => {
|
|
66
|
+
const { container } = await client.createContainer(schema);
|
|
67
|
+
const containerId = await container.attach();
|
|
68
|
+
|
|
69
|
+
await timeoutPromise((resolve) => container.once("connected", () => resolve()), {
|
|
70
|
+
durationMs: connectTimeoutMs,
|
|
71
|
+
errorMsg: "container connect() timeout",
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
const initialObjectsCreate = container.initialObjects;
|
|
75
|
+
const map1Create = initialObjectsCreate.map1 as SharedMap;
|
|
76
|
+
map1Create.set("new-key", "new-value");
|
|
77
|
+
const valueCreate: string | undefined = map1Create.get("new-key");
|
|
78
|
+
|
|
79
|
+
const { container: containerGet } = await client.getContainer(containerId, schema);
|
|
80
|
+
const map1Get = containerGet.initialObjects.map1 as SharedMap;
|
|
81
|
+
const valueGet: string | undefined = await mapWait(map1Get, "new-key");
|
|
82
|
+
assert.strictEqual(valueGet, valueCreate, "container can't change initial objects");
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Scenario: test if we can create DataObjects through initialObjects schema.
|
|
87
|
+
*
|
|
88
|
+
* Expected behavior: DataObjects can be retrieved from the original and loaded container.
|
|
89
|
+
*/
|
|
90
|
+
it("can set DataObjects as initial objects for a container", async () => {
|
|
91
|
+
const doSchema: ContainerSchema = {
|
|
92
|
+
initialObjects: {
|
|
93
|
+
mdo1: TestDataObject,
|
|
94
|
+
mdo2: CounterTestDataObject,
|
|
95
|
+
},
|
|
96
|
+
};
|
|
97
|
+
const { container } = await client.createContainer(doSchema);
|
|
98
|
+
const containerId = await container.attach();
|
|
99
|
+
|
|
100
|
+
await timeoutPromise((resolve) => container.once("connected", () => resolve()), {
|
|
101
|
+
durationMs: connectTimeoutMs,
|
|
102
|
+
errorMsg: "container connect() timeout",
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
const initialObjectsCreate = container.initialObjects;
|
|
106
|
+
assert(
|
|
107
|
+
initialObjectsCreate.mdo1 instanceof TestDataObject,
|
|
108
|
+
"container returns the wrong type for mdo1",
|
|
109
|
+
);
|
|
110
|
+
assert(
|
|
111
|
+
initialObjectsCreate.mdo2 instanceof CounterTestDataObject,
|
|
112
|
+
"container returns the wrong type for mdo2",
|
|
113
|
+
);
|
|
114
|
+
|
|
115
|
+
const { container: containerGet } = await client.getContainer(containerId, doSchema);
|
|
116
|
+
const initialObjectsGet = containerGet.initialObjects;
|
|
117
|
+
assert(
|
|
118
|
+
initialObjectsGet.mdo1 instanceof TestDataObject,
|
|
119
|
+
"container returns the wrong type for mdo1",
|
|
120
|
+
);
|
|
121
|
+
assert(
|
|
122
|
+
initialObjectsCreate.mdo2 instanceof CounterTestDataObject,
|
|
123
|
+
"container returns the wrong type for mdo2",
|
|
124
|
+
);
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* Scenario: test if we can create multiple DataObjects of the same type
|
|
129
|
+
*
|
|
130
|
+
* Expected behavior: DataObjects of the same type can be retrieved from the
|
|
131
|
+
* original and loaded container.
|
|
132
|
+
* TODO: Known bug that needs to be re-tested once fixed.
|
|
133
|
+
*/
|
|
134
|
+
it("can use multiple DataObjects of the same type", async () => {
|
|
135
|
+
const doSchema: ContainerSchema = {
|
|
136
|
+
initialObjects: {
|
|
137
|
+
mdo1: TestDataObject,
|
|
138
|
+
mdo2: CounterTestDataObject,
|
|
139
|
+
mdo3: CounterTestDataObject,
|
|
140
|
+
},
|
|
141
|
+
};
|
|
142
|
+
const { container } = await client.createContainer(doSchema);
|
|
143
|
+
const containerId = await container.attach();
|
|
144
|
+
|
|
145
|
+
await timeoutPromise((resolve) => container.once("connected", () => resolve()), {
|
|
146
|
+
durationMs: connectTimeoutMs,
|
|
147
|
+
errorMsg: "container connect() timeout",
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
const initialObjectsCreate = container.initialObjects;
|
|
151
|
+
assert(
|
|
152
|
+
initialObjectsCreate.mdo1 instanceof TestDataObject,
|
|
153
|
+
"container returns the wrong type for mdo1",
|
|
154
|
+
);
|
|
155
|
+
assert(
|
|
156
|
+
initialObjectsCreate.mdo2 instanceof CounterTestDataObject,
|
|
157
|
+
"container returns the wrong type for mdo2",
|
|
158
|
+
);
|
|
159
|
+
assert(
|
|
160
|
+
initialObjectsCreate.mdo3 instanceof CounterTestDataObject,
|
|
161
|
+
"container returns the wrong type for mdo3",
|
|
162
|
+
);
|
|
163
|
+
|
|
164
|
+
const { container: containerGet } = await client.getContainer(containerId, doSchema);
|
|
165
|
+
const initialObjectsGet = containerGet.initialObjects;
|
|
166
|
+
assert(
|
|
167
|
+
initialObjectsGet.mdo1 instanceof TestDataObject,
|
|
168
|
+
"container returns the wrong type for mdo1",
|
|
169
|
+
);
|
|
170
|
+
assert(
|
|
171
|
+
initialObjectsCreate.mdo2 instanceof CounterTestDataObject,
|
|
172
|
+
"container returns the wrong type for mdo2",
|
|
173
|
+
);
|
|
174
|
+
assert(
|
|
175
|
+
initialObjectsCreate.mdo3 instanceof CounterTestDataObject,
|
|
176
|
+
"container returns the wrong type for mdo3",
|
|
177
|
+
);
|
|
178
|
+
});
|
|
179
|
+
|
|
180
|
+
/**
|
|
181
|
+
* Scenario: test if we can change DataObject value contained within initialObjects
|
|
182
|
+
*
|
|
183
|
+
* Expected behavior: DataObject changes are correctly reflected on original and loaded containers
|
|
184
|
+
*/
|
|
185
|
+
it("can change DataObjects within initialObjects value", async () => {
|
|
186
|
+
const doSchema: ContainerSchema = {
|
|
187
|
+
initialObjects: {
|
|
188
|
+
mdo1: TestDataObject,
|
|
189
|
+
mdo2: CounterTestDataObject,
|
|
190
|
+
},
|
|
191
|
+
};
|
|
192
|
+
const { container } = await client.createContainer(doSchema);
|
|
193
|
+
const initialObjectsCreate = container.initialObjects;
|
|
194
|
+
const mdo2 = initialObjectsCreate.mdo2 as CounterTestDataObject;
|
|
195
|
+
mdo2.increment();
|
|
196
|
+
mdo2.increment();
|
|
197
|
+
mdo2.increment();
|
|
198
|
+
|
|
199
|
+
assert.strictEqual(mdo2.value, 3);
|
|
200
|
+
|
|
201
|
+
const containerId = await container.attach();
|
|
202
|
+
|
|
203
|
+
await timeoutPromise((resolve) => container.once("connected", () => resolve()), {
|
|
204
|
+
durationMs: connectTimeoutMs,
|
|
205
|
+
errorMsg: "container connect() timeout",
|
|
206
|
+
});
|
|
207
|
+
|
|
208
|
+
const { container: containerGet } = await client.getContainer(containerId, doSchema);
|
|
209
|
+
const initialObjectsGet = containerGet.initialObjects;
|
|
210
|
+
const mdo2get = initialObjectsGet.mdo2 as CounterTestDataObject;
|
|
211
|
+
|
|
212
|
+
assert.strictEqual(mdo2get.value, 3);
|
|
213
|
+
|
|
214
|
+
mdo2get.increment();
|
|
215
|
+
mdo2get.increment();
|
|
216
|
+
assert.strictEqual(mdo2get.value, 5);
|
|
217
|
+
});
|
|
218
|
+
|
|
219
|
+
/**
|
|
220
|
+
* Scenario: test if the optional schema parameter, dynamicObjectTypes (custom data objects),
|
|
221
|
+
* can be added during runtime and be returned by the container.
|
|
222
|
+
*
|
|
223
|
+
* Expected behavior: added loadable object can be retrieved from the container. Loadable
|
|
224
|
+
* object's id and container config ID should be identical since it's now attached to
|
|
225
|
+
* the container.
|
|
226
|
+
*/
|
|
227
|
+
it("can create/add loadable objects (custom data object) dynamically during runtime", async () => {
|
|
228
|
+
const dynamicSchema: ContainerSchema = {
|
|
229
|
+
initialObjects: {
|
|
230
|
+
map1: SharedMap,
|
|
231
|
+
},
|
|
232
|
+
dynamicObjectTypes: [TestDataObject],
|
|
233
|
+
};
|
|
234
|
+
|
|
235
|
+
const { container } = await client.createContainer(dynamicSchema);
|
|
236
|
+
|
|
237
|
+
const newDo = await container.create(TestDataObject);
|
|
238
|
+
assert.ok(newDo?.handle);
|
|
239
|
+
|
|
240
|
+
const map1 = container.initialObjects.map1 as SharedMap;
|
|
241
|
+
map1.set("new-pair-id", newDo.handle);
|
|
242
|
+
const handle: IFluidHandle | undefined = await map1.get("new-pair-id");
|
|
243
|
+
const obj: unknown = await handle?.get();
|
|
244
|
+
assert.ok(obj, "container added dynamic objects incorrectly");
|
|
245
|
+
});
|
|
246
|
+
});
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends": "@fluidframework/build-common/ts-common-config.json",
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
"declaration": false,
|
|
5
|
+
"declarationMap": false,
|
|
6
|
+
"rootDir": "../",
|
|
7
|
+
"outDir": "../../dist",
|
|
8
|
+
"types": [
|
|
9
|
+
"mocha",
|
|
10
|
+
"@fluidframework/test-driver-definitions",
|
|
11
|
+
]
|
|
12
|
+
},
|
|
13
|
+
"include": [
|
|
14
|
+
"./**/*",
|
|
15
|
+
"../*"
|
|
16
|
+
]
|
|
17
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
import { IMember } from "fluid-framework";
|
|
6
|
+
|
|
7
|
+
import { AzureMember, IAzureAudience } from "@fluidframework/azure-client";
|
|
8
|
+
import { ISharedMap, IValueChanged } from "@fluidframework/map";
|
|
9
|
+
|
|
10
|
+
export const waitForMember = async (
|
|
11
|
+
audience: IAzureAudience,
|
|
12
|
+
userId: string,
|
|
13
|
+
): Promise<AzureMember> => {
|
|
14
|
+
const allMembers = audience.getMembers();
|
|
15
|
+
const member = allMembers.get(userId);
|
|
16
|
+
if (member !== undefined) {
|
|
17
|
+
return member;
|
|
18
|
+
}
|
|
19
|
+
return new Promise((resolve) => {
|
|
20
|
+
const handler = (clientId: string, newMember: IMember): void => {
|
|
21
|
+
if (newMember.userId === userId) {
|
|
22
|
+
resolve(newMember as AzureMember);
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
audience.on("memberAdded", handler);
|
|
26
|
+
});
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
export const mapWait = async <T>(map: ISharedMap, key: string): Promise<T> => {
|
|
30
|
+
const maybeValue = map.get<T>(key);
|
|
31
|
+
if (maybeValue !== undefined) {
|
|
32
|
+
return maybeValue;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
return new Promise((resolve) => {
|
|
36
|
+
const handler = (changed: IValueChanged): void => {
|
|
37
|
+
if (changed.key === key) {
|
|
38
|
+
map.off("valueChanged", handler);
|
|
39
|
+
const value = map.get<T>(changed.key);
|
|
40
|
+
if (value === undefined) {
|
|
41
|
+
throw new Error("Unexpected valueChanged result");
|
|
42
|
+
}
|
|
43
|
+
resolve(value);
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
map.on("valueChanged", handler);
|
|
47
|
+
});
|
|
48
|
+
};
|