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
2 changes: 1 addition & 1 deletion powersync/src/sync/instruction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ pub struct Timestamp(pub i64);

impl From<Timestamp> for SystemTime {
fn from(val: Timestamp) -> Self {
let since_epoch = Duration::from_secs(val.0 as u64);
let since_epoch = Duration::from_micros(val.0 as u64);
SystemTime::UNIX_EPOCH + since_epoch
}
}
31 changes: 30 additions & 1 deletion powersync/tests/sync_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::{
Arc,
atomic::{AtomicUsize, Ordering},
},
time::Duration,
time::{Duration, SystemTime},
};

use async_task::Task;
Expand Down Expand Up @@ -424,3 +424,32 @@ fn upload_retry() {
assert!(sync.db.next_crud_transaction().await.unwrap().is_none());
});
}

#[test]
fn reports_correct_times() {
let sync = SyncStreamTest::new();
sync.connect();

sync.run(async {
let request = sync.test.http.receive_requests.recv().await.unwrap();
sync.wait_for_status(|s| s.is_connected()).await;

request
.send_checkpoint(Checkpoint::single_bucket("a", 0, None))
.await;
request.send_checkpoint_complete(0, None).await;
sync.wait_for_status(|s| !s.is_downloading()).await;

let stream = sync.db.sync_stream("a", None);
let status = sync.db.status();
let status = status
.for_stream(&stream)
.expect("should have stream status");
let last_synced_at = status
.subscription
.last_synced_at()
.expect("should have last synced at");
let delta = SystemTime::now().duration_since(last_synced_at).unwrap();
assert!(delta < Duration::from_secs(5));
});
}
Loading