@@ -33,7 +33,7 @@ func TestPeriodicHourly(t *testing.T) {
33
33
34
34
fc := clockwork .NewFakeClock ()
35
35
// TODO: Do not depand or real time (Recorder.Wait) in unit tests.
36
- rg := & fakeRevGetter {testutil .NewRecorderStreamWithWaitTimout (10 * time . Millisecond ), 0 }
36
+ rg := & fakeRevGetter {testutil .NewRecorderStreamWithWaitTimout (0 ), 0 }
37
37
compactable := & fakeCompactable {testutil .NewRecorderStreamWithWaitTimout (10 * time .Millisecond )}
38
38
tb := newPeriodic (zaptest .NewLogger (t ), fc , retentionDuration , rg , compactable )
39
39
@@ -43,8 +43,8 @@ func TestPeriodicHourly(t *testing.T) {
43
43
initialIntervals , intervalsPerPeriod := tb .getRetentions (), 10
44
44
45
45
// compaction doesn't happen til 2 hours elapse
46
- for i := 0 ; i < initialIntervals ; i ++ {
47
- rg . Wait ( 1 )
46
+ for i := 0 ; i < initialIntervals - 1 ; i ++ {
47
+ waitOneAction ( t , rg )
48
48
fc .Advance (tb .getRetryInterval ())
49
49
}
50
50
@@ -63,7 +63,7 @@ func TestPeriodicHourly(t *testing.T) {
63
63
for i := 0 ; i < 3 ; i ++ {
64
64
// advance one hour, one revision for each interval
65
65
for j := 0 ; j < intervalsPerPeriod ; j ++ {
66
- rg . Wait ( 1 )
66
+ waitOneAction ( t , rg )
67
67
fc .Advance (tb .getRetryInterval ())
68
68
}
69
69
@@ -84,7 +84,7 @@ func TestPeriodicMinutes(t *testing.T) {
84
84
retentionDuration := time .Duration (retentionMinutes ) * time .Minute
85
85
86
86
fc := clockwork .NewFakeClock ()
87
- rg := & fakeRevGetter {testutil .NewRecorderStreamWithWaitTimout (10 * time . Millisecond ), 0 }
87
+ rg := & fakeRevGetter {testutil .NewRecorderStreamWithWaitTimout (0 ), 0 }
88
88
compactable := & fakeCompactable {testutil .NewRecorderStreamWithWaitTimout (10 * time .Millisecond )}
89
89
tb := newPeriodic (zaptest .NewLogger (t ), fc , retentionDuration , rg , compactable )
90
90
@@ -94,8 +94,8 @@ func TestPeriodicMinutes(t *testing.T) {
94
94
initialIntervals , intervalsPerPeriod := tb .getRetentions (), 10
95
95
96
96
// compaction doesn't happen til 5 minutes elapse
97
- for i := 0 ; i < initialIntervals ; i ++ {
98
- rg . Wait ( 1 )
97
+ for i := 0 ; i < initialIntervals - 1 ; i ++ {
98
+ waitOneAction ( t , rg )
99
99
fc .Advance (tb .getRetryInterval ())
100
100
}
101
101
@@ -113,7 +113,7 @@ func TestPeriodicMinutes(t *testing.T) {
113
113
for i := 0 ; i < 5 ; i ++ {
114
114
// advance 5-minute, one revision for each interval
115
115
for j := 0 ; j < intervalsPerPeriod ; j ++ {
116
- rg . Wait ( 1 )
116
+ waitOneAction ( t , rg )
117
117
fc .Advance (tb .getRetryInterval ())
118
118
}
119
119
@@ -132,7 +132,7 @@ func TestPeriodicMinutes(t *testing.T) {
132
132
func TestPeriodicPause (t * testing.T ) {
133
133
fc := clockwork .NewFakeClock ()
134
134
retentionDuration := time .Hour
135
- rg := & fakeRevGetter {testutil .NewRecorderStreamWithWaitTimout (10 * time . Millisecond ), 0 }
135
+ rg := & fakeRevGetter {testutil .NewRecorderStreamWithWaitTimout (0 ), 0 }
136
136
compactable := & fakeCompactable {testutil .NewRecorderStreamWithWaitTimout (10 * time .Millisecond )}
137
137
tb := newPeriodic (zaptest .NewLogger (t ), fc , retentionDuration , rg , compactable )
138
138
@@ -143,7 +143,7 @@ func TestPeriodicPause(t *testing.T) {
143
143
144
144
// tb will collect 3 hours of revisions but not compact since paused
145
145
for i := 0 ; i < n * 3 ; i ++ {
146
- rg . Wait ( 1 )
146
+ waitOneAction ( t , rg )
147
147
fc .Advance (tb .getRetryInterval ())
148
148
}
149
149
// t.revs = [21 22 23 24 25 26 27 28 29 30]
@@ -156,7 +156,7 @@ func TestPeriodicPause(t *testing.T) {
156
156
157
157
// tb resumes to being blocked on the clock
158
158
tb .Resume ()
159
- rg . Wait ( 1 )
159
+ waitOneAction ( t , rg )
160
160
161
161
// unblock clock, will kick off a compaction at T=3h6m by retry
162
162
fc .Advance (tb .getRetryInterval ())
@@ -179,7 +179,7 @@ func TestPeriodicSkipRevNotChange(t *testing.T) {
179
179
retentionDuration := time .Duration (retentionMinutes ) * time .Minute
180
180
181
181
fc := clockwork .NewFakeClock ()
182
- rg := & fakeRevGetter {testutil .NewRecorderStreamWithWaitTimout (10 * time . Millisecond ), 0 }
182
+ rg := & fakeRevGetter {testutil .NewRecorderStreamWithWaitTimout (0 ), 0 }
183
183
compactable := & fakeCompactable {testutil .NewRecorderStreamWithWaitTimout (10 * time .Millisecond )}
184
184
tb := newPeriodic (zaptest .NewLogger (t ), fc , retentionDuration , rg , compactable )
185
185
@@ -189,10 +189,10 @@ func TestPeriodicSkipRevNotChange(t *testing.T) {
189
189
initialIntervals , intervalsPerPeriod := tb .getRetentions (), 10
190
190
191
191
// first compaction happens til 5 minutes elapsed
192
- for i := 0 ; i < initialIntervals ; i ++ {
192
+ for i := 0 ; i < initialIntervals - 1 ; i ++ {
193
193
// every time set the same revision with 100
194
194
rg .SetRev (int64 (100 ))
195
- rg . Wait ( 1 )
195
+ waitOneAction ( t , rg )
196
196
fc .Advance (tb .getRetryInterval ())
197
197
}
198
198
@@ -212,7 +212,7 @@ func TestPeriodicSkipRevNotChange(t *testing.T) {
212
212
for i := 0 ; i < 5 ; i ++ {
213
213
for j := 0 ; j < intervalsPerPeriod ; j ++ {
214
214
rg .SetRev (int64 (100 ))
215
- rg . Wait ( 1 )
215
+ waitOneAction ( t , rg )
216
216
fc .Advance (tb .getRetryInterval ())
217
217
}
218
218
@@ -224,7 +224,7 @@ func TestPeriodicSkipRevNotChange(t *testing.T) {
224
224
225
225
// when revision changed, compaction is normally
226
226
for i := 0 ; i < initialIntervals ; i ++ {
227
- rg . Wait ( 1 )
227
+ waitOneAction ( t , rg )
228
228
fc .Advance (tb .getRetryInterval ())
229
229
}
230
230
@@ -238,3 +238,9 @@ func TestPeriodicSkipRevNotChange(t *testing.T) {
238
238
t .Errorf ("compact request = %v, want %v" , a [0 ].Params [0 ], & pb.CompactionRequest {Revision : expectedRevision })
239
239
}
240
240
}
241
+
242
+ func waitOneAction (t * testing.T , r testutil.Recorder ) {
243
+ if actions , _ := r .Wait (1 ); len (actions ) != 1 {
244
+ t .Errorf ("expect 1 action, got %v instead" , len (actions ))
245
+ }
246
+ }
0 commit comments