Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .changeset/tall-dolphins-sleep.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
'@powersync/common': patch
'@powersync/node': patch
'@powersync/web': patch
'@powersync/react-native': patch
---

Rust sync client: Fix reported `lastSyncedAt` values in sync status.
Original file line number Diff line number Diff line change
Expand Up @@ -923,7 +923,7 @@ The next upload iteration will be delayed.`);
return {
priority: status.priority,
hasSynced: status.has_synced ?? undefined,
lastSyncedAt: status?.last_synced_at != null ? new Date(status!.last_synced_at!) : undefined
lastSyncedAt: status?.last_synced_at != null ? new Date(status!.last_synced_at! * 1000) : undefined
};
}

Expand Down
23 changes: 23 additions & 0 deletions packages/node/tests/sync.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,29 @@ function defineSyncTests(impl: SyncClientImplementation) {
connectionMethod: SyncStreamConnectionMethod.HTTP
};

mockSyncServiceTest('sets last sync time', async ({ syncService }) => {
const db = await syncService.createDatabase();
db.connect(new TestConnector(), options);
await vi.waitFor(() => expect(syncService.connectedListeners).toHaveLength(1));

syncService.pushLine({
checkpoint: {
last_op_id: '0',
buckets: []
}
});
syncService.pushLine({ checkpoint_complete: { last_op_id: '0' } });
const now = Date.now();

await db.waitForFirstSync();
const status = db.currentStatus;
const lastSyncedAt = status.lastSyncedAt!.getTime();

// The reported time of the last sync should be close to the current time (5s is very generous already, but we've
// had an issue where dates weren't parsed correctly and we were off by decades).
expect(Math.abs(lastSyncedAt - now)).toBeLessThan(5000);
});

describe('reports progress', () => {
let lastOpId = 0;

Expand Down