Skip to content

Commit d1b7fcb

Browse files
committed
Fix lastSyncedAt values with Rust client
1 parent b398483 commit d1b7fcb

File tree

3 files changed

+29
-1
lines changed

3 files changed

+29
-1
lines changed

.changeset/tall-dolphins-sleep.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@powersync/common': patch
3+
---
4+
5+
Rust sync client: Fix reported `lastSyncedAt` values in sync status.

packages/common/src/client/sync/stream/AbstractStreamingSyncImplementation.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -923,7 +923,7 @@ The next upload iteration will be delayed.`);
923923
return {
924924
priority: status.priority,
925925
hasSynced: status.has_synced ?? undefined,
926-
lastSyncedAt: status?.last_synced_at != null ? new Date(status!.last_synced_at!) : undefined
926+
lastSyncedAt: status?.last_synced_at != null ? new Date(status!.last_synced_at! * 1000) : undefined
927927
};
928928
}
929929

packages/node/tests/sync.test.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,29 @@ function defineSyncTests(impl: SyncClientImplementation) {
112112
connectionMethod: SyncStreamConnectionMethod.HTTP
113113
};
114114

115+
mockSyncServiceTest('sets last sync time', async ({ syncService }) => {
116+
const db = await syncService.createDatabase();
117+
db.connect(new TestConnector(), options);
118+
await vi.waitFor(() => expect(syncService.connectedListeners).toHaveLength(1));
119+
120+
syncService.pushLine({
121+
checkpoint: {
122+
last_op_id: '0',
123+
buckets: []
124+
}
125+
});
126+
syncService.pushLine({ checkpoint_complete: { last_op_id: '0' } });
127+
const now = Date.now();
128+
129+
await db.waitForFirstSync();
130+
const status = db.currentStatus;
131+
const lastSyncedAt = status.lastSyncedAt!.getTime();
132+
133+
// The reported time of the last sync should be close to the current time (5s is very generous already, but we've
134+
// had an issue where dates weren't parsed correctly and we were off by decades).
135+
expect(Math.abs(lastSyncedAt - now)).toBeLessThan(5000);
136+
});
137+
115138
describe('reports progress', () => {
116139
let lastOpId = 0;
117140

0 commit comments

Comments
 (0)