diff --git a/client.go b/client.go index fecc8a33..9245e3fd 100644 --- a/client.go +++ b/client.go @@ -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) diff --git a/client_test.go b/client_test.go index 09b05778..733fe6ff 100644 --- a/client_test.go +++ b/client_test.go @@ -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))