Skip to content

Fix flaky ALSP manager tests#8606

Open
janezpodhostnik wants to merge 2 commits into
masterfrom
janezp/fix-flaky-alsp-manager-tests
Open

Fix flaky ALSP manager tests#8606
janezpodhostnik wants to merge 2 commits into
masterfrom
janezp/fix-flaky-alsp-manager-tests

Conversation

@janezpodhostnik

@janezpodhostnik janezpodhostnik commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

Fixes flakiness in network/alsp/manager tests.

My knowledge of this part of the code is a bit cursory, I tried retain the logic of the tests, but please check thoroughly if that is actually the case.

7fc8850 — Fix flaky ALSP manager tests

  • Replace assertions inside require.Eventually callbacks with return false, so the poll retries instead of aborting while reports are still being processed asynchronously.
  • Disable periodic penalty decay (via a long heartbeat interval) in tests that assert exact penalty values.

Test failure sample:

   ok      github.com/onflow/flow-go/network/alsp/internal 0.193s  coverage: 96.2% of statements
   --- FAIL: TestHandleReportedMisbehavior_Cache_Integration (1.10s)
       manager_test.go:175:
                   Error Trace:    /home/janezp/Programming/onflow/flow-go/network/alsp/manager/manager_test.go:175
                                                           /nix/store/binbxcrrms98kcy8amn34ynij0x8zrml-go-1.25.11/share/go/src/runtime/asm_amd64.s:1693
                   Error:          Not equal:
                                   expected: -22
                                   actual  : -17
                   Test:           TestHandleReportedMisbehavior_Cache_Integration
       manager_test.go:162:
                   Error Trace:    /home/janezp/Programming/onflow/flow-go/network/alsp/manager/manager_test.go:162
                   Error:          Condition never satisfied
                   Test:           TestHandleReportedMisbehavior_Cache_Integration
                   Messages:       ALSP manager did not handle the misbehavior report
   --- FAIL: TestHandleMisbehaviorReport_MultiplePenaltyReportsForMultiplePeers_Sequentially (2.01s)
       manager_test.go:1157:
                   Error Trace:    /home/janezp/Programming/onflow/flow-go/network/alsp/manager/manager_test.go:1157
                                                           /nix/store/binbxcrrms98kcy8amn34ynij0x8zrml-go-1.25.11/share/go/src/runtime/asm_amd64.s:1693
                   Error:          Not equal:
                                   expected: -42
                                   actual  : -36
                   Test:           TestHandleMisbehaviorReport_MultiplePenaltyReportsForMultiplePeers_Sequentially
       manager_test.go:1144:
                   Error Trace:    /home/janezp/Programming/onflow/flow-go/network/alsp/manager/manager_test.go:1144
                   Error:          Condition never satisfied
                   Test:           TestHandleMisbehaviorReport_MultiplePenaltyReportsForMultiplePeers_Sequentially
   FAIL
   coverage: 85.7% of statements
   FAIL    github.com/onflow/flow-go/network/alsp/manager  32.605s

a75280b — Fix flaky slashing violations consumer integration test

TestHandleReportedMisbehavior_And_SlashingViolationsConsumer_Integration is load-sensitive (reproduced 4/12 failures under CPU contention; 0/96 after the fix):

  • Wait for the misbehaving nodes' swarms to also observe the disconnection (connection closure propagates asynchronously from the victim) before running the strict no-retry connectivity checks.
  • Relax overly tight timeouts: disconnect wait 2s → 10s (disallow-listing needs an ALSP heartbeat + peer manager prune cycle, each on 1s ticks), connectivity checks 100ms → 2s, component shutdown 100ms → 2s.

Test failure sample:

ok      github.com/onflow/flow-go/network/alsp/internal 0.209s  coverage: 96.2% of statements
--- FAIL: TestHandleReportedMisbehavior_And_SlashingViolationsConsumer_Integration (1.91s)
    fixtures.go:254:
                Error Trace:    /home/janezp/Programming/onflow/flow-go/network/internal/p2pfixtures/fixtures.go:254
                                                        /home/janezp/Programming/onflow/flow-go/network/p2p/test/fixtures.go:715
                                                        /home/janezp/Programming/onflow/flow-go/network/alsp/manager/manager_test.go:546
                                                        /home/janezp/Programming/onflow/flow-go/network/alsp/manager/manager_test.go:527
                                                        /home/janezp/Programming/onflow/flow-go/network/alsp/manager/manager_test.go:545
                                                        /nix/store/binbxcrrms98kcy8amn34ynij0x8zrml-go-1.25.11/share/go/src/runtime/asm_amd64.s:1693
                Error:          Not equal:
                                expected: 0
                                actual  : 1
                Test:           TestHandleReportedMisbehavior_And_SlashingViolationsConsumer_Integration
FAIL
coverage: 85.7% of statements

Summary by CodeRabbit

  • Tests
    • Improved integration test stability when processing occurs asynchronously.
    • Prevented periodic penalty decay from affecting exact-value assertions.
    • Added more reliable checks for penalty accumulation, disallow-list status, cutoff counters, and decay values.
    • Relaxed shutdown and connectivity timing checks to better accommodate slower environments.
    • Updated expected penalty calculations for disallow-list notifications.

@janezpodhostnik janezpodhostnik requested a review from a team as a code owner July 10, 2026 14:36
@github-actions

Copy link
Copy Markdown
Contributor

Dependency Review

✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.

Scanned Files

None

@coderabbitai

coderabbitai Bot commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

The ALSP manager tests disable periodic decay where exact penalties are expected, poll for asynchronous worker-pool state transitions, widen integration connectivity timing, and include decay accrued before disallow-list notification assertions.

Changes

ALSP manager test synchronization

Layer / File(s) Summary
Cache state polling
network/alsp/manager/manager_test.go
Cache integration and single-report tests poll until penalty, cutoff, disallow-list, and decay fields reach their expected values while periodic decay is disabled.
Penalty report scenarios
network/alsp/manager/manager_test.go
Sequential, concurrent, multi-peer, and duplicate-report tests use conditional polling and long heartbeat intervals for stable accumulated-penalty assertions.
Decay and disallow-list transitions
network/alsp/manager/manager_test.go
Decay tests tolerate asynchronous processing, and disallow-list notification validation includes the decay-adjusted penalty.
Connectivity and shutdown timing
network/alsp/manager/manager_test.go
Integration shutdown and disconnection checks use wider timeouts and wait for misbehaving nodes to observe disconnection before validating remaining peer connectivity.

Estimated code review effort: 2 (Simple) | ~10 minutes

Suggested reviewers: holyfuchs, turbolent, peterargue, fxamacker

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: stabilizing flaky ALSP manager tests.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch janezp/fix-flaky-alsp-manager-tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@janezpodhostnik janezpodhostnik self-assigned this Jul 10, 2026
@codecov-commenter

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (2)
network/alsp/manager/manager_test.go (2)

1459-1469: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Minor inconsistency: DisallowListed check present in SingleHeartbeat phase-1 but missing in MultipleHeartbeats phase-1.

TestDecayMisbehaviorPenalty_SingleHeartbeat (line 1459) checks record.DisallowListed in the phase-1 polling callback, but TestDecayMisbehaviorPenalty_MultipleHeartbeats (lines 1554-1560) does not. Both tests verify the same pre-decay state. Consider adding the DisallowListed check to MultipleHeartbeats phase-1 for consistency, or document why it's intentionally omitted.

Also applies to: 1554-1560

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@network/alsp/manager/manager_test.go` around lines 1459 - 1469, The
MultipleHeartbeats phase-1 validation lacks the pre-decay DisallowListed
assertion present in TestDecayMisbehaviorPenalty_SingleHeartbeat. Update the
phase-1 polling callback in TestDecayMisbehaviorPenalty_MultipleHeartbeats to
reject records where record.DisallowListed is true, keeping its checks
consistent with the single-heartbeat test.

192-194: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Extract the default decay value to a shared variable.

The expression model.SpamRecordFactory()(unittest.IdentifierFixture()).Decay is repeated 13+ times across these tests to retrieve the default decay value. Each call allocates a new identifier and spam record. Extract it to a package-level variable or a helper for clarity and to avoid drift.

♻️ Suggested refactor
+// defaultDecay is the default decay value used by newly created spam records.
+var defaultDecay = model.SpamRecordFactory()(unittest.IdentifierFixture()).Decay

Then replace all occurrences:

- if record.Decay != model.SpamRecordFactory()(unittest.IdentifierFixture()).Decay {
+ if record.Decay != defaultDecay {

Alternatively, if the value must be computed at test time, use a helper:

+func defaultDecayValue() float64 {
+     return model.SpamRecordFactory()(unittest.IdentifierFixture()).Decay
+ }

Also applies to: 783-785, 911-913, 989-991, 1057-1059, 1138-1140, 1229-1231, 1311-1313, 1391-1393, 1467-1469, 1558-1560, 1649-1651, 1834-1836

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@network/alsp/manager/manager_test.go` around lines 192 - 194, Extract the
repeated default decay expression used in the tests into a package-level shared
variable or helper, such as near the test fixtures. Replace every occurrence in
the affected comparisons, including those in the relevant test sections, with
the shared value so the identifier and spam record are created only once and all
tests use the same default.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@network/alsp/manager/manager_test.go`:
- Around line 1459-1469: The MultipleHeartbeats phase-1 validation lacks the
pre-decay DisallowListed assertion present in
TestDecayMisbehaviorPenalty_SingleHeartbeat. Update the phase-1 polling callback
in TestDecayMisbehaviorPenalty_MultipleHeartbeats to reject records where
record.DisallowListed is true, keeping its checks consistent with the
single-heartbeat test.
- Around line 192-194: Extract the repeated default decay expression used in the
tests into a package-level shared variable or helper, such as near the test
fixtures. Replace every occurrence in the affected comparisons, including those
in the relevant test sections, with the shared value so the identifier and spam
record are created only once and all tests use the same default.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 5c2b37e4-975a-42fd-a780-0b946b346c17

📥 Commits

Reviewing files that changed from the base of the PR and between a983fda and 7fc8850.

📒 Files selected for processing (1)
  • network/alsp/manager/manager_test.go

@blacksmith-sh

This comment has been minimized.

@janezpodhostnik janezpodhostnik requested a review from a team July 10, 2026 16:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants