test(sync): observe descendant live generation before replies

Layer-3 tag tests waited a fixed 500 ms after the root arrived. Root confirmation and the bounded five-second descendant maintenance tick can legitimately take longer, so all three tag variants published before their live coverage existed.

Record the current descendant-live generation and wait with a bounded deadline for a newer installation before publishing each reply. This preserves the e, E, and q delivery assertions and removes timing as a proxy for readiness.

Validated with all three Layer-3 tag-variation integration tests.
This commit is contained in:
DanConwayDev
2026-08-12 15:28:39 +00:00
parent a861d444e7
commit 53388db511
2 changed files with 48 additions and 6 deletions
+27
View File
@@ -18,6 +18,33 @@ use nostr_sdk::prelude::*;
use super::port::{self, PortReservation};
use super::relay::TestRelay;
const DESCENDANT_LIVE_LOG: &str = "Installed priority-bounded auxiliary live coverage";
pub fn descendant_live_generation(relay: &TestRelay) -> usize {
std::fs::read_to_string(relay.log_path())
.unwrap_or_default()
.matches(DESCENDANT_LIVE_LOG)
.count()
}
pub async fn wait_for_new_descendant_live_generation(
relay: &TestRelay,
previous: usize,
timeout: Duration,
) {
let deadline = tokio::time::Instant::now() + timeout;
loop {
if descendant_live_generation(relay) > previous {
return;
}
assert!(
tokio::time::Instant::now() < deadline,
"descendant live coverage was not installed before the deadline"
);
tokio::task::yield_now().await;
}
}
// NOTE: Using rust-nostr Kind variants:
// - Kind::GitIssue.as_u16() -> Kind::GitIssue (1621)
// - Kind::Comment.as_u16() -> Kind::Comment (1111)
+21 -6
View File
@@ -348,6 +348,7 @@ async fn test_layer3_sync_with_lowercase_e_tag() {
let issue = build_layer2_issue_event(&keys, &repo_coordinate, "Parent Issue for Tag 9a Test")
.expect("Failed to create issue");
let issue_id = issue.id;
let descendant_generation = descendant_live_generation(&relay_b);
let client_a = TestClient::new(relay_a.url(), keys.clone())
.await
@@ -366,8 +367,12 @@ async fn test_layer3_sync_with_lowercase_e_tag() {
println!("Issue synced to relay_b: {}", issue_synced);
assert!(issue_synced, "Layer 2 issue should sync first");
// Wait for Layer 3 subscriptions to be established
tokio::time::sleep(Duration::from_millis(500)).await;
wait_for_new_descendant_live_generation(
&relay_b,
descendant_generation,
Duration::from_secs(20),
)
.await;
// 6. Create and send Layer 3 reply with lowercase 'e' tag (kind 1)
let reply = build_layer3_reply_with_e_tag(&keys, &issue_id, "Reply with lowercase e tag")
@@ -455,6 +460,7 @@ async fn test_layer3_sync_with_uppercase_e_tag() {
let issue = build_layer2_issue_event(&keys, &repo_coordinate, "Parent Issue for Tag 9b Test")
.expect("Failed to create issue");
let issue_id = issue.id;
let descendant_generation = descendant_live_generation(&relay_b);
let client_a = TestClient::new(relay_a.url(), keys.clone())
.await
@@ -473,8 +479,12 @@ async fn test_layer3_sync_with_uppercase_e_tag() {
println!("Issue synced to relay_b: {}", issue_synced);
assert!(issue_synced, "Layer 2 issue should sync first");
// Wait for Layer 3 subscriptions to be established
tokio::time::sleep(Duration::from_millis(500)).await;
wait_for_new_descendant_live_generation(
&relay_b,
descendant_generation,
Duration::from_secs(20),
)
.await;
// 6. Create and send Layer 3 comment with uppercase 'E' tag (kind 1111)
let comment =
@@ -566,6 +576,7 @@ async fn test_layer3_sync_with_q_tag() {
let issue = build_layer2_issue_event(&keys, &repo_coordinate, "Parent Issue for Tag 9c Test")
.expect("Failed to create issue");
let issue_id = issue.id;
let descendant_generation = descendant_live_generation(&relay_b);
let client_a = TestClient::new(relay_a.url(), keys.clone())
.await
@@ -584,8 +595,12 @@ async fn test_layer3_sync_with_q_tag() {
println!("Issue synced to relay_b: {}", issue_synced);
assert!(issue_synced, "Layer 2 issue should sync first");
// Wait for Layer 3 subscriptions to be established
tokio::time::sleep(Duration::from_millis(500)).await;
wait_for_new_descendant_live_generation(
&relay_b,
descendant_generation,
Duration::from_secs(20),
)
.await;
// 6. Create and send Layer 3 quote with 'q' tag (kind 1)
let quote = build_layer3_quote_with_q_tag(&keys, &issue_id, "Quote with q tag")