@@ -416,6 +416,57 @@ func TestServer_Stop(t *testing.T) {
416
416
assert .NoError (t , stopErr )
417
417
}
418
418
419
+ func TestServer_StopJustDisconnect (t * testing.T ) {
420
+ initConfig := "initial_config"
421
+ app := & StubApp {}
422
+ srv := createAndStartServer (t , & StubHandler {})
423
+ defer srv .Stop ()
424
+ as , err := srv .Register (app , initConfig )
425
+ require .NoError (t , err )
426
+ cImpl := & StubClientImpl {}
427
+ c := newClientFromApplicationState (t , as , cImpl )
428
+ require .NoError (t , c .Start (context .Background ()))
429
+ defer c .Stop ()
430
+
431
+ // clients should get initial check-ins then set as healthy
432
+ require .NoError (t , waitFor (func () error {
433
+ if cImpl .Config () != initConfig {
434
+ return fmt .Errorf ("client never got intial config" )
435
+ }
436
+ return nil
437
+ }))
438
+ c .Status (proto .StateObserved_HEALTHY , "Running" , nil )
439
+ assert .NoError (t , waitFor (func () error {
440
+ if app .Status () != proto .StateObserved_HEALTHY {
441
+ return fmt .Errorf ("server never updated currect application state" )
442
+ }
443
+ return nil
444
+ }))
445
+
446
+ // send stop to the client
447
+ done := make (chan bool )
448
+ var stopErr error
449
+ go func () {
450
+ stopErr = as .Stop (time .Second * 5 )
451
+ close (done )
452
+ }()
453
+
454
+ // process of testing the flow
455
+ // 1. server sends stop
456
+ // 2. client disconnects
457
+ require .NoError (t , waitFor (func () error {
458
+ if cImpl .Stop () == 0 {
459
+ return fmt .Errorf ("client never got expected stop" )
460
+ }
461
+ return nil
462
+ }))
463
+ c .Stop ()
464
+ <- done
465
+
466
+ // no error on stop
467
+ assert .NoError (t , stopErr )
468
+ }
469
+
419
470
func TestServer_StopTimeout (t * testing.T ) {
420
471
initConfig := "initial_config"
421
472
app := & StubApp {}
0 commit comments