Skip to content

Commit 418c4dd

Browse files
committed
cleanup test
1 parent 52b0e83 commit 418c4dd

File tree

1 file changed

+13
-25
lines changed

1 file changed

+13
-25
lines changed

provisionerd/provisionerd_test.go

Lines changed: 13 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -597,7 +597,8 @@ func TestProvisionerd(t *testing.T) {
597597
assert.True(t, didFail.Load(), "should fail the job")
598598
})
599599

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.
601602
t.Run("ShutdownNoCoderd", func(t *testing.T) {
602603
t.Parallel()
603604
done := make(chan struct{})
@@ -608,36 +609,23 @@ func TestProvisionerd(t *testing.T) {
608609
connectAttemptedClose := sync.Once{}
609610
connectAttempted := make(chan struct{})
610611
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.
611613
connectAttemptedClose.Do(func() { close(connectAttempted) })
612614
return nil, fmt.Errorf("client connection always fails")
613615
}, 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{}),
635617
})
636618

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.
638621
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.")
641629
require.NoError(t, server.Close())
642630
})
643631

0 commit comments

Comments
 (0)