-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
160 additions
and
73 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
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,65 @@ | ||
//go:build spike | ||
|
||
package clock_test | ||
|
||
import ( | ||
"testing" | ||
"time" | ||
|
||
"go.llib.dev/testcase/clock" | ||
"go.llib.dev/testcase/clock/timecop" | ||
) | ||
|
||
func Test_spike_timeTicker(t *testing.T) { | ||
ticker := time.NewTicker(time.Second / 4) | ||
|
||
done := make(chan struct{}) | ||
defer close(done) | ||
go func() { | ||
for { | ||
select { | ||
case <-ticker.C: | ||
t.Log("ticked") | ||
case <-done: | ||
return | ||
} | ||
} | ||
}() | ||
|
||
t.Log("4 expected on sleep") | ||
time.Sleep(time.Second + time.Microsecond) | ||
|
||
t.Log("now we reset and we expect 8 tick on sleep") | ||
ticker.Reset(time.Second / 8) | ||
time.Sleep(time.Second + time.Microsecond) | ||
|
||
} | ||
|
||
func Test_spike_clockTicker(t *testing.T) { | ||
ticker := clock.NewTicker(time.Second / 4) | ||
|
||
done := make(chan struct{}) | ||
defer close(done) | ||
go func() { | ||
for { | ||
select { | ||
case <-ticker.C: | ||
t.Log("ticked") | ||
case <-done: | ||
return | ||
} | ||
} | ||
}() | ||
|
||
t.Log("4 expected on sleep") | ||
time.Sleep(time.Second + time.Microsecond) | ||
|
||
t.Log("now we reset and we expect 8 tick on sleep") | ||
ticker.Reset(time.Second / 8) | ||
time.Sleep(time.Second + time.Microsecond) | ||
|
||
t.Log("now time sped up, and where 4 would be expected on the following sleep, it should be 8") | ||
timecop.SetSpeed(t, 2) | ||
time.Sleep(time.Second + time.Microsecond) | ||
|
||
} |