Skip to content

Commit

Permalink
Add Test Shutdown After CleanUp
Browse files Browse the repository at this point in the history
  • Loading branch information
tung.tq committed Oct 17, 2023
1 parent cd1e256 commit 3a3f12c
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
1 change: 1 addition & 0 deletions svloc.go
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,7 @@ func (u *universeData) cloneShutdownFuncList() []func() {
funcList := make([]func(), len(u.shutdownFuncs))
copy(funcList, u.shutdownFuncs)

u.shutdownFuncs = nil
u.alreadyShutdown = true
return funcList
}
Expand Down
20 changes: 20 additions & 0 deletions svloc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -813,4 +813,24 @@ func TestUniverse_CleanUp(t *testing.T) {
})
assert.Equal(t, errors.New("svloc: can NOT call 'Wrap' after 'CleanUp'"), err)
})

t.Run("success shutdown after clean up", func(t *testing.T) {
var shutdowns []string
repoLoc := Register[Repo](func(unv *Universe) Repo {
unv.OnShutdown(func() {
shutdowns = append(shutdowns, "repo")
})
return &UserRepo{}
})

unv := NewUniverse()

repoLoc.Get(unv)

unv.CleanUp()

unv.Shutdown()

assert.Equal(t, []string{"repo"}, shutdowns)
})
}

0 comments on commit 3a3f12c

Please sign in to comment.