@@ -597,6 +597,38 @@ func TestProvisionerd(t *testing.T) {
597
597
assert .True (t , didFail .Load (), "should fail the job" )
598
598
})
599
599
600
+ // Simulates when there is no coderd to connect to. So the client connection
601
+ // will never be established.
602
+ t .Run ("ShutdownNoCoderd" , func (t * testing.T ) {
603
+ t .Parallel ()
604
+ done := make (chan struct {})
605
+ t .Cleanup (func () {
606
+ close (done )
607
+ })
608
+
609
+ connectAttemptedClose := sync.Once {}
610
+ connectAttempted := make (chan struct {})
611
+ server := createProvisionerd (t , func (ctx context.Context ) (proto.DRPCProvisionerDaemonClient , error ) {
612
+ // This is the dial out to Coderd, which in this unit test will always fail.
613
+ connectAttemptedClose .Do (func () { close (connectAttempted ) })
614
+ return nil , fmt .Errorf ("client connection always fails" )
615
+ }, provisionerd.LocalProvisioners {
616
+ "someprovisioner" : createProvisionerClient (t , done , provisionerTestServer {}),
617
+ })
618
+
619
+ // Wait for at least 1 attempt to connect to ensure the connect go routine
620
+ // is running.
621
+ require .Condition (t , closedWithin (connectAttempted , testutil .WaitShort ))
622
+
623
+ // The test is ensuring this Shutdown call does not block indefinitely.
624
+ // If it does, the context will return with an error, and the test will
625
+ // fail.
626
+ shutdownCtx := testutil .Context (t , testutil .WaitShort )
627
+ err := server .Shutdown (shutdownCtx , true )
628
+ require .NoError (t , err , "shutdown did not unblock. Failed to close the server gracefully." )
629
+ require .NoError (t , server .Close ())
630
+ })
631
+
600
632
t .Run ("Shutdown" , func (t * testing.T ) {
601
633
t .Parallel ()
602
634
done := make (chan struct {})
0 commit comments