Skip to content

Commit

Permalink
Allow stopping app after Stop() has been called (#1019)
Browse files Browse the repository at this point in the history
Starting from 1.19, calling Stop() when an app has been stopped returns
an error.

This actually is an unexpected change for many users who have been using
fxtest for testing their apps. Specifically, if they have a server that
errors out when tests are written, these will often trigger Stop() to be
called many times..
  • Loading branch information
sywhang committed Jan 9, 2023
1 parent f0d73c6 commit 91e752c
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 11 deletions.
2 changes: 1 addition & 1 deletion internal/lifecycle/lifecycle.go
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ func (l *Lifecycle) Stop(ctx context.Context) error {
l.mu.Lock()
if l.state != started && l.state != incompleteStart {
defer l.mu.Unlock()
return fmt.Errorf("attempted to stop lifecycle when in state: %v", l.state)
return nil
}
l.state = stopping
l.mu.Unlock()
Expand Down
10 changes: 0 additions & 10 deletions internal/lifecycle/lifecycle_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -331,16 +331,6 @@ func TestLifecycleStop(t *testing.T) {
assert.Contains(t, err.Error(), "called OnStop with nil context")

})

t.Run("StopWhileStoppedErrors", func(t *testing.T) {
t.Parallel()

l := New(testLogger(t), fxclock.System)
err := l.Stop(context.Background())
require.Error(t, err)
assert.Contains(t, err.Error(), "attempted to stop lifecycle when in state: stopped")
})

}

func TestHookRecordsFormat(t *testing.T) {
Expand Down

0 comments on commit 91e752c

Please sign in to comment.