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

Sniffer::wait_for_message_count #1283

Closed
Closed
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
19 changes: 19 additions & 0 deletions roles/tests-integration/tests/common/sniffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,21 @@ impl Sniffer {
panic!("Impossible to accept dowsntream connection")
}
}

/// used to block the test runtime
/// while we wait until Sniffer has a specific count of messages
pub async fn wait_for_message_count(&self, message_direction: MessageDirection, count: usize) {
loop {
let message_count = match message_direction {
MessageDirection::ToDownstream => self.messages_from_upstream.message_count(),
MessageDirection::ToUpstream => self.messages_from_downstream.message_count(),
};

if message_count >= count {
return;
}
}
}
}

// Utility macro to assert that the downstream and upstream roles have sent specific messages.
Expand Down Expand Up @@ -589,6 +604,10 @@ impl MessagesAggregator {
.unwrap()
}

fn message_count(&self) -> usize {
self.messages.safe_lock(|messages| messages.len()).unwrap()
}

// The aggregator queues messages in FIFO order, so this function returns the oldest message in
// the queue.
//
Expand Down
Loading