Skip to content

test: fix flaky test_put_contract_three_hop_returns_response #2112

@sanity

Description

@sanity

Problem

test_put_contract_three_hop_returns_response fails intermittently in CI with timeout errors:

  • Transaction timed out errors
  • Connection already exists errors
  • Times out after 120 seconds waiting for PUT response

Latest failure: https://github.com/freenet/freenet-core/actions/runs/19486370415/job/55769443837

Root Cause

The test has a known issue documented in the code itself (crates/core/tests/operations.rs:1938-1941):

// Note: We cannot modify node locations after they're created with the macro,
// so this test will use random locations. The original test had specific location
// requirements to ensure proper three-hop routing. For now, we'll proceed with
// the test and it should still validate PUT response routing.

The test requires:

  • Specific node topology for guaranteed three-hop routing (gateway → peer-a → intermediate → peer-c)
  • Currently uses random locations which sometimes don't create the required topology
  • When topology is wrong, messages don't route correctly and test times out

Impact

  • Causes false-positive CI failures on unrelated PRs
  • Requires manual re-runs, slowing down development
  • Wastes CI resources (10+ minute timeouts)
  • Creates uncertainty about actual failures vs flakes

Solution

Make the test deterministic:

  1. Use fixed locations for nodes to guarantee three-hop path:

    • Gateway at location 0.1
    • Peer A at location 0.3
    • Intermediate peer at location 0.5
    • Peer C at location 0.7
  2. Verify topology before running the test (assert connection graph matches expectations)

  3. Replace timeout waits with condition-based polling (related to Replace fixed timing waits in tests with condition-based polling #1943)

  4. Add diagnostic logging when test fails to help debug future issues

Related Issues

Test Location

crates/core/tests/operations.rs:1922

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-developer-xpArea: developer experienceA-networkingArea: Networking, ring protocol, peer discoveryE-mediumExperience needed to fix/implement: Medium / intermediateP-highHigh priorityT-bugType: Something is broken

    Type

    No type

    Projects

    Status

    Triage

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions