Skip to content

Commit

Permalink
fix(sim): correct Waiting state comparison in NodeHolder::ready() (
Browse files Browse the repository at this point in the history
…#2263)

A `Node` (e.g. a `Client`, `Server` or `TailDrop` router) can be in 3 states:

``` rust
enum NodeState {
    /// The node just produced a datagram.  It should be activated again as soon as possible.
    Active,
    /// The node is waiting.
    Waiting(Instant),
    /// The node became idle.
    Idle,
}
```

`NodeHolder::ready()` determines whether a `Node` is ready to be processed
again. When `NodeState::Waiting`, it should only be ready when `t <= now`, i.e.
the waiting time has passed, not `t >= now`.

``` rust
impl NodeHolder {
    fn ready(&self, now: Instant) -> bool {
        match self.state {
            Active => true,
            Waiting(t) => t <= now, // not >=
            Idle => false,
        }
    }
}
```

The previous behavior lead to wastefull non-ready `Node`s being processed and
thus a large test runtime when e.g. simulating a gbit
connection (#2203).
  • Loading branch information
mxinden authored Dec 8, 2024
1 parent dd8e801 commit a87b379
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion test-fixture/src/sim/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ impl NodeHolder {
fn ready(&self, now: Instant) -> bool {
match self.state {
Active => true,
Waiting(t) => t >= now,
Waiting(t) => t <= now,
Idle => false,
}
}
Expand Down

0 comments on commit a87b379

Please sign in to comment.