Skip to content

Commit 30df064

Browse files
use helper
1 parent e0fd9f0 commit 30df064

File tree

3 files changed

+206
-572
lines changed

3 files changed

+206
-572
lines changed

packages/dds/cell/src/test/cell.rollback.spec.ts

Lines changed: 34 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -5,67 +5,19 @@
55

66
import { strict as assert } from "node:assert";
77

8-
import { AttachState } from "@fluidframework/container-definitions";
9-
import {
10-
MockContainerRuntimeFactory,
11-
MockFluidDataStoreRuntime,
12-
MockStorage,
13-
type MockContainerRuntime,
14-
} from "@fluidframework/test-runtime-utils/internal";
8+
import { setupRollbackTest, createAdditionalClient } from "@fluid-private/test-dds-utils";
159

1610
import { CellFactory } from "../cellFactory.js";
1711
import type { ISharedCell } from "../interfaces.js";
1812

19-
interface RollbackTestSetup {
20-
cell: ISharedCell;
21-
dataStoreRuntime: MockFluidDataStoreRuntime;
22-
containerRuntimeFactory: MockContainerRuntimeFactory;
23-
containerRuntime: MockContainerRuntime;
24-
}
25-
26-
const mapFactory = new CellFactory();
27-
28-
function setupRollbackTest(id: string): RollbackTestSetup {
29-
const containerRuntimeFactory = new MockContainerRuntimeFactory({ flushMode: 1 });
30-
const dataStoreRuntime = new MockFluidDataStoreRuntime({ clientId: "1" });
31-
const containerRuntime = containerRuntimeFactory.createContainerRuntime(dataStoreRuntime);
32-
const cell = mapFactory.create(dataStoreRuntime, id);
33-
dataStoreRuntime.setAttachState(AttachState.Attached);
34-
cell.connect({
35-
deltaConnection: dataStoreRuntime.createDeltaConnection(),
36-
objectStorage: new MockStorage(),
37-
});
38-
return {
39-
cell,
40-
dataStoreRuntime,
41-
containerRuntimeFactory,
42-
containerRuntime,
43-
};
44-
}
45-
46-
// Helper to create another client attached to the same containerRuntimeFactory
47-
function createAdditionalClient(
48-
containerRuntimeFactory: MockContainerRuntimeFactory,
49-
id: string = "client-2",
50-
): {
51-
cell: ISharedCell;
52-
dataStoreRuntime: MockFluidDataStoreRuntime;
53-
containerRuntime: MockContainerRuntime;
54-
} {
55-
const dataStoreRuntime = new MockFluidDataStoreRuntime({ clientId: id });
56-
const containerRuntime = containerRuntimeFactory.createContainerRuntime(dataStoreRuntime);
57-
const cell = mapFactory.create(dataStoreRuntime, `cell-${id}`);
58-
dataStoreRuntime.setAttachState(AttachState.Attached);
59-
cell.connect({
60-
deltaConnection: dataStoreRuntime.createDeltaConnection(),
61-
objectStorage: new MockStorage(),
62-
});
63-
return { cell, dataStoreRuntime, containerRuntime };
64-
}
13+
const cellFactory = new CellFactory();
6514

6615
describe("Cell with rollback", () => {
6716
it("should emit valueChanged on set and rollback should re-emit previous value", async () => {
68-
const { cell, containerRuntime } = setupRollbackTest("client-1");
17+
const { dds: cell, containerRuntime } = setupRollbackTest<ISharedCell>(
18+
"cell-1",
19+
(rt, id): ISharedCell => cellFactory.create(rt, id),
20+
);
6921

7022
const events: (string | undefined)[] = [];
7123

@@ -82,7 +34,14 @@ describe("Cell with rollback", () => {
8234
});
8335

8436
it("should emit delete on delete, and rollback should re-emit last valueChanged", async () => {
85-
const { cell, containerRuntimeFactory, containerRuntime } = setupRollbackTest("client-1");
37+
const {
38+
dds: cell,
39+
containerRuntimeFactory,
40+
containerRuntime,
41+
} = setupRollbackTest<ISharedCell>(
42+
"cell-1",
43+
(rt, id): ISharedCell => cellFactory.create(rt, id),
44+
);
8645

8746
const events: (string | undefined)[] = [];
8847

@@ -109,11 +68,18 @@ describe("SharedCell rollback events with multiple clients", () => {
10968
it("should emit valueChanged on set and rollback should re-emit previous value across clients", async () => {
11069
// Setup two clients
11170
const {
112-
cell: cell1,
71+
dds: cell1,
11372
containerRuntimeFactory,
11473
containerRuntime: runtime1,
115-
} = setupRollbackTest("client-1");
116-
const { cell: cell2 } = createAdditionalClient(containerRuntimeFactory);
74+
} = setupRollbackTest<ISharedCell>(
75+
"client-1",
76+
(rt, id): ISharedCell => cellFactory.create(rt, id),
77+
);
78+
const { dds: cell2 } = createAdditionalClient(
79+
containerRuntimeFactory,
80+
"client-2",
81+
(rt, id): ISharedCell => cellFactory.create(rt, `cell-${id}`),
82+
);
11783

11884
const events1: string[] = [];
11985
const events2: string[] = [];
@@ -150,11 +116,18 @@ describe("SharedCell rollback events with multiple clients", () => {
150116
it("should emit delete on delete, and rollback should re-emit last valueChanged across clients", async () => {
151117
// Setup two clients
152118
const {
153-
cell: cell1,
119+
dds: cell1,
154120
containerRuntimeFactory,
155121
containerRuntime: runtime1,
156-
} = setupRollbackTest("client-1");
157-
const { cell: cell2 } = createAdditionalClient(containerRuntimeFactory);
122+
} = setupRollbackTest<ISharedCell>(
123+
"client-1",
124+
(rt, id): ISharedCell => cellFactory.create(rt, id),
125+
);
126+
const { dds: cell2 } = createAdditionalClient(
127+
containerRuntimeFactory,
128+
"client-2",
129+
(rt, id): ISharedCell => cellFactory.create(rt, `cell-${id}`),
130+
);
158131

159132
const events1: string[] = [];
160133
const events2: string[] = [];

0 commit comments

Comments
 (0)