@@ -209,9 +209,30 @@ func TestDataSourceStatusProviderV2(t *testing.T) {
209
209
210
210
t .Run ("waitFor detects correct status" , func (t * testing.T ) {
211
211
clientListenersV2Test (func (p clientListenersV2TestParams ) {
212
- p .client .GetDataSourceStatusProvider ().WaitFor (interfaces .DataSourceStateValid , time .Second )
212
+ // Can wait for the valid state
213
+ foundIt := p .client .GetDataSourceStatusProvider ().WaitFor (interfaces .DataSourceStateValid , time .Second )
214
+ assert .True (t , foundIt )
215
+
216
+ // Negative timeouts fire immediately
217
+ start := time .Now ()
218
+ foundIt = p .client .GetDataSourceStatusProvider ().WaitFor (interfaces .DataSourceStateInterrupted , time .Second * - 1 )
219
+ assert .WithinDuration (t , time .Now (), start , time .Millisecond * 30 )
220
+ assert .False (t , foundIt )
221
+
222
+ // Make sure timeout will occur when a state cannot be found
223
+ foundIt = p .client .GetDataSourceStatusProvider ().WaitFor (interfaces .DataSourceStateInterrupted , time .Second )
224
+ assert .False (t , foundIt )
225
+
226
+ // Shut it down and make sure it's stopped.
213
227
p .control .Close ()
214
- p .client .GetDataSourceStatusProvider ().WaitFor (interfaces .DataSourceStateOff , time .Second )
228
+ foundIt = p .client .GetDataSourceStatusProvider ().WaitFor (interfaces .DataSourceStateOff , time .Second )
229
+ assert .True (t , foundIt )
230
+
231
+ // Ensure that an off status doesn't require the use of a timer.
232
+ start = time .Now ()
233
+ foundIt = p .client .GetDataSourceStatusProvider ().WaitFor (interfaces .DataSourceStateValid , time .Hour * 100 )
234
+ assert .WithinDuration (t , time .Now (), start , time .Millisecond * 30 )
235
+ assert .False (t , foundIt )
215
236
}, httphelpers .HandlerWithStatus (401 ))
216
237
})
217
238
}
0 commit comments