@@ -597,7 +597,8 @@ func TestProvisionerd(t *testing.T) {
597
597
assert .True (t , didFail .Load (), "should fail the job" )
598
598
})
599
599
600
- // When there is no coderd, the connect loop will never succeed.
600
+ // Simulates when there is no coderd to connect to. So the client connection
601
+ // will never be established.
601
602
t .Run ("ShutdownNoCoderd" , func (t * testing.T ) {
602
603
t .Parallel ()
603
604
done := make (chan struct {})
@@ -608,36 +609,23 @@ func TestProvisionerd(t *testing.T) {
608
609
connectAttemptedClose := sync.Once {}
609
610
connectAttempted := make (chan struct {})
610
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.
611
613
connectAttemptedClose .Do (func () { close (connectAttempted ) })
612
614
return nil , fmt .Errorf ("client connection always fails" )
613
615
}, provisionerd.LocalProvisioners {
614
- "someprovisioner" : createProvisionerClient (t , done , provisionerTestServer {
615
- plan : func (
616
- s * provisionersdk.Session ,
617
- _ * sdkproto.PlanRequest ,
618
- canceledOrComplete <- chan struct {},
619
- ) * sdkproto.PlanComplete {
620
- s .ProvisionLog (sdkproto .LogLevel_DEBUG , "in progress" )
621
- <- canceledOrComplete
622
- return & sdkproto.PlanComplete {
623
- Error : "some error" ,
624
- }
625
- },
626
- apply : func (
627
- _ * provisionersdk.Session ,
628
- _ * sdkproto.ApplyRequest ,
629
- _ <- chan struct {},
630
- ) * sdkproto.ApplyComplete {
631
- t .Error ("should never apply" )
632
- return & sdkproto.ApplyComplete {}
633
- },
634
- }),
616
+ "someprovisioner" : createProvisionerClient (t , done , provisionerTestServer {}),
635
617
})
636
618
637
- // At least 1 attempt to connect
619
+ // Wait for at least 1 attempt to connect to ensure the connect go routine
620
+ // is running.
638
621
require .Condition (t , closedWithin (connectAttempted , testutil .WaitShort ))
639
- err := server .Shutdown (context .Background (), true )
640
- require .NoError (t , err )
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." )
641
629
require .NoError (t , server .Close ())
642
630
})
643
631
0 commit comments