Skip to content

test(p2p): cover the timer branch of waitForDialTime - #6067

Open
tbruyelle wants to merge 3 commits into
gnolang:masterfrom
tbruyelle:test-p2p-dial-timer-branch
Open

test(p2p): cover the timer branch of waitForDialTime#6067
tbruyelle wants to merge 3 commits into
gnolang:masterfrom
tbruyelle:test-p2p-dial-timer-branch

Conversation

@tbruyelle

Copy link
Copy Markdown
Contributor

Description

Follow-up to #6054, from AviaOne's review. The test is theirs; I folded it in as a subtest and verified it.

runDialLoop parks on waitForDialTime, which wakes on three things:

select {
case <-ctx.Done():      // covered: "the wait ends on context cancellation"
case <-timer.C:         // not covered
case <-sw.dialNotify:   // covered: "a due item is dialed while an earlier one backs off"
}

The timer branch had no coverage, and the gap was invisible — removing case <-timer.C: left the entire package green:

$ # with `case <-timer.C:` deleted from waitForDialTime
$ go test ./tm2/pkg/p2p/
ok      github.com/gnolang/gno/tm2/pkg/p2p    0.238s

That branch is not cosmetic. Without it, a backed off item is never dialed once it becomes due: the loop parks until something else is queued or the node shuts down, so persistent peer backoff silently stops retrying. It is the behaviour #6054 exists to provide.

The test

Added as a third subtest of TestMultiplexSwitch_DialLoop_BackedOff, so the three subtests now map one to one onto the three select branches.

A single item is queued, due shortly, with nothing else in the queue and a live context — so the timer is the only thing that can bring the loop back.

Verification

Mutation checked in both directions:

new subtest other two subtests DoesNotSpin package
case <-timer.C: removed FAIL pass pass FAIL
unmodified master pass pass pass pass

So the subtest is the one carrying the guarantee, and nothing else in the suite notices that branch going missing. Passing run repeated with -count=3; gofmt, go vet and ./tm2/pkg/p2p/... all clean.

Test-only, so no ADR per AGENTS.md.


Drafted with AI assistance (Claude Code). I have reviewed the change and the verification and stand behind them.

The dial loop parks on waitForDialTime, which wakes on three things: the
context, a newly queued item, and the timer that fires when the queue head
becomes due. The first two are covered. The third was not, and the gap was
invisible: removing 'case <-timer.C:' left the whole p2p package green.

That branch is not cosmetic. Without it a backed off item is never dialed
when its time comes, so the loop parks until something else is queued or the
node shuts down, and persistent peer backoff silently stops retrying.

The new subtest queues a single item due shortly, with nothing else queued
and a live context, so the timer is the only thing that can bring the loop
back. It fails against a build with that case removed, and the other two
subtests still pass there, so it is the one carrying the guarantee.

Reported by AviaOne while reviewing gnolang#6054.
@Gno2D2

Gno2D2 commented Aug 14, 2026

Copy link
Copy Markdown
Collaborator

🛠 PR Checks Summary

All Automated Checks passed. ✅

Manual Checks (for Reviewers):
  • IGNORE the bot requirements for this PR (force green CI check)
Read More

🤖 This bot helps streamline PR reviews by verifying automated checks and providing guidance for contributors and reviewers.

✅ Automated Checks (for Contributors):

🟢 Maintainers must be able to edit this pull request (more info)

☑️ Contributor Actions:
  1. Fix any issues flagged by automated checks.
  2. Follow the Contributor Checklist to ensure your PR is ready for review.
    • Add new tests, or document why they are unnecessary.
    • Provide clear examples/screenshots, if necessary.
    • Update documentation, if required.
    • Ensure no breaking changes, or include BREAKING CHANGE notes.
    • Link related issues/PRs, where applicable.
☑️ Reviewer Actions:
  1. Complete manual checks for the PR, including the guidelines and additional checks if applicable.
📚 Resources:
Debug
Automated Checks
Maintainers must be able to edit this pull request (more info)

If

🟢 Condition met
└── 🟢 And
    ├── 🟢 The base branch matches this pattern: ^master$
    └── 🟢 The pull request was created from a fork (head branch repo: tbruyelle/gno)

Then

🟢 Requirement satisfied
└── 🟢 Maintainer can modify this pull request

Manual Checks
**IGNORE** the bot requirements for this PR (force green CI check)

If

🟢 Condition met
└── 🟢 On every pull request

Can be checked by

  • Any user with comment edit permission

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

a/blockchain Consensus, IBC, TM2 team 📦 🌐 tendermint v2 Issues or PRs tm2 related

Projects

Development

Successfully merging this pull request may close these issues.

2 participants