Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: make watch test more reliable #74

Merged
merged 1 commit into from
Apr 27, 2024
Merged
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
33 changes: 18 additions & 15 deletions denokv/tests/integration.rs
Original file line number Diff line number Diff line change
@@ -2,10 +2,12 @@ use std::net::SocketAddr;
use std::num::NonZeroU32;
use std::path::PathBuf;
use std::process::Stdio;
use std::time::Duration;

use bytes::Bytes;
use denokv_proto::AtomicWrite;
use denokv_proto::Database;
use denokv_proto::KvEntry;
use denokv_proto::KvValue;
use denokv_proto::ReadRange;
use denokv_proto::WatchKeyOutput;
@@ -229,12 +231,17 @@ async fn watch() {
let remote2 = remote.clone();
let local = LocalSet::new();
let (tx, mut rx) = tokio::sync::mpsc::unbounded_channel();
let a = local.spawn_local(async move {
local.spawn_local(async move {
let mut s = remote2.watch(vec![vec![1]]);
while let Some(w) = s.next().await {
let w = w.expect("watch success");
eprintln!("{w:?}");
tx.send(w).expect("send success");
eprintln!("Watch output: {w:?}");
for w in w {
if let WatchKeyOutput::Changed { entry: Some(_) } = w {
tx.send(w).expect("send success");
return;
}
}
}
});
local.spawn_local(async move {
@@ -255,19 +262,15 @@ async fn watch() {
.unwrap()
.expect("commit success");
}
a.abort();
});
local.await;

let mut count = 0;
while let Some(w) = rx.recv().await {
for w in w {
if let WatchKeyOutput::Changed { entry: Some(_) } = w {
count += 1;
}
}
}
assert!(count > 0);
tokio::time::timeout(Duration::from_secs(60), local)
.await
.expect("no timeout");
let w = rx.try_recv().expect("recv success");
let WatchKeyOutput::Changed { entry: Some(entry) } = w else {
panic!("Unexpected watch result");
};
assert_eq!(entry.key, vec![1]);
}

#[tokio::test]