← Back to Pull requests

Deflake `TestRequestScan` with `synctest` #54700

Closed
unknown closed this pull request without merging on Aug 11, 2026 10:35 UTC
View on GitHub
unknown unknown commented on Aug 11, 2026 06:52 UTC
Author

What does this PR do?


Wrap TestRequestScan and TestQueueDueScans in synctest "bubbles", replacing assert.EventuallyWithT's real-clock polling with synctest.Wait().

Motivation


Stumbled upon the following flake when running tests locally through bazel with flake detection:
    --- FAIL: TestRequestScan/default_scan_is_enabled_via_config (4.44s)
        mock.go:28: 2026-08-07 15:06:43 UTC | WARN | (pkg/api/util/util_dca.go:67 in SetCrossNodeClientTLSConfig) | Cross-node client TLS configuration is already set, ignoring the new configuration
        mock.go:28: 2026-08-07 15:06:43 UTC | INFO | (comp/snmpscanmanager/impl/snmpscanmanager.go:184 in RequestScan) | Queued default scan request for device 192.168.0.1
        mock.go:28: 2026-08-07 15:06:43 UTC | INFO | (comp/snmpscanmanager/impl/snmpscanmanager.go:184 in RequestScan) | Queued default scan request for device 192.168.0.2
        mock.go:28: 2026-08-07 15:06:43 UTC | INFO | (comp/snmpscanmanager/impl/snmpscanmanager.go:184 in RequestScan) | Queued default scan request for device 10.0.0.1
        mock.go:28: 2026-08-07 15:06:43 UTC | INFO | (comp/snmpscanmanager/impl/snmpscanmanager.go:184 in RequestScan) | Queued default scan request for device 10.0.0.2
        mock.go:28: 2026-08-07 15:06:43 UTC | WARN | (comp/snmpscanmanager/impl/snmpscanmanager.go:270 in onDeviceScanFailure) | Default scan for device 192.168.0.2 failed with a non-retryable error, will not be retried
        mock.go:28: 2026-08-07 15:06:43 UTC | INFO | (comp/snmpscanmanager/impl/snmpscanmanager.go:244 in processScanRequest) | Successfully processed default scan request for device '192.168.0.1'
        mock.go:28: 2026-08-07 15:06:43 UTC | ERROR | (comp/snmpscanmanager/impl/snmpscanmanager.go:204 in scanWorker) | Error processing default scan request for device '192.168.0.2': some error
        snmpscanmanager_test.go:305:
            	Error Trace:	comp/snmpscanmanager/impl/snmpscanmanager_test.go:944
            	            				comp/snmpscanmanager/impl/snmpscanmanager_test.go:306
            	            				src/runtime/asm_amd64.s:1771
            	Error:      	Not equal:
            	            	expected: 4
            	            	actual  : 2
        snmpscanmanager_test.go:305:
            	Error Trace:	comp/snmpscanmanager/impl/snmpscanmanager_test.go:305
            	Error:      	Condition never satisfied
            	Test:       	TestRequestScan/default_scan_is_enabled_via_config

It turns out the flake also triggers at times in CI (example).

scanWorkers = 2 and nothing in the scan chain sleeps, so 4 queued devices need 2 waves, and a contended runner can occasionally make the second wave outlast EventuallyWithT's fixed 2 seconds.

TestQueueDueScans shares the same worker pool and queuing code, hence the same theoretical exposure, though its 2 due scans against 2 workers never actually need a second wave.

With synctest faking time, the bubble's clock advances once every goroutine is durably blocked, so the completion check can no longer time out against wall clock.

Describe how you validated your changes


40/40 tests in the package pass under -race, both tests pass 30/30 repeated -race runs, and timing improves as a side effect: the same passing subtest averages ~130ms before this change versus ~35ms after.

Diff: 432 lines (+324 / -108) across 5 files Reviewer: Pierre-L42 Review duration: 222m
All Vouch review confidence checks passed
Residual risk 0.18 = Change Risk (0.45) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.45 · 432 lines diff across 5 files
0.45
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
0.17
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
60%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size diff_size
0.363
Shallow Review Depth shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #54700"
general weight: 0.35
Reviewers
Assignees
Unassigned
Labels
risk: low confidence: 60.5% reviewed
Vouch Risk Breakdown
AI-powered review risk analysis
Change Risk
Change Risk · Model 1 (XGBoost)
Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
Score: 45.2% (MEDIUM) · Higher = larger blast radius
45.2%
Review Confidence
Review Confidence · Models 2 & 3
Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
Score: 60.5% · Lower = rushed or shallow review
60.5%
Residual Risk
Residual Risk · Core Equation
Residual = Change × (1 − Confidence)
Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
Score: 17.8% · Safe to merge
17.8%