Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

autorelay: fix busy loop bug and flaky tests in relay finder #2208

Merged
merged 13 commits into from
Mar 22, 2023

Conversation

MarcoPolo
Copy link
Collaborator

@MarcoPolo MarcoPolo commented Mar 21, 2023

Also adds our own custom mock clock that fits a better interface for this module.

The new mock clock implements the following interface:

// InstantTimer is a timer that triggers at some instant rather than some duration
type InstantTimer interface {
	Reset(d time.Time) bool
	Stop() bool
	Ch() <-chan time.Time
}

// ClockWithInstantTimer is a clock that can create timers that trigger at some
// instant rather than some duration
type ClockWithInstantTimer interface {
	Now() time.Time
	Since(t time.Time) time.Duration
	InstantTimer(when time.Time) InstantTimer
}

This lets us avoid the issue of #2187 altogether.

The new mock clock is about 100 LOC and should behave logically close to a real clock (time shouldn't jump from 0 to 1000 without work being done in between).

Closes #2187. Closes #2192. Fixes #2189. Closes #2183

I chose to incorporate those PRs into this one to avoid the merge conflicts that would ensue.

p2p/host/autorelay/autorelay_test.go Outdated Show resolved Hide resolved
p2p/host/autorelay/autorelay_test.go Outdated Show resolved Hide resolved
p2p/host/autorelay/relay_finder.go Outdated Show resolved Hide resolved
@MarcoPolo MarcoPolo force-pushed the marco/fix-flaky-tests-and-busy-loop branch from 22be1b5 to 0abf49a Compare March 21, 2023 04:13
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh nice, you already extracted it to a separate package.

@marten-seemann marten-seemann changed the title relay_finder: Fix busy loop bug and flaky tests autorelay: fix busy loop bug and flaky tests in relay finder Mar 22, 2023
@marten-seemann marten-seemann merged commit 950151e into master Mar 22, 2023
marten-seemann pushed a commit that referenced this pull request Mar 22, 2023
* Don't run clock add in eventually loop

* Fix busy loop

* Fix scheduling bug

* Add new mock clock

* Add busy loop test

* With comments

* Fix comment

* Move mockclock to separate file

* Fix race

* Fix potential deadlock

* Fix flaky TestBackoff

* Fix import

* Fix how mock implements interface
marten-seemann pushed a commit that referenced this pull request Mar 24, 2023
* Don't run clock add in eventually loop

* Fix busy loop

* Fix scheduling bug

* Add new mock clock

* Add busy loop test

* With comments

* Fix comment

* Move mockclock to separate file

* Fix race

* Fix potential deadlock

* Fix flaky TestBackoff

* Fix import

* Fix how mock implements interface
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

autorelay: Handle WithMinInterval(0) without constantly looping
2 participants