File tree 2 files changed +38
-14
lines changed
topic/topicwriterinternal
2 files changed +38
-14
lines changed Original file line number Diff line number Diff line change @@ -14,7 +14,6 @@ import (
14
14
"testing"
15
15
"time"
16
16
17
- "github.com/jonboulle/clockwork"
18
17
"github.com/stretchr/testify/require"
19
18
"go.uber.org/mock/gomock"
20
19
@@ -428,19 +427,7 @@ func TestWriterImpl_Reconnect(t *testing.T) {
428
427
xtest .TestManyTimesWithName (t , "ReconnectOnErrors" , func (t testing.TB ) {
429
428
ctx := xtest .Context (t )
430
429
431
- clock := clockwork .NewFakeClock ()
432
-
433
- go func () {
434
- for {
435
- if ctx .Err () != nil {
436
- return
437
- }
438
- clock .Advance (time .Second )
439
- time .Sleep (time .Microsecond )
440
- }
441
- }()
442
-
443
- w := newTestWriterStopped (WithClock (clock ), WithTokenUpdateInterval (time .Duration (math .MaxInt64 )))
430
+ w := newTestWriterStopped (WithClock (xtest .FastClock (t )), WithTokenUpdateInterval (time .Duration (math .MaxInt64 )))
444
431
445
432
mc := gomock .NewController (t )
446
433
Original file line number Diff line number Diff line change
1
+ package xtest
2
+
3
+ import (
4
+ "sync/atomic"
5
+ "testing"
6
+ "time"
7
+
8
+ "github.com/jonboulle/clockwork"
9
+ )
10
+
11
+ // FastClock returns fake clock with very fast time speed advanced until end of test
12
+ // the clock stops advance at end of test
13
+ func FastClock (t testing.TB ) clockwork.FakeClock {
14
+ clock := clockwork .NewFakeClock ()
15
+ var needStop atomic.Bool
16
+ clockStopped := make (chan struct {})
17
+
18
+ go func () {
19
+ defer close (clockStopped )
20
+
21
+ for {
22
+ if needStop .Load () {
23
+ return
24
+ }
25
+
26
+ clock .Advance (time .Second )
27
+ time .Sleep (time .Microsecond )
28
+ }
29
+ }()
30
+
31
+ t .Cleanup (func () {
32
+ needStop .Store (true )
33
+ <- clockStopped
34
+ })
35
+
36
+ return clock
37
+ }
You can’t perform that action at this time.
0 commit comments