-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
setectest: add a Ticker type implementing a fake setec.Ticker
Move the unexported utility type into the shared test package. Update the tests to use the test package version instead.
- Loading branch information
1 parent
f63dc91
commit 4af0470
Showing
2 changed files
with
31 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package setectest | ||
|
||
import "time" | ||
|
||
// NewFakeTicker constructs a test-controled instance of the [setec.Ticker] | ||
// interface that can be used by tests to control the advancement of updates to | ||
// a [setec.Store]. | ||
func NewFakeTicker() *Ticker { | ||
return &Ticker{ch: make(chan time.Time), done: make(chan struct{})} | ||
} | ||
|
||
// Ticker implements the [setec.Ticker] interface allowing a test to control | ||
// the advancement of time to exercise polling. | ||
type Ticker struct { | ||
ch chan time.Time | ||
done chan struct{} | ||
} | ||
|
||
func (Ticker) Stop() {} | ||
func (f Ticker) Chan() <-chan time.Time { return f.ch } | ||
func (f *Ticker) Done() { f.done <- struct{}{} } | ||
|
||
// Poll signals the ticker, then waits for Done to be invoked. | ||
func (f *Ticker) Poll() { | ||
f.ch <- time.Now() | ||
<-f.done | ||
} |