Skip to content

Commit

Permalink
tests(coordinator): Improve unit test coverage (#98)
Browse files Browse the repository at this point in the history
* tests(coordinator): Improve unit test coverage

Signed-off-by: Flc゛ <[email protected]>

* tests(coordinator): Improve unit test coverage

Signed-off-by: Flc゛ <[email protected]>

---------

Signed-off-by: Flc゛ <[email protected]>
  • Loading branch information
flc1125 authored Feb 15, 2024
1 parent 26a6f6b commit c57bd61
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
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
28 changes: 27 additions & 1 deletion coordinator/manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (

func TestManager(t *testing.T) {
wg := sync.WaitGroup{}
ch := make(chan struct{}, 2)
ch := make(chan struct{}, 10)

c1 := Until("foo")
c2 := Until("foo")
Expand Down 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 c57bd61

Please sign in to comment.