5
5
6
6
import { strict as assert } from "node:assert" ;
7
7
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" ;
15
9
16
10
import { CellFactory } from "../cellFactory.js" ;
17
11
import type { ISharedCell } from "../interfaces.js" ;
18
12
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 ( ) ;
65
14
66
15
describe ( "Cell with rollback" , ( ) => {
67
16
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
+ ) ;
69
21
70
22
const events : ( string | undefined ) [ ] = [ ] ;
71
23
@@ -82,7 +34,14 @@ describe("Cell with rollback", () => {
82
34
} ) ;
83
35
84
36
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
+ ) ;
86
45
87
46
const events : ( string | undefined ) [ ] = [ ] ;
88
47
@@ -109,11 +68,18 @@ describe("SharedCell rollback events with multiple clients", () => {
109
68
it ( "should emit valueChanged on set and rollback should re-emit previous value across clients" , async ( ) => {
110
69
// Setup two clients
111
70
const {
112
- cell : cell1 ,
71
+ dds : cell1 ,
113
72
containerRuntimeFactory,
114
73
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
+ ) ;
117
83
118
84
const events1 : string [ ] = [ ] ;
119
85
const events2 : string [ ] = [ ] ;
@@ -150,11 +116,18 @@ describe("SharedCell rollback events with multiple clients", () => {
150
116
it ( "should emit delete on delete, and rollback should re-emit last valueChanged across clients" , async ( ) => {
151
117
// Setup two clients
152
118
const {
153
- cell : cell1 ,
119
+ dds : cell1 ,
154
120
containerRuntimeFactory,
155
121
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
+ ) ;
158
131
159
132
const events1 : string [ ] = [ ] ;
160
133
const events2 : string [ ] = [ ] ;
0 commit comments