Skip to content

chore: shutdown provisioner should stop waiting on client #13118

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 3, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
cleanup test
  • Loading branch information
Emyrk committed May 2, 2024
commit 418c4ddfc8c458c923a5d0495adb54aa5ea1b090
38 changes: 13 additions & 25 deletions provisionerd/provisionerd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -597,7 +597,8 @@ func TestProvisionerd(t *testing.T) {
assert.True(t, didFail.Load(), "should fail the job")
})

// When there is no coderd, the connect loop will never succeed.
// Simulates when there is no coderd to connect to. So the client connection
// will never be established.
t.Run("ShutdownNoCoderd", func(t *testing.T) {
t.Parallel()
done := make(chan struct{})
Expand All @@ -608,36 +609,23 @@ func TestProvisionerd(t *testing.T) {
connectAttemptedClose := sync.Once{}
connectAttempted := make(chan struct{})
server := createProvisionerd(t, func(ctx context.Context) (proto.DRPCProvisionerDaemonClient, error) {
// This is the dial out to Coderd, which in this unit test will always fail.
connectAttemptedClose.Do(func() { close(connectAttempted) })
return nil, fmt.Errorf("client connection always fails")
}, provisionerd.LocalProvisioners{
"someprovisioner": createProvisionerClient(t, done, provisionerTestServer{
plan: func(
s *provisionersdk.Session,
_ *sdkproto.PlanRequest,
canceledOrComplete <-chan struct{},
) *sdkproto.PlanComplete {
s.ProvisionLog(sdkproto.LogLevel_DEBUG, "in progress")
<-canceledOrComplete
return &sdkproto.PlanComplete{
Error: "some error",
}
},
apply: func(
_ *provisionersdk.Session,
_ *sdkproto.ApplyRequest,
_ <-chan struct{},
) *sdkproto.ApplyComplete {
t.Error("should never apply")
return &sdkproto.ApplyComplete{}
},
}),
"someprovisioner": createProvisionerClient(t, done, provisionerTestServer{}),
})

// At least 1 attempt to connect
// Wait for at least 1 attempt to connect to ensure the connect go routine
// is running.
require.Condition(t, closedWithin(connectAttempted, testutil.WaitShort))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just FYI, we have testutil.RequireRecvCtx() which is what I usually use for this sort of thing.

err := server.Shutdown(context.Background(), true)
require.NoError(t, err)

// The test is ensuring this Shutdown call does not block indefinitely.
// If it does, the context will return with an error, and the test will
// fail.
shutdownCtx := testutil.Context(t, testutil.WaitShort)
err := server.Shutdown(shutdownCtx, true)
require.NoError(t, err, "shutdown did not unblock. Failed to close the server gracefully.")
require.NoError(t, server.Close())
})

Expand Down
Loading