-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
44099a0
commit 0da4c50
Showing
1 changed file
with
78 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
import { MongoLSN, ZERO_LSN } from '@module/common/MongoLSN.js'; | ||
import { mongo } from '@powersync/lib-service-mongodb'; | ||
import { describe, expect, test } from 'vitest'; | ||
|
||
describe('mongo lsn resume tokens', () => { | ||
test('LSN with resume tokens should be comparable', () => { | ||
// Values without a resume token should be comparable | ||
expect( | ||
new MongoLSN({ | ||
timestamp: mongo.Timestamp.fromNumber(1) | ||
}).comparable < | ||
new MongoLSN({ | ||
timestamp: mongo.Timestamp.fromNumber(10) | ||
}).comparable | ||
).true; | ||
|
||
// Values with resume tokens should correctly compare | ||
expect( | ||
new MongoLSN({ | ||
timestamp: mongo.Timestamp.fromNumber(1), | ||
resume_token: { _data: 'resume1' } | ||
}).comparable < | ||
new MongoLSN({ | ||
timestamp: mongo.Timestamp.fromNumber(10), | ||
resume_token: { _data: 'resume2' } | ||
}).comparable | ||
).true; | ||
|
||
// The resume token should not affect comparison | ||
expect( | ||
new MongoLSN({ | ||
timestamp: mongo.Timestamp.fromNumber(1), | ||
resume_token: { _data: '2' } | ||
}).comparable < | ||
new MongoLSN({ | ||
timestamp: mongo.Timestamp.fromNumber(10), | ||
resume_token: { _data: '1' } | ||
}).comparable | ||
).true; | ||
|
||
// Resume token should not be required for comparison | ||
expect( | ||
new MongoLSN({ | ||
timestamp: mongo.Timestamp.fromNumber(10), | ||
resume_token: { _data: '2' } | ||
}).comparable > // Switching the order to test this case | ||
new MongoLSN({ | ||
timestamp: mongo.Timestamp.fromNumber(9) | ||
}).comparable | ||
).true; | ||
|
||
// Comparison should be backwards compatible with old LSNs | ||
expect( | ||
new MongoLSN({ | ||
timestamp: mongo.Timestamp.fromNumber(10), | ||
resume_token: { _data: '2' } | ||
}).comparable > ZERO_LSN | ||
).true; | ||
expect( | ||
new MongoLSN({ | ||
timestamp: mongo.Timestamp.fromNumber(10), | ||
resume_token: { _data: '2' } | ||
}).comparable > | ||
new MongoLSN({ | ||
timestamp: mongo.Timestamp.fromNumber(1) | ||
}).comparable.split('|')[0] // Simulate an old LSN | ||
).true; | ||
expect( | ||
new MongoLSN({ | ||
timestamp: mongo.Timestamp.fromNumber(1), | ||
resume_token: { _data: '2' } | ||
}).comparable < | ||
new MongoLSN({ | ||
timestamp: mongo.Timestamp.fromNumber(10) | ||
}).comparable.split('|')[0] // Simulate an old LSN | ||
).true; | ||
}); | ||
}); |