Skip to content

Commit

Permalink
Deflake ThrottledLogger test
Browse files Browse the repository at this point in the history
Kubernetes-commit: c84df5d66ea8d949374b67c5205b9869b984ea84
  • Loading branch information
liggitt authored and k8s-publishing-bot committed Nov 19, 2020
1 parent 66db254 commit 61471be
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions rest/request_test.go
Expand Up @@ -2228,14 +2228,18 @@ func TestRequestPreflightCheck(t *testing.T) {

func TestThrottledLogger(t *testing.T) {
now := time.Now()
oldClock := globalThrottledLogger.clock
defer func() {
globalThrottledLogger.clock = oldClock
}()
clock := clock.NewFakeClock(now)
globalThrottledLogger.clock = clock

logMessages := 0
for i := 0; i < 10000; i++ {
for i := 0; i < 1000; i++ {
var wg sync.WaitGroup
wg.Add(100)
for j := 0; j < 100; j++ {
wg.Add(10)
for j := 0; j < 10; j++ {
go func() {
if _, ok := globalThrottledLogger.attemptToLog(); ok {
logMessages++
Expand All @@ -2248,7 +2252,7 @@ func TestThrottledLogger(t *testing.T) {
clock.SetTime(now)
}

if a, e := logMessages, 1000; a != e {
if a, e := logMessages, 100; a != e {
t.Fatalf("expected %v log messages, but got %v", e, a)
}
}
Expand Down

0 comments on commit 61471be

Please sign in to comment.