Skip to content

fix: flaky test relay_does_not_accept_when_not_at_terminus uses Location::random() #3657

@sanity

Description

@sanity

Problem

relay_does_not_accept_when_not_at_terminus (crates/core/src/operations/connect.rs:3084) uses Location::random() for the desired_location. Since Location::random() uses GlobalRng, which is process-global shared state:

  1. When run concurrently with other tests, the RNG state differs, producing different locations
  2. The random location may make self_loc the closest peer to desired_location, turning the relay into a terminus — the test then fails because it expects forwarding, not acceptance

Root Cause

Location::random() at line 3091 is non-deterministic when tests run in parallel.

Fix

Replace Location::random() with a fixed location that guarantees next_hop is closer to the target than self_loc. For example:

desired_location: next_hop.location().unwrap(),

This ensures the relay always has a closer peer and is never at terminus.

Reproduction

Run the full test suite; it fails intermittently:

cargo test -p freenet --lib  # fails ~5% of the time
cargo test -p freenet --lib relay_does_not_accept_when_not_at_terminus  # always passes alone

[AI-assisted - Claude]

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-developer-xpArea: developer experienceA-networkingArea: Networking, ring protocol, peer discoveryE-easyExperience needed to fix/implement: Easy / not muchP-mediumMedium priorityT-bugType: Something is broken

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions