awake: TestKeepOffWaitsForTheSetting keeps its 50ms clear of a beat (#3687)
Turned off, Keep looks at the setting at each beat, the multiples of
filememo.OthersEvery (5s) on the clock. The test counted Keep's looks
over a fixed 50ms, so a beat inside that window made a second look and
the test red, about one run in 100. That happened in the full suite on
mote at e9bde2520 ("looked at the setting 2 times in 50ms"). The test
now waits out a beat that is under a second away before it starts Keep,
as TestKeepOffSeesAWriteDuringTheLook does. Keep's code is unchanged,
as #3687 found.
Run (mote): go test -count=400 -run 'TestKeepOffWaitsForTheSetting$'
./internal/awake ok (26.7s); go test ./internal/awake ./internal/beat
ok; GOOS=linux and GOOS=windows go vet ./internal/awake ok; gofmt clean.
Broken by hand: the window put 30ms before a beat (sleep to it) without
the new wait, red 3 of 3 with the line above. With the wait, ok 3 of 3.
Not done here: #3687's comment also asks for a write-while-off check in
this test and a deferred cancel in TestKeep and TestKeepDisplay. Those
stay open on #3687.
This commit is contained in:
@@ -158,6 +158,13 @@ func TestKeepOffWaitsForTheSetting(t *testing.T) {
|
||||
hold = func(bool) (func(), error) { held.Add(1); return func() { held.Add(-1) }, nil }
|
||||
var looks atomic.Int32
|
||||
var on atomic.Bool
|
||||
// turned off, Keep also looks at each beat (beat.Next: the multiples of
|
||||
// OthersEvery on the clock); the 50ms counted below stay clear of one,
|
||||
// or its look counts as a second (#3687)
|
||||
every := filememo.OthersEvery()
|
||||
if time.Until(time.Now().Truncate(every).Add(every)) < time.Second {
|
||||
<-beat.Next(every)
|
||||
}
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
done := make(chan struct{})
|
||||
go func() {
|
||||
|
||||
Reference in New Issue
Block a user