Skip to content

Commit

Permalink
Update timers for go1.23
Browse files Browse the repository at this point in the history
Do not read timer channel after call to Stop.
  • Loading branch information
gammazero committed Sep 3, 2024
1 parent 38ce464 commit 8df363e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 27 deletions.
31 changes: 7 additions & 24 deletions assigner/core/assigner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,7 @@ func TestAssignerAll(t *testing.T) {
t.Fatal("timed out waiting for assignment")
}
}
if !timeout.Stop() {
<-timeout.C
}
timeout.Stop()
require.Equal(t, 1, len(assigns))
require.Equal(t, 0, assigns[0])

Expand Down Expand Up @@ -178,9 +176,7 @@ func TestAssignerAll(t *testing.T) {
t.Fatal("timed out waiting for assignment")
}
}
if !timeout.Stop() {
<-timeout.C
}
timeout.Stop()
sort.Ints(assigns)
require.Equal(t, []int{0, 1}, assigns)

Expand Down Expand Up @@ -271,9 +267,7 @@ func TestAssignerOne(t *testing.T) {
t.Fatal("timed out waiting for assignment")
}
}
if !timeout.Stop() {
<-timeout.C
}
timeout.Stop()
require.Equal(t, 1, len(assigns))
require.Equal(t, 0, assigns[0])

Expand Down Expand Up @@ -306,9 +300,7 @@ func TestAssignerOne(t *testing.T) {
t.Fatal("timed out waiting for assignment")
}
}
if !timeout.Stop() {
<-timeout.C
}
timeout.Stop()
require.Equal(t, 1, len(assigns))
require.Equal(t, 1, assigns[0])

Expand Down Expand Up @@ -431,9 +423,7 @@ func TestAssignerPreferred(t *testing.T) {
t.Fatal("timed out waiting for assignment")
}
}
if !timeout.Stop() {
<-timeout.C
}
timeout.Stop()
require.Equal(t, 1, len(assigns))
require.Equal(t, 1, assigns[0], "expected assignment to indexer 1")

Expand Down Expand Up @@ -466,9 +456,7 @@ func TestAssignerPreferred(t *testing.T) {
t.Fatal("timed out waiting for assignment")
}
}
if !timeout.Stop() {
<-timeout.C
}
timeout.Stop()
require.Equal(t, 1, len(assigns))
require.Equal(t, 1, assigns[0], "expected assignment to indexer 1")

Expand Down Expand Up @@ -743,9 +731,7 @@ func TestFreezeHandoff(t *testing.T) {
t.Fatal("timed out waiting for assignment")
}
}
if !timeout.Stop() {
<-timeout.C
}
timeout.Stop()
require.Equal(t, 1, len(assigns))
require.Equal(t, 0, assigns[0])

Expand All @@ -771,9 +757,6 @@ func TestFreezeHandoff(t *testing.T) {
t.Fatal("timed out waiting for handoff")
}
}
if !timeout.Stop() {
<-timeout.C
}

timeout.Reset(time.Second)
select {
Expand Down
4 changes: 1 addition & 3 deletions internal/registry/registry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -410,9 +410,7 @@ func TestPollProvider(t *testing.T) {
case <-timeout.C:
t.Fatal("Expected sync channel to be written")
}
if !timeout.Stop() {
<-timeout.C
}
timeout.Stop()

// Check that registry is not blocked by unread auto-sync channel.
poll.retryAfter = 0
Expand Down

0 comments on commit 8df363e

Please sign in to comment.