Skip to content

Commit

Permalink
Merge pull request #96720 from liggitt/throttled-logger
Browse files Browse the repository at this point in the history
Deflake ThrottledLogger test

Kubernetes-commit: 2ea6828ea0803e188a6a7c4a6581f522865ae8f3
  • Loading branch information
k8s-publishing-bot committed Nov 21, 2020
2 parents 66db254 + 61471be commit fb61a7c
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions rest/request_test.go
Original file line number Diff line number Diff line change
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 fb61a7c

Please sign in to comment.