Skip to content

Commit fb61a7c

Browse files
Merge pull request #96720 from liggitt/throttled-logger
Deflake ThrottledLogger test Kubernetes-commit: 2ea6828ea0803e188a6a7c4a6581f522865ae8f3
2 parents 66db254 + 61471be commit fb61a7c

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

rest/request_test.go

+8-4
Original file line numberDiff line numberDiff line change
@@ -2228,14 +2228,18 @@ func TestRequestPreflightCheck(t *testing.T) {
22282228

22292229
func TestThrottledLogger(t *testing.T) {
22302230
now := time.Now()
2231+
oldClock := globalThrottledLogger.clock
2232+
defer func() {
2233+
globalThrottledLogger.clock = oldClock
2234+
}()
22312235
clock := clock.NewFakeClock(now)
22322236
globalThrottledLogger.clock = clock
22332237

22342238
logMessages := 0
2235-
for i := 0; i < 10000; i++ {
2239+
for i := 0; i < 1000; i++ {
22362240
var wg sync.WaitGroup
2237-
wg.Add(100)
2238-
for j := 0; j < 100; j++ {
2241+
wg.Add(10)
2242+
for j := 0; j < 10; j++ {
22392243
go func() {
22402244
if _, ok := globalThrottledLogger.attemptToLog(); ok {
22412245
logMessages++
@@ -2248,7 +2252,7 @@ func TestThrottledLogger(t *testing.T) {
22482252
clock.SetTime(now)
22492253
}
22502254

2251-
if a, e := logMessages, 1000; a != e {
2255+
if a, e := logMessages, 100; a != e {
22522256
t.Fatalf("expected %v log messages, but got %v", e, a)
22532257
}
22542258
}

0 commit comments

Comments
 (0)