Skip to content

Commit 8dc4674

Browse files
Stabilize remaining live sync acceptance probes
1 parent dd64258 commit 8dc4674

2 files changed

Lines changed: 65 additions & 28 deletions

File tree

tests/acceptance/multi_edge.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,10 @@ async fn f21c_edge_b_observes_auto_synced_delete_before_edge_a_quits() {
219219
let nats = start_nats().await;
220220
let tenant = "f21c_edge_b_observes_auto_synced_delete_before_edge_a_quits";
221221
let mut server = spawn_server(&server_path, tenant, &nats.nats_url);
222+
assert!(
223+
wait_for_sync_server_ready(&nats.nats_url, tenant, Duration::from_secs(15)).await,
224+
"sync server should be ready before f21c begins"
225+
);
222226

223227
let setup = run_cli_script(
224228
&edge_a,

tests/acceptance/sync.rs

Lines changed: 61 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -613,6 +613,10 @@ async fn f12_auto_sync_pushes_on_commit_not_on_quit() {
613613
let ws_url = &nats.ws_url;
614614
let tenant = "f12_auto_sync_pushes_on_commit_not_on_quit";
615615
let mut server = spawn_server(&server_path, tenant, nats_url);
616+
assert!(
617+
wait_for_sync_server_ready(nats_url, tenant, Duration::from_secs(15)).await,
618+
"sync server should be ready before f12 begins"
619+
);
616620

617621
// Start CLI with spawn_cli (keeps process alive)
618622
let mut child = spawn_cli(&edge_path, &["--tenant-id", tenant, "--nats-url", ws_url]);
@@ -628,15 +632,21 @@ async fn f12_auto_sync_pushes_on_commit_not_on_quit() {
628632
// Wait for data to appear on server WHILE CLI IS STILL RUNNING.
629633
// Timeout-based poll is correct here: auto-sync is async by design,
630634
// there is no deterministic completion signal (unlike f09c which has stdout "ok" lines).
635+
let checker_path = edge_path.with_file_name("f12-checker.db");
636+
let checker_setup = run_cli_script(
637+
&checker_path,
638+
&["--tenant-id", tenant, "--nats-url", ws_url],
639+
"CREATE TABLE sensors (id UUID PRIMARY KEY, name TEXT)\n.quit\n",
640+
);
641+
assert!(
642+
checker_setup.status.success(),
643+
"checker edge setup must succeed"
644+
);
631645
let found = wait_until(Duration::from_secs(30), || {
632-
// Must not kill the server — check by opening a second connection to the DB
633-
// The server process holds the DB open, so we check via a fresh CLI pull
634-
let fresh_path = edge_path.with_file_name("f12-checker.db");
635646
let check = run_cli_script(
636-
&fresh_path,
647+
&checker_path,
637648
&["--tenant-id", tenant, "--nats-url", ws_url],
638-
"CREATE TABLE sensors (id UUID PRIMARY KEY, name TEXT)\n\
639-
.sync pull\n\
649+
".sync pull\n\
640650
SELECT count(*) FROM sensors\n\
641651
.quit\n",
642652
);
@@ -666,6 +676,10 @@ async fn f12b_auto_sync_pushes_updates_not_just_inserts() {
666676
let ws_url = &nats.ws_url;
667677
let tenant = "f12b_auto_sync_pushes_updates_not_just_inserts";
668678
let mut server = spawn_server(&server_path, tenant, nats_url);
679+
assert!(
680+
wait_for_sync_server_ready(nats_url, tenant, Duration::from_secs(15)).await,
681+
"sync server should be ready before f12b setup push begins"
682+
);
669683

670684
let mut child = spawn_cli(&edge_path, &["--tenant-id", tenant, "--nats-url", ws_url]);
671685

@@ -679,23 +693,35 @@ async fn f12b_auto_sync_pushes_updates_not_just_inserts() {
679693
UPDATE sensors SET name = 'updated' WHERE id = '00000000-0000-0000-0000-000000000001'\n",
680694
);
681695

682-
// Wait for UPDATE to appear on server while CLI is still running
683-
let mut checker_idx = 0u32;
684-
let mut last_stdout = String::new();
696+
// Wait for UPDATE to appear on the server while the writer CLI is still running.
697+
// Inspect the server DB file directly between short server restarts so this test stays
698+
// focused on edge->server auto-push rather than pull-side conflict resolution on a checker edge.
699+
let mut last_server_name = None;
685700
let found = wait_until(Duration::from_secs(30), || {
686-
checker_idx += 1;
687-
let fresh_path = edge_path.with_file_name(format!("f12b-checker-{checker_idx}.db"));
688-
let check = run_cli_script(
689-
&fresh_path,
690-
&["--tenant-id", tenant, "--nats-url", ws_url],
691-
"CREATE TABLE sensors (id UUID PRIMARY KEY, name TEXT)\n\
692-
.sync pull\n\
693-
SELECT name FROM sensors WHERE id = '00000000-0000-0000-0000-000000000001'\n\
694-
.quit\n",
701+
stop_child(&mut server);
702+
let db = Database::open(&server_path).expect("server db");
703+
let row = db.point_lookup(
704+
"sensors",
705+
"id",
706+
&Value::Uuid(Uuid::parse_str("00000000-0000-0000-0000-000000000001").unwrap()),
707+
db.snapshot(),
695708
);
696-
let stdout = output_string(&check.stdout);
697-
last_stdout = stdout.clone();
698-
stdout.contains("updated")
709+
last_server_name = match row {
710+
Ok(found) => found
711+
.as_ref()
712+
.and_then(|r| r.values.get("name"))
713+
.and_then(Value::as_text)
714+
.map(ToOwned::to_owned),
715+
Err(contextdb_core::Error::TableNotFound(_)) => None,
716+
Err(err) => panic!("server lookup: {err}"),
717+
};
718+
db.close().expect("server db close");
719+
if last_server_name.as_deref() == Some("updated") {
720+
true
721+
} else {
722+
server = spawn_server(&server_path, tenant, nats_url);
723+
false
724+
}
699725
});
700726

701727
write_child_stdin(&mut child, ".quit\n");
@@ -704,7 +730,7 @@ async fn f12b_auto_sync_pushes_updates_not_just_inserts() {
704730

705731
assert!(
706732
found,
707-
"UPDATE must auto-sync to server while CLI is still running; child stdout={}; child stderr={}; last checker stdout={last_stdout}",
733+
"UPDATE must auto-sync to server while CLI is still running; child stdout={}; child stderr={}; last server name={last_server_name:?}",
708734
output_string(&output.stdout),
709735
output_string(&output.stderr),
710736
);
@@ -802,15 +828,22 @@ async fn f12d_auto_sync_retries_after_server_starts_late() {
802828
std::thread::sleep(Duration::from_secs(2));
803829
let mut server = spawn_server(&server_path, tenant, nats_url);
804830

805-
let mut checker_idx = 0u32;
831+
let checker_path = edge_path.with_file_name("f12d-checker.db");
832+
let checker_setup = run_cli_script(
833+
&checker_path,
834+
&["--tenant-id", tenant, "--nats-url", ws_url],
835+
"CREATE TABLE sensors (id UUID PRIMARY KEY, name TEXT)\n.quit\n",
836+
);
837+
assert!(
838+
checker_setup.status.success(),
839+
"checker edge setup must succeed"
840+
);
841+
806842
let found = wait_until(Duration::from_secs(30), || {
807-
checker_idx += 1;
808-
let fresh_path = edge_path.with_file_name(format!("f12d-checker-{checker_idx}.db"));
809843
let check = run_cli_script(
810-
&fresh_path,
844+
&checker_path,
811845
&["--tenant-id", tenant, "--nats-url", ws_url],
812-
"CREATE TABLE sensors (id UUID PRIMARY KEY, name TEXT)\n\
813-
.sync pull\n\
846+
".sync pull\n\
814847
SELECT count(*) FROM sensors\n\
815848
.quit\n",
816849
);

0 commit comments

Comments
 (0)