bg check ajustments
This commit is contained in:
1 parent
7eed94d82c
commit
923f4e397e
14 files changed
+649
-46
No files matched your search
@@ -226,7 +226,7 @@ impl meow_server::store::ServerStore for FlakyStore {
|
||||
}
|
||||
async fn fetch(
|
||||
&self,
|
||||
mbs: &[[u8; 32]],
|
||||
mbs: &[([u8; 32], Vec<u8>)],
|
||||
limit: usize,
|
||||
) -> meow_server::store::StoreResult<Vec<meow_proto::v2::StoredMessage>> {
|
||||
self.inner.fetch(mbs, limit).await
|
||||
@@ -849,3 +849,71 @@ async fn one_shot_invitation_completes_through_servers() {
|
||||
);
|
||||
let _ = std::fs::remove_dir_all(&dir);
|
||||
}
|
||||
|
||||
// ───────────── background watch (roadmap lot 7.7) ─────────────
|
||||
|
||||
#[tokio::test(flavor = "multi_thread")]
|
||||
async fn background_watch_peeks_without_consuming() {
|
||||
let url = spawn_server().await;
|
||||
let servers = vec![url.clone()];
|
||||
let dir = tmpdir();
|
||||
let mut alice = client(&dir, "alice", &servers).await;
|
||||
let mut bob = client(&dir, "bob", &servers).await;
|
||||
let mut carol = client(&dir, "carol", &servers).await;
|
||||
connect(&mut alice, &mut bob, "bob").await;
|
||||
connect(&mut alice, &mut carol, "carol").await;
|
||||
alice.hide_contact("carol", "carol-secret").await.unwrap();
|
||||
bob.sync(Duration::ZERO).await.unwrap();
|
||||
carol.sync(Duration::ZERO).await.unwrap();
|
||||
alice.sync(Duration::ZERO).await.unwrap();
|
||||
|
||||
let path = dir.join("alice.watch");
|
||||
let key = [7u8; 32];
|
||||
alice.enable_watch(&path, key).unwrap();
|
||||
// Encrypted, and padded: neither the servers nor the number of contacts show.
|
||||
let raw = std::fs::read(&path).unwrap();
|
||||
assert!(!raw.windows(9).any(|w| w == b"127.0.0.1"));
|
||||
assert!(
|
||||
meow_client::watch_check(&path, [8u8; 32], Duration::ZERO)
|
||||
.await
|
||||
.is_err(),
|
||||
"wrong key"
|
||||
);
|
||||
// Baseline (whatever was pending), then nothing new.
|
||||
meow_client::watch_check(&path, key, Duration::ZERO).await.unwrap();
|
||||
assert_eq!(meow_client::watch_check(&path, key, Duration::ZERO).await.unwrap(), 0);
|
||||
|
||||
// A new message is counted once, and not consumed.
|
||||
bob.send_text("alice", "ping").await.unwrap();
|
||||
assert_eq!(meow_client::watch_check(&path, key, Duration::ZERO).await.unwrap(), 1);
|
||||
assert_eq!(meow_client::watch_check(&path, key, Duration::ZERO).await.unwrap(), 0);
|
||||
|
||||
// Hidden contacts are never watched.
|
||||
carol.send_text("alice", "from the hidden side").await.unwrap();
|
||||
assert_eq!(meow_client::watch_check(&path, key, Duration::ZERO).await.unwrap(), 0);
|
||||
|
||||
// The app still gets everything (nothing was acknowledged by the watcher).
|
||||
let got = texts(&alice.sync(Duration::ZERO).await.unwrap());
|
||||
assert!(got.contains(&"ping".to_string()) && got.contains(&"from the hidden side".to_string()));
|
||||
|
||||
// Long-poll: wakes up as soon as something arrives.
|
||||
let p = path.clone();
|
||||
let waiter = tokio::spawn(async move {
|
||||
let start = std::time::Instant::now();
|
||||
(
|
||||
meow_client::watch_check(&p, key, Duration::from_secs(20))
|
||||
.await
|
||||
.unwrap(),
|
||||
start.elapsed(),
|
||||
)
|
||||
});
|
||||
tokio::time::sleep(Duration::from_millis(500)).await;
|
||||
bob.send_text("alice", "wake").await.unwrap();
|
||||
let (n, elapsed) = waiter.await.unwrap();
|
||||
assert_eq!(n, 1);
|
||||
assert!(elapsed < Duration::from_secs(10), "{elapsed:?}");
|
||||
|
||||
alice.disable_watch().unwrap();
|
||||
assert!(!path.exists());
|
||||
let _ = std::fs::remove_dir_all(&dir);
|
||||
}
|
||||
Reference in new issue
Block a user