Skip to content

Commit

Permalink
tests(coordinator): Improve unit test coverage
Browse files Browse the repository at this point in the history
Signed-off-by: Flc゛ <[email protected]>
  • Loading branch information
flc1125 committed Feb 15, 2024
1 parent 26a6f6b commit b26de1d
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
2 changes: 1 addition & 1 deletion coordinator/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import "sync"

type Manager struct {
coordinators map[string]*Coordinator
mu sync.RWMutex
mu sync.Mutex
}

func NewManager() *Manager {
Expand Down
26 changes: 26 additions & 0 deletions coordinator/manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,30 @@ func TestManager(t *testing.T) {

wg.Wait()
assert.Equal(t, 2, len(ch))

// Clear all coordinators
Clear()

c3 := Until("foo")
assert.NotSame(t, c1, c3)

// Close foo coordinators
wg.Add(1)
go func() {
defer wg.Done()

if <-c3.Done(); true {
ch <- struct{}{}
return
}
}()
assert.Equal(t, 2, len(ch))
Close("foo")
wg.Wait()
assert.Equal(t, 3, len(ch))

// Close non-exist coordinator
assert.NotPanics(t, func() {
Close("bar")
})
}

0 comments on commit b26de1d

Please sign in to comment.