@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.
@@ -0,0 +1,138 @@
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
+
7
+ import { AzureClient } from "@fluidframework/azure-client";
8
+ import { AttachState } from "@fluidframework/container-definitions";
9
+ import { ContainerSchema } from "@fluidframework/fluid-static";
10
+ import { SharedMap } from "@fluidframework/map";
11
+ import { timeoutPromise } from "@fluidframework/test-utils";
12
+
13
+ import { createAzureClient } from "./AzureClientFactory";
14
+ import { waitForMember } from "./utils";
15
+
16
+ describe("Fluid audience", () => {
17
+ const connectTimeoutMs = 1000;
18
+ let client: AzureClient;
19
+ let schema: ContainerSchema;
20
+
21
+ beforeEach(() => {
22
+ client = createAzureClient("test-user-id-1", "test-user-name-1");
23
+ schema = {
24
+ initialObjects: {
25
+ map1: SharedMap,
26
+ },
27
+ };
28
+ });
29
+
30
+ /**
31
+ * Scenario: Find original member/self
32
+ *
33
+ * Expected behavior: container should have a single member upon creation.
34
+ */
35
+ it("can find original member", async () => {
36
+ const { container, services } = await client.createContainer(schema);
37
+ const containerId = await container.attach();
38
+
39
+ await timeoutPromise((resolve) => container.once("connected", () => resolve()), {
40
+ durationMs: connectTimeoutMs,
41
+ errorMsg: "container connect() timeout",
42
+ });
43
+
44
+ assert.strictEqual(typeof containerId, "string", "Attach did not return a string ID");
45
+ assert.strictEqual(
46
+ container.attachState,
47
+ AttachState.Attached,
48
+ "Container is not attached after attach is called",
49
+ );
50
+
51
+ /* This is a workaround for a known bug, we should have one member (self) upon container connection */
52
+ const myself = await waitForMember(services.audience, "test-user-id-1");
53
+ assert.notStrictEqual(myself, undefined, "We should have myself at this point.");
54
+
55
+ const members = services.audience.getMembers();
56
+ assert.strictEqual(members.size, 1, "We should have only one member at this point.");
57
+ });
58
+
59
+ /**
60
+ * Scenario: Find partner member
61
+ *
62
+ * Expected behavior: upon resolving container, the partner member should be able
63
+ * to resolve original member.
64
+ */
65
+ it("can find partner member", async () => {
66
+ const { container, services } = 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
+ assert.strictEqual(typeof containerId, "string", "Attach did not return a string ID");
75
+ assert.strictEqual(
76
+ container.attachState,
77
+ AttachState.Attached,
78
+ "Container is not attached after attach is called",
79
+ );
80
+
81
+ /* This is a workaround for a known bug, we should have one member (self) upon container connection */
82
+ const originalSelf = await waitForMember(services.audience, "test-user-id-1");
83
+ assert.notStrictEqual(originalSelf, undefined, "We should have myself at this point.");
84
+
85
+ const client2 = createAzureClient("test-user-id-2", "test-user-name-2");
86
+ const { services: servicesGet } = await client2.getContainer(containerId, schema);
87
+
88
+ /* This is a workaround for a known bug, we should have one member (self) upon container connection */
89
+ const partner = await waitForMember(servicesGet.audience, "test-user-id-2");
90
+ assert.notStrictEqual(partner, undefined, "We should have partner at this point.");
91
+
92
+ const members = servicesGet.audience.getMembers();
93
+ assert.strictEqual(members.size, 2, "We should have two members at this point.");
94
+
95
+ assert.notStrictEqual(
96
+ partner?.userId,
97
+ originalSelf?.userId,
98
+ "Self and partner should have different IDs",
99
+ );
100
+ });
101
+
102
+ /**
103
+ * Scenario: Partner should be able to observe change in audience
104
+ *
105
+ * Expected behavior: upon 1 partner leaving, other parther should observe
106
+ * memberRemoved event and have correct partner count.
107
+ */
108
+ it("can observe member leaving", async () => {
109
+ const { container } = await client.createContainer(schema);
110
+ const containerId = await container.attach();
111
+
112
+ await timeoutPromise((resolve) => container.once("connected", () => resolve()), {
113
+ durationMs: connectTimeoutMs,
114
+ errorMsg: "container connect() timeout",
115
+ });
116
+
117
+ const client2 = createAzureClient("test-user-id-2", "test-user-name-2");
118
+ const { services: servicesGet } = await client2.getContainer(containerId, schema);
119
+
120
+ /* This is a workaround for a known bug, we should have one member (self) upon container connection */
121
+ const partner = await waitForMember(servicesGet.audience, "test-user-id-2");
122
+ assert.notStrictEqual(partner, undefined, "We should have partner at this point.");
123
+
124
+ let members = servicesGet.audience.getMembers();
125
+ assert.strictEqual(members.size, 2, "We should have two members at this point.");
126
+
127
+ container.disconnect();
128
+
129
+ await new Promise<void>((resolve) => {
130
+ servicesGet.audience.on("memberRemoved", () => {
131
+ resolve();
132
+ });
133
+ });
134
+
135
+ members = servicesGet.audience.getMembers();
136
+ assert.strictEqual(members.size, 1, "We should have one member left at this point.");
137
+ });
138
+ });
@@ -0,0 +1,184 @@
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 { AttachState } from "@fluidframework/container-definitions";
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 { mapWait } from "./utils";
13
+
14
+ describe("Container copy scenarios", () => {
15
+ const connectTimeoutMs = 1000;
16
+ let client: AzureClient;
17
+ let schema: ContainerSchema;
18
+
19
+ beforeEach(() => {
20
+ client = createAzureClient();
21
+ schema = {
22
+ initialObjects: {
23
+ map1: SharedMap,
24
+ },
25
+ };
26
+ });
27
+
28
+ beforeEach(async function () {
29
+ if (process.env.FLUID_CLIENT !== "azure") {
30
+ this.skip();
31
+ }
32
+ });
33
+
34
+ /**
35
+ * Scenario: test if Azure Client can provide versions of the container.
36
+ *
37
+ * Expected behavior: an error should not be thrown nor should a rejected promise
38
+ * be returned. Upon creation, we should recieve back 1 version of the container.
39
+ */
40
+ it("can get versions of current document", async () => {
41
+ const { container } = await client.createContainer(schema);
42
+ const containerId = await container.attach();
43
+
44
+ await timeoutPromise((resolve) => container.once("connected", () => resolve()), {
45
+ durationMs: connectTimeoutMs,
46
+ errorMsg: "container connect() timeout",
47
+ });
48
+ const resources = client.getContainerVersions(containerId);
49
+ await assert.doesNotReject(
50
+ resources,
51
+ () => true,
52
+ "could not get versions of the container",
53
+ );
54
+
55
+ const versions = await resources;
56
+ assert.strictEqual(versions.length, 1, "Container should have exactly one version.");
57
+ });
58
+
59
+ /**
60
+ * Scenario: test if Azure Client can handle bad version ID when versions are requested.
61
+ *
62
+ * Expected behavior: Client should throw an error.
63
+ */
64
+ it("can handle bad versions of current document", async () => {
65
+ const resources = client.getContainerVersions("badid");
66
+ await assert.rejects(
67
+ resources,
68
+ () => true,
69
+ "We should not be able to get container versions.",
70
+ );
71
+ });
72
+
73
+ /**
74
+ * Scenario: test if Azure Client can copy existing container.
75
+ *
76
+ * Expected behavior: an error should not be thrown nor should a rejected promise
77
+ * be returned.
78
+ */
79
+ it("can copy document successfully", async () => {
80
+ const { container } = await client.createContainer(schema);
81
+ const containerId = await container.attach();
82
+
83
+ await timeoutPromise((resolve) => container.once("connected", () => resolve()), {
84
+ durationMs: connectTimeoutMs,
85
+ errorMsg: "container connect() timeout",
86
+ });
87
+ const resources = client.copyContainer(containerId, schema);
88
+ await assert.doesNotReject(resources, () => true, "container could not be copied");
89
+
90
+ const { container: containerCopy } = await resources;
91
+
92
+ const newContainerId = await containerCopy.attach();
93
+ await timeoutPromise((resolve) => containerCopy.once("connected", () => resolve()), {
94
+ durationMs: connectTimeoutMs,
95
+ errorMsg: "container connect() timeout",
96
+ });
97
+
98
+ assert.strictEqual(typeof newContainerId, "string", "Attach did not return a string ID");
99
+ assert.strictEqual(
100
+ containerCopy.attachState,
101
+ AttachState.Attached,
102
+ "Container is not attached after attach is called",
103
+ );
104
+ });
105
+
106
+ /**
107
+ * Scenario: test if Azure Client can copy existing container at specific version.
108
+ *
109
+ * Expected behavior: an error should not be thrown nor should a rejected promise
110
+ * be returned.
111
+ */
112
+ it("can sucesfully copy document from a specific version", async () => {
113
+ const { container } = await client.createContainer(schema);
114
+ const containerId = await container.attach();
115
+
116
+ await timeoutPromise((resolve) => container.once("connected", () => resolve()), {
117
+ durationMs: connectTimeoutMs,
118
+ errorMsg: "container connect() timeout",
119
+ });
120
+
121
+ const versions = await client.getContainerVersions(containerId);
122
+ assert.strictEqual(versions.length, 1, "Container should have exactly one version.");
123
+
124
+ const resources = client.copyContainer(containerId, schema, versions[0]);
125
+ await assert.doesNotReject(resources, () => true, "container could not be copied");
126
+
127
+ const { container: containerCopy } = await resources;
128
+
129
+ const newContainerId = await containerCopy.attach();
130
+ await timeoutPromise((resolve) => containerCopy.once("connected", () => resolve()), {
131
+ durationMs: connectTimeoutMs,
132
+ errorMsg: "container connect() timeout",
133
+ });
134
+
135
+ assert.strictEqual(typeof newContainerId, "string", "Attach did not return a string ID");
136
+ assert.strictEqual(
137
+ containerCopy.attachState,
138
+ AttachState.Attached,
139
+ "Container is not attached after attach is called",
140
+ );
141
+ });
142
+
143
+ /**
144
+ * Scenario: test if Azure Client properly handles DDS objects when
145
+ * copying existing container.
146
+ *
147
+ * Expected behavior: DDS values should match across original and copied
148
+ * container.
149
+ */
150
+ it("correctly copies DDS values when copying container", async () => {
151
+ const { container } = await client.createContainer(schema);
152
+
153
+ const initialObjectsCreate = container.initialObjects;
154
+ const map1Create = initialObjectsCreate.map1 as SharedMap;
155
+ map1Create.set("new-key", "new-value");
156
+ const valueCreate: string | undefined = map1Create.get("new-key");
157
+
158
+ const containerId = await container.attach();
159
+
160
+ await timeoutPromise((resolve) => container.once("connected", () => resolve()), {
161
+ durationMs: connectTimeoutMs,
162
+ errorMsg: "container connect() timeout",
163
+ });
164
+
165
+ const resources = client.copyContainer(containerId, schema);
166
+ await assert.doesNotReject(resources, () => true, "container could not be copied");
167
+
168
+ const { container: containerCopy } = await resources;
169
+
170
+ const map1Get = containerCopy.initialObjects.map1 as SharedMap;
171
+ const valueGet: string | undefined = await mapWait(map1Get, "new-key");
172
+ assert.strictEqual(valueGet, valueCreate, "DDS value was not correctly copied.");
173
+ });
174
+
175
+ /**
176
+ * Scenario: test if Azure Client can handle non-existing container when trying to copy
177
+ *
178
+ * Expected behavior: client should throw an error.
179
+ */
180
+ it("can handle non-existing container", async () => {
181
+ const resources = client.copyContainer("badidoncopy", schema);
182
+ await assert.rejects(resources, () => true, "We should not be able to copy container.");
183
+ });
184
+ });
@@ -0,0 +1,152 @@
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 { AttachState } from "@fluidframework/container-definitions";
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
+
13
+ describe("Container create scenarios", () => {
14
+ const connectTimeoutMs = 1000;
15
+ let client: AzureClient;
16
+ let schema: ContainerSchema;
17
+
18
+ beforeEach(() => {
19
+ client = createAzureClient();
20
+ schema = {
21
+ initialObjects: {
22
+ map1: SharedMap,
23
+ },
24
+ };
25
+ });
26
+
27
+ /**
28
+ * Scenario: test when Azure Client is instantiated correctly, it can create
29
+ * a container successfully.
30
+ *
31
+ * Expected behavior: an error should not be thrown nor should a rejected promise
32
+ * be returned.
33
+ */
34
+ it("can create new Azure Fluid Relay container successfully", async () => {
35
+ const resourcesP = client.createContainer(schema);
36
+
37
+ await assert.doesNotReject(
38
+ resourcesP,
39
+ () => true,
40
+ "container cannot be created in Azure Fluid Relay",
41
+ );
42
+ });
43
+
44
+ /**
45
+ * Scenario: test when an Azure Client container is created,
46
+ * it is initially detached.
47
+ *
48
+ * Expected behavior: an error should not be thrown nor should a rejected promise
49
+ * be returned.
50
+ */
51
+ it("Created container is detached", async () => {
52
+ const { container } = await client.createContainer(schema);
53
+ assert.strictEqual(
54
+ container.attachState,
55
+ AttachState.Detached,
56
+ "Container should be detached",
57
+ );
58
+ });
59
+
60
+ /**
61
+ * Scenario: Test attaching a container.
62
+ *
63
+ * Expected behavior: an error should not be thrown nor should a rejected promise
64
+ * be returned.
65
+ */
66
+ it("can attach a container", async () => {
67
+ const { container } = await client.createContainer(schema);
68
+ const containerId = await container.attach();
69
+
70
+ await timeoutPromise((resolve) => container.once("connected", () => resolve()), {
71
+ durationMs: connectTimeoutMs,
72
+ errorMsg: "container connect() timeout",
73
+ });
74
+
75
+ assert.strictEqual(typeof containerId, "string", "Attach did not return a string ID");
76
+ assert.strictEqual(
77
+ container.attachState,
78
+ AttachState.Attached,
79
+ "Container is not attached after attach is called",
80
+ );
81
+ });
82
+
83
+ /**
84
+ * Scenario: Test if attaching a container twice fails.
85
+ *
86
+ * Expected behavior: an error should not be thrown nor should a rejected promise
87
+ * be returned.
88
+ */
89
+ it("cannot attach a container twice", async () => {
90
+ const { container } = await client.createContainer(schema);
91
+ const containerId = await container.attach();
92
+
93
+ await timeoutPromise((resolve) => container.once("connected", () => resolve()), {
94
+ durationMs: connectTimeoutMs,
95
+ errorMsg: "container connect() timeout",
96
+ });
97
+
98
+ assert.strictEqual(typeof containerId, "string", "Attach did not return a string ID");
99
+ assert.strictEqual(
100
+ container.attachState,
101
+ AttachState.Attached,
102
+ "Container is attached after attach is called",
103
+ );
104
+ await assert.rejects(container.attach(), () => true, "Container should not attach twice");
105
+ });
106
+
107
+ /**
108
+ * Scenario: test if Azure Client can get an existing container.
109
+ *
110
+ * Expected behavior: an error should not be thrown nor should a rejected promise
111
+ * be returned.
112
+ */
113
+ it("can retrieve existing Azure Fluid Relay container successfully", async () => {
114
+ const { container: newContainer } = await client.createContainer(schema);
115
+ const containerId = await newContainer.attach();
116
+
117
+ await timeoutPromise((resolve) => newContainer.once("connected", () => resolve()), {
118
+ durationMs: connectTimeoutMs,
119
+ errorMsg: "container connect() timeout",
120
+ });
121
+
122
+ const resources = client.getContainer(containerId, schema);
123
+ await assert.doesNotReject(
124
+ resources,
125
+ () => true,
126
+ "container cannot be retrieved from Azure Fluid Relay",
127
+ );
128
+ });
129
+
130
+ /**
131
+ * Scenario: test if Azure Client can get a non-exiting container.
132
+ *
133
+ * Expected behavior: an error should be thrown when trying to get a non-existent container.
134
+ */
135
+ it("cannot load improperly created container (cannot load a non-existent container)", async () => {
136
+ const consoleErrorFn = console.error;
137
+ console.error = (): void => {};
138
+ const containerAndServicesP = client.getContainer("containerConfig", schema);
139
+
140
+ const errorFn = (error: Error): boolean => {
141
+ assert.notStrictEqual(error.message, undefined, "Azure Client error is undefined");
142
+ return true;
143
+ };
144
+
145
+ await assert.rejects(
146
+ containerAndServicesP,
147
+ errorFn,
148
+ "Azure Client can load a non-existent container",
149
+ );
150
+ console.error = consoleErrorFn;
151
+ });
152
+ });