@@ -25,7 +25,26 @@ describe('Sync', () => {
2525 describe ( 'json' , ( ) => defineSyncTests ( false ) ) ;
2626 describe ( 'bson' , ( ) => defineSyncTests ( true ) ) ;
2727
28- mockSyncServiceTest . skip ( 'can migrate between sync implementations' , async ( { syncService } ) => {
28+ mockSyncServiceTest ( 'can migrate between sync implementations' , async ( { syncService } ) => {
29+ let database = await syncService . createDatabase ( ) ;
30+ // Create a bucket with a broken oplog key format.
31+ const { id : bucketId } = await database . writeLock ( async ( adapter ) => {
32+ return await adapter . get < { id : number } > ( 'INSERT INTO ps_buckets(name) VALUES (?) RETURNING id' , [ 'a' ] ) ;
33+ } ) ;
34+ await database . execute (
35+ 'INSERT INTO ps_oplog(bucket, op_id, key, row_type, row_id, data, hash) VALUES (?, ?, ?, ?, ?, ?, ?)' ,
36+ [
37+ bucketId ,
38+ '1' ,
39+ // The JavaScript client used to subkeys to JSON when it shouldn't...
40+ 'lists/1/"subkey_1"' ,
41+ 'lists' ,
42+ '1' ,
43+ '{}' ,
44+ 0
45+ ]
46+ ) ;
47+
2948 function addData ( id : string ) {
3049 syncService . pushLine ( {
3150 data : {
@@ -51,27 +70,8 @@ describe('Sync', () => {
5170 }
5271 } ;
5372
54- let database = await syncService . createDatabase ( ) ;
73+ // Connecting with the new client should fix the format.
5574 database . connect ( new TestConnector ( ) , {
56- clientImplementation : SyncClientImplementation . JAVASCRIPT ,
57- connectionMethod : SyncStreamConnectionMethod . HTTP
58- } ) ;
59- await vi . waitFor ( ( ) => expect ( syncService . connectedListeners ) . toHaveLength ( 1 ) ) ;
60- syncService . pushLine ( checkpoint ) ;
61- addData ( '1' ) ;
62-
63- await vi . waitFor ( async ( ) => {
64- expect ( await database . getAll ( 'SELECT * FROM ps_oplog' ) ) . toHaveLength ( 1 ) ;
65- } ) ;
66- await database . disconnect ( ) ;
67- // The JavaScript client encodes subkeys to JSON when it shouldn't...
68- expect ( await database . getAll ( 'SELECT * FROM ps_oplog' ) ) . toEqual ( [
69- expect . objectContaining ( { key : 'lists/1/"subkey_1"' } )
70- ] ) ;
71-
72- // Connecting again with the new client should fix the format
73- database . connect ( new TestConnector ( ) , {
74- clientImplementation : SyncClientImplementation . RUST ,
7575 connectionMethod : SyncStreamConnectionMethod . HTTP
7676 } ) ;
7777 await vi . waitFor ( ( ) => expect ( syncService . connectedListeners ) . toHaveLength ( 1 ) ) ;
@@ -86,25 +86,6 @@ describe('Sync', () => {
8686 expect . objectContaining ( { key : 'lists/1/subkey_1' } ) ,
8787 expect . objectContaining ( { key : 'lists/2/subkey_2' } )
8888 ] ) ;
89-
90- // Finally, connecting with JS again should keep the fixed subkey format.
91- database . connect ( new TestConnector ( ) , {
92- clientImplementation : SyncClientImplementation . RUST ,
93- connectionMethod : SyncStreamConnectionMethod . HTTP
94- } ) ;
95- await vi . waitFor ( ( ) => expect ( syncService . connectedListeners ) . toHaveLength ( 1 ) ) ;
96- syncService . pushLine ( checkpoint ) ;
97- addData ( '3' ) ;
98- await vi . waitFor ( async ( ) => {
99- expect ( await database . getAll ( 'SELECT * FROM ps_oplog' ) ) . toHaveLength ( 3 ) ;
100- } ) ;
101- await database . disconnect ( ) ;
102- expect ( await database . getAll ( 'SELECT * FROM ps_oplog' ) ) . toEqual ( [
103- // Existing entry should be fixed too!
104- expect . objectContaining ( { key : 'lists/1/subkey_1' } ) ,
105- expect . objectContaining ( { key : 'lists/2/subkey_2' } ) ,
106- expect . objectContaining ( { key : 'lists/3/subkey_3' } )
107- ] ) ;
10889 } ) ;
10990
11091 mockSyncServiceTest ( 'reconnects immediately after changed connection' , async ( { syncService } ) => {
0 commit comments