Skip to content

Commit

Permalink
Input operator should stop without errors even if start was not calle…
Browse files Browse the repository at this point in the history
…d or failed
  • Loading branch information
pjanotti committed Nov 7, 2024
1 parent cd2970a commit 1d7b73f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
9 changes: 9 additions & 0 deletions pkg/stanza/operator/input/windows/input.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,16 @@ func (i *Input) Start(persister operator.Persister) error {

// Stop will stop reading events from a subscription.
func (i *Input) Stop() error {
if i.cancel == nil {
// Nothing to do: either already stopped or never started.
return nil
}

i.cancel()
i.cancel = nil

// Warning: all calls made below must be safe to be done even if Start() was not called or failed.

i.wg.Wait()

if err := i.subscription.Close(); err != nil {
Expand Down
6 changes: 6 additions & 0 deletions pkg/stanza/operator/input/windows/input_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ func newTestInput() *Input {
})
}

// TestInputCreate_Stop ensures the input correctly shuts down even if it was never started.
func TestInputCreate_Stop(t *testing.T) {
input := newTestInput()
assert.NoError(t, input.Stop())
}

// TestInputStart_LocalSubscriptionError ensures the input correctly handles local subscription errors.
func TestInputStart_LocalSubscriptionError(t *testing.T) {
persister := testutil.NewMockPersister("")
Expand Down

0 comments on commit 1d7b73f

Please sign in to comment.