Skip to content

Commit

Permalink
util: fix data race in the cpu test (#40154)
Browse files Browse the repository at this point in the history
close #40125
  • Loading branch information
hawkingrei authored Dec 27, 2022
1 parent ab01065 commit 3c8f11d
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
1 change: 1 addition & 0 deletions util/cpu/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,6 @@ go_test(
srcs = ["cpu_test.go"],
embed = [":cpu"],
flaky = True,
race = "on",
deps = ["@com_github_stretchr_testify//require"],
)
7 changes: 3 additions & 4 deletions util/cpu/cpu_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ import (
)

func TestCPUValue(t *testing.T) {
Observer := NewCPUObserver()
Observer.Start()
observer := NewCPUObserver()
exit := make(chan struct{})
var wg sync.WaitGroup
for i := 0; i < 10; i++ {
Expand All @@ -42,11 +41,11 @@ func TestCPUValue(t *testing.T) {
}
}()
}
Observer.Start()
observer.Start()
time.Sleep(5 * time.Second)
require.GreaterOrEqual(t, GetCPUUsage(), 0.0)
require.Less(t, GetCPUUsage(), 1.0)
Observer.Stop()
observer.Stop()
close(exit)
wg.Wait()
}

0 comments on commit 3c8f11d

Please sign in to comment.