@@ -84,7 +84,7 @@ func TestAfterFunc_NegativeDuration(t *testing.T) {
84
84
func TestNewTicker (t * testing.T ) {
85
85
t .Parallel ()
86
86
// nolint:gocritic // trying to avoid Coder-specific stuff with an eye toward spinning this out
87
- ctx , cancel := context .WithTimeout (context .Background (), 1000 * time .Second )
87
+ ctx , cancel := context .WithTimeout (context .Background (), 10 * time .Second )
88
88
defer cancel ()
89
89
90
90
mClock := clock .NewMock (t )
@@ -167,3 +167,50 @@ func TestNewTicker(t *testing.T) {
167
167
}
168
168
}
169
169
}
170
+
171
+ func TestNext (t * testing.T ) {
172
+ t .Parallel ()
173
+ // nolint:gocritic // trying to avoid Coder-specific stuff with an eye toward spinning this out
174
+ ctx , cancel := context .WithTimeout (context .Background (), 10 * time .Second )
175
+ defer cancel ()
176
+
177
+ mClock := clock .NewMock (t )
178
+ d , ok := mClock .Next ()
179
+ if d != 0 {
180
+ t .Fatal ("expected Next() to return 0" )
181
+ }
182
+ if ok {
183
+ t .Fatal ("expected Next() to return false" )
184
+ }
185
+
186
+ tmr := mClock .NewTimer (time .Second )
187
+ d , ok = mClock .Next ()
188
+ if d != time .Second {
189
+ t .Fatal ("expected Next() to return 1s" )
190
+ }
191
+ if ! ok {
192
+ t .Fatal ("expected Next() to return true" )
193
+ }
194
+
195
+ mClock .Advance (999 * time .Millisecond ).MustWait (ctx )
196
+ d , ok = mClock .Next ()
197
+ if d != time .Millisecond {
198
+ t .Fatal ("expected Next() to return 1ms" )
199
+ }
200
+ if ! ok {
201
+ t .Fatal ("expected Next() to return true" )
202
+ }
203
+
204
+ stopped := tmr .Stop ()
205
+ if ! stopped {
206
+ t .Fatal ("expected Stop() to return true" )
207
+ }
208
+
209
+ d , ok = mClock .Next ()
210
+ if d != 0 {
211
+ t .Fatal ("expected Next() to return 0" )
212
+ }
213
+ if ok {
214
+ t .Fatal ("expected Next() to return false" )
215
+ }
216
+ }
0 commit comments