Skip to content

Commit

Permalink
Fix race issue in tick_test.go (influxdata#7663)
Browse files Browse the repository at this point in the history
  • Loading branch information
danielnelson authored and rhajek committed Jul 13, 2020
1 parent 6fed6bf commit 3ddc233
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
11 changes: 10 additions & 1 deletion agent/tick_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ func TestAlignedTicker(t *testing.T) {
until := since.Add(60 * time.Second)

ticker := newAlignedTicker(since, interval, jitter, clock)
defer ticker.Stop()

expected := []time.Time{
time.Unix(10, 0).UTC(),
Expand All @@ -32,11 +33,12 @@ func TestAlignedTicker(t *testing.T) {
}

actual := []time.Time{}

clock.Add(10 * time.Second)
for !clock.Now().After(until) {
select {
case tm := <-ticker.Elapsed():
actual = append(actual, tm.UTC())
default:
}
clock.Add(10 * time.Second)
}
Expand All @@ -53,6 +55,7 @@ func TestAlignedTickerJitter(t *testing.T) {
until := since.Add(60 * time.Second)

ticker := newAlignedTicker(since, interval, jitter, clock)
defer ticker.Stop()

last := since
for !clock.Now().After(until) {
Expand All @@ -75,6 +78,7 @@ func TestAlignedTickerMissedTick(t *testing.T) {
since := clock.Now()

ticker := newAlignedTicker(since, interval, jitter, clock)
defer ticker.Stop()

clock.Add(25 * time.Second)
tm := <-ticker.Elapsed()
Expand All @@ -94,6 +98,7 @@ func TestUnalignedTicker(t *testing.T) {
until := since.Add(60 * time.Second)

ticker := newUnalignedTicker(interval, jitter, clock)
defer ticker.Stop()

expected := []time.Time{
time.Unix(1, 0).UTC(),
Expand Down Expand Up @@ -128,6 +133,7 @@ func TestRollingTicker(t *testing.T) {
until := since.Add(60 * time.Second)

ticker := newUnalignedTicker(interval, jitter, clock)
defer ticker.Stop()

expected := []time.Time{
time.Unix(1, 0).UTC(),
Expand Down Expand Up @@ -166,6 +172,7 @@ func TestAlignedTickerDistribution(t *testing.T) {
since := clock.Now()

ticker := newAlignedTicker(since, interval, jitter, clock)
defer ticker.Stop()
dist := simulatedDist(ticker, clock)
printDist(dist)
require.True(t, 350 < dist.Count)
Expand All @@ -185,6 +192,7 @@ func TestUnalignedTickerDistribution(t *testing.T) {
clock := clock.NewMock()

ticker := newUnalignedTicker(interval, jitter, clock)
defer ticker.Stop()
dist := simulatedDist(ticker, clock)
printDist(dist)
require.True(t, 350 < dist.Count)
Expand All @@ -204,6 +212,7 @@ func TestRollingTickerDistribution(t *testing.T) {
clock := clock.NewMock()

ticker := newRollingTicker(interval, jitter, clock)
defer ticker.Stop()
dist := simulatedDist(ticker, clock)
printDist(dist)
require.True(t, 275 < dist.Count)
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ require (
github.com/aristanetworks/goarista v0.0.0-20190325233358-a123909ec740
github.com/armon/go-metrics v0.3.0 // indirect
github.com/aws/aws-sdk-go v1.30.9
github.com/benbjohnson/clock v1.0.2
github.com/benbjohnson/clock v1.0.3
github.com/bitly/go-hostpool v0.1.0 // indirect
github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869 // indirect
github.com/caio/go-tdigest v2.3.0+incompatible // indirect
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,8 @@ github.com/armon/go-metrics v0.3.0 h1:B7AQgHi8QSEi4uHu7Sbsga+IJDU+CENgjxoo81vDUq
github.com/armon/go-metrics v0.3.0/go.mod h1:zXjbSimjXTd7vOpY8B0/2LpvNvDoXBuplAD+gJD3GYs=
github.com/aws/aws-sdk-go v1.30.9 h1:DntpBUKkchINPDbhEzDRin1eEn1TG9TZFlzWPf0i8to=
github.com/aws/aws-sdk-go v1.30.9/go.mod h1:5zCpMtNQVjRREroY7sYe8lOMRSxkhG6MZveU8YkpAk0=
github.com/benbjohnson/clock v1.0.2 h1:Z0CN0Yb4ig9sGPXkvAQcGJfnrrMQ5QYLCMPRi9iD7YE=
github.com/benbjohnson/clock v1.0.2/go.mod h1:bGMdMPoPVvcYyt1gHDf4J2KE153Yf9BuiUKYMaxlTDM=
github.com/benbjohnson/clock v1.0.3 h1:vkLuvpK4fmtSCuo60+yC63p7y0BmQ8gm5ZXGuBCJyXg=
github.com/benbjohnson/clock v1.0.3/go.mod h1:bGMdMPoPVvcYyt1gHDf4J2KE153Yf9BuiUKYMaxlTDM=
github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973 h1:xJ4a3vCFaGF/jqvzLMYoU8P317H5OQ+Via4RmuPwCS0=
github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q=
github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8=
Expand Down

0 comments on commit 3ddc233

Please sign in to comment.