@@ -24,7 +24,7 @@ test('stores documents without conflicts', async t => {
24
24
new Redis ( {
25
25
...redisConnectionSettings ,
26
26
identifier : `server${ uuidv4 ( ) } ` ,
27
- prefix : 'extension-redis/onStoreDocument ' ,
27
+ prefix : 'extension-redis/onStoreDocument1 ' ,
28
28
} ) ,
29
29
new CustomStorageExtension ( ) ,
30
30
] ,
@@ -36,7 +36,7 @@ test('stores documents without conflicts', async t => {
36
36
new Redis ( {
37
37
...redisConnectionSettings ,
38
38
identifier : `anotherServer${ uuidv4 ( ) } ` ,
39
- prefix : 'extension-redis/onStoreDocument ' ,
39
+ prefix : 'extension-redis/onStoreDocument1 ' ,
40
40
} ) ,
41
41
new CustomStorageExtension ( ) ,
42
42
] ,
@@ -63,7 +63,7 @@ test('stores documents when the last client disconnects', async t => {
63
63
const server = await newHocuspocus ( {
64
64
extensions : [
65
65
new Redis ( {
66
- prefix : 'extension-redis/onStoreDocument ' ,
66
+ prefix : 'extension-redis/onStoreDocument2 ' ,
67
67
...redisConnectionSettings ,
68
68
} ) ,
69
69
] ,
@@ -85,3 +85,69 @@ test('stores documents when the last client disconnects', async t => {
85
85
} )
86
86
} )
87
87
} )
88
+
89
+ test ( 'document gets unloaded on both servers after disconnection' , async t => {
90
+ await new Promise ( async resolve => {
91
+ class CustomStorageExtension {
92
+ priority = 10
93
+
94
+ onStoreDocument ( { document } : onStoreDocumentPayload ) {
95
+ console . log ( 'storing' )
96
+ return new Promise ( resolve2 => {
97
+ setTimeout ( ( ) => {
98
+ console . log ( 'stored' )
99
+
100
+ resolve2 ( '' )
101
+ } , 3000 )
102
+ } )
103
+ }
104
+ }
105
+
106
+ const server = await newHocuspocus ( {
107
+ name : 'redis-1' ,
108
+ extensions : [
109
+ new Redis ( {
110
+ ...redisConnectionSettings ,
111
+ prefix : 'extension-redis/onStoreDocument3' ,
112
+ } ) ,
113
+ new CustomStorageExtension ( ) ,
114
+ ] ,
115
+ } )
116
+
117
+ const anotherServer = await newHocuspocus ( {
118
+ name : 'redis-2' ,
119
+ extensions : [
120
+ new Redis ( {
121
+ ...redisConnectionSettings ,
122
+ prefix : 'extension-redis/onStoreDocument3' ,
123
+ } ) ,
124
+ new CustomStorageExtension ( ) ,
125
+ ] ,
126
+ } )
127
+
128
+ const provider = newHocuspocusProvider ( server )
129
+
130
+ const anotherProvider = newHocuspocusProvider ( anotherServer , {
131
+ onSynced ( ) {
132
+ // once we're setup make an edit on anotherProvider, if all succeeds the onStoreDocument
133
+ // callback will be called after the debounce period and all docs will
134
+ // be identical
135
+ anotherProvider . document . getArray ( 'foo' ) . insert ( 0 , [ 'bar' ] )
136
+ provider . document . getArray ( 'foo2' ) . insert ( 0 , [ 'bar' ] )
137
+
138
+ setTimeout ( ( ) => {
139
+ provider . configuration . websocketProvider . disconnect ( )
140
+ anotherProvider . configuration . websocketProvider . disconnect ( )
141
+
142
+ setTimeout ( ( ) => {
143
+ t . is ( anotherServer . documents . size , 0 )
144
+ t . is ( server . documents . size , 0 )
145
+
146
+ resolve ( '' )
147
+ } , 5000 ) // must be higher than RedisExtension.disconnectDelay
148
+ } , 1500 )
149
+
150
+ } ,
151
+ } )
152
+ } )
153
+ } )
0 commit comments