Replies: 1 comment
-
|
It’s great to see the effort to improve the integration tests — that’s definitely appreciated.
There’s a bit of a chicken-and-egg situation here. Because of that, I’m not sure the framing of “before the sniffer is actually listening for connections” is entirely accurate. That said, it is true that the function returns before the sniffer is fully connected to both upstream and downstream. One possible approach(what you are suggesting) could be to return the receiver side of a channel and have the test wait on it, which would allow us to remove the sleep. That might be a bit overengineered for testing purposes, though. If we do go in that direction, I think it should remain an internal mechanism rather than something each test has to handle explicitly.
I understand the concern here, but asserting every property of every message could make the tests very verbose and somewhat painful to write and maintain. For example, if a test is specifically about validating the |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Context
After reviewing the integration test framework in sv2-apps, specifically
sniffer.rs,message_aggregator.rs,mock_roles.rs, and the test files, I discovered several structural issues that affect test reliability. These issues can cause false positives (tests pass when code is broken), false negatives (tests fail when code is correct), and slow test execution.Note: The framework relies on time-based synchronization (fixed sleeps, polling intervals) instead of event-based synchronization (ready signals, notifications). This makes tests fragile, slow, and non-deterministic.
Issues Discovered
Sniffer Returns Before Ready
The
start()function insniffer.rs:81-113spawns an async task and returns immediately, before the sniffer is actually listening for connections.Tests compensate with arbitrary sleeps, as seen in
mod.rs:152:If the sniffer takes longer than the sleep to bind its port, downstream connections fail and tests crash.
Instant Negative Assertions
The
assert_message_not_present()function insniffer.rs:205-219checks the queue at a single point in time and returns immediately.Tests use this with a preceding sleep, as seen in
pool_integration.rs:314:If the message arrives at 1.001 seconds, the test passes but the code is broken. The assertion checks a snapshot in time, not a guarantee that the message will never arrive.
Coarse Polling Interval
Message polling in
sniffer.rs:198uses a 1-second interval, which significantly slows down test execution.A message arriving at 10ms is not detected until 1000ms. A test waiting for 5 messages takes a minimum of 5 seconds regardless of how fast the system responds.
The same 1-second polling exists in
sv1_sniffer.rs:118andsv1_sniffer.rs:154.Weak Assertions
Current assertions in test files like
pool_integration.rsonly verify message type, not message content.This does not verify that
used_version,flags, or any other fields contain correct values. A bug could sendSetupConnectionSuccess { used_version: 0, flags: 0 }and tests would still pass.Arbitrary Sleep Values
Hardcoded sleep durations are scattered throughout the codebase with no relation to actual timing requirements.
template_provider.rs:346template_provider.rs:180mod.rs:152pool_integration.rs:314pool_integration.rs:341jd_integration.rs:44jdc_block_propagation.rs:42This is not exhaustive. These values work on fast machines but can cause flaky failures on slower CI systems.
Disabled Message Verification
Most tests disable
check_on_drop, which would otherwise verify that all captured messages were consumed.Unconsumed messages could indicate unexpected protocol behavior or missing test assertions.
Proposed Improvements
The solution is to shift from time-based to event-based synchronization wherever possible.
oneshot::Receiverthat signals when the sniffer is listeningcheck_on_dropby defaultThese are incremental fixes to the existing codebase, not a rewrite.
Note: Some work has already started. PR #156 added sleep to connection retry loops in
Sniffer,MockDownstream, andSnifferSV1. PR #191 adds implicitSetupConnectionhandling toMockDownstreamandMockUpstream. These can serve as a foundation for the remaining improvements.Discussion
Beta Was this translation helpful? Give feedback.
All reactions