fix: deflake delegate node-limit tests under parallel cargo test --lib#4564
fix: deflake delegate node-limit tests under parallel cargo test --lib#4564mvanhorn wants to merge 1 commit into
Conversation
test_create_delegate_non_attested_still_counts_toward_node_limit snapshots the process-global CREATED_DELEGATES_COUNT atomic into `before`, creates a delegate, and asserts `after > before` before restoring the counter with fetch_sub(1). Under a threaded `cargo test -p freenet --lib` run, sibling delegate-creation tests on other threads call create_delegate_sync concurrently and fetch_add the same global, perturbing the before/after snapshot and racing the cleanup. CI uses nextest per-process isolation so it never sees the race. Serialize the delegate-creation tests that read or mutate the shared CREATED_DELEGATES_COUNT global into a single named serial group (`#[serial_test::serial(created_delegates_count)]`) so they cannot run concurrently with one another. The named group avoids globally serializing the whole suite. serial_test is already a workspace dev-dependency. No production code changes; the fix is confined to the test module. Fixes freenet#4418
|
Now I have all the context needed. Let me compile the review. Rule Review: No significant issues foundRules checked: SummaryThe PR adds Root-cause assessment: The fix is appropriate. Counter accumulation: WarningsNone. Info
Rule review against |
|
The Rule Lint is failing because this |
What
Deflakes
test_create_delegate_non_attested_still_counts_toward_node_limit(and its sibling delegate-creation tests) under a threadedcargo test -p freenet --librun.Why
test_create_delegate_non_attested_still_counts_toward_node_limitsnapshots the process-globalCREATED_DELEGATES_COUNTatomic intobefore, creates a delegate, assertsafter > before, then restores the counter withfetch_sub(1). Because the counter is a process-global static, other delegate-creation tests in the same binary run concurrently on other threads and callCREATED_DELEGATES_COUNT.fetch_add(1)insidecreate_delegate_sync, perturbing thebefore/aftersnapshot and racing the cleanup. The test passes in isolation but fails intermittently under the full parallel--librun.CI uses nextest per-process isolation, so each test gets its own process and never observes the race; only a threaded
cargo test --libexercises it.How
Group the delegate-creation tests that read or mutate the shared
CREATED_DELEGATES_COUNTglobal into a single named serial group via#[serial_test::serial(created_delegates_count)], so they cannot run concurrently with one another. The named group serializes only these tests against each other; it does not globally serialize the rest of the suite, keeping the wall-clock impact minimal.serial_testis already a workspace dev-dependency.No production code changes — the fix is confined to the test module in
crates/core/src/wasm_runtime/delegate_api.rs.Verification
cargo build -p freenet --lib— passescargo test -p freenet --lib wasm_runtime::delegate_api— 43 passed, 0 failedcargo fmt -p freenet --check— cleanFixes #4418