Skip to content

Fix flaky test in indexer_startup_test.rs using deterministic synchronization #176

@coderabbitai

Description

@coderabbitai

Problem

The test test_indexer_handles_start_block_configuration in bloklid/tests/indexer_startup_test.rs has a potential flakiness issue. It uses tokio::spawn with a detached task to set requested_start_block, and then relies on a fixed sleep(Duration::from_millis(200)) before asserting the value. This timing-based approach can intermittently fail on slow or loaded CI environments.

Current Implementation

  • TrackingMockRpc.requested_start_block is an Arc<Mutex<Option<u64>>>
  • Value is set in a detached task spawned via tokio::spawn
  • Test waits a fixed 200ms before checking the value

Proposed Solution

Replace the timing-based approach with a deterministic synchronization mechanism:

  1. Change requested_start_block from Arc<Mutex<Option<u64>>> to Arc<tokio::sync::OnceCell<u64>>
  2. Set the value synchronously via OnceCell::set(...) instead of spawning a task
  3. In the test, await the cell with a bounded wait using tokio::time::timeout to fail deterministically if the value never arrives

This ensures the test will either pass reliably or fail quickly with a clear timeout error, rather than racing against arbitrary sleep durations.

References

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions