Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 4 additions & 0 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -681,6 +681,10 @@ func (c *Client[TTx]) signalStopComplete(ctx context.Context) {
// There's no need to call this method if a hard stop has already been initiated
// by cancelling the context passed to Start or by calling StopAndCancel.
func (c *Client[TTx]) Stop(ctx context.Context) error {
if c.fetchNewWorkCancel == nil {
return errors.New("client not started")
}

c.baseService.Logger.InfoContext(ctx, c.baseService.Name+": Stop started")
c.fetchNewWorkCancel()
return c.awaitStop(ctx)
Expand Down
9 changes: 9 additions & 0 deletions client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,15 @@ func Test_Client_Stop(t *testing.T) {
}
}

t.Run("not started", func(t *testing.T) {
t.Parallel()
client := newTestClient(ctx, t, newTestConfig(t, nil))

err := client.Stop(ctx)
require.Error(t, err)
require.Equal(t, "client not started", err.Error())
})

t.Run("no jobs in progress", func(t *testing.T) {
t.Parallel()
client := runNewTestClient(ctx, t, newTestConfig(t, nil))
Expand Down