Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions internal/client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -345,17 +345,15 @@ func TestConcurrentStartOneDaemon(t *testing.T) {
resps := make([]proto.Response, n)
errs := make([]error, n)
var wg sync.WaitGroup
for i := 0; i < n; i++ {
wg.Add(1)
go func() {
defer wg.Done()
for i := range n {
wg.Go(func() {
resps[i], errs[i] = Do(proto.Request{Op: proto.OpNote}, o)
}()
})
}
wg.Wait()
t.Cleanup(func() { stopDaemons(t, home, resps[0].Context, resps[1].Context) })

for i := 0; i < n; i++ {
for i := range n {
if errs[i] != nil || !resps[i].OK {
t.Fatalf("Do(note) call %d = %+v, %v, want OK and nil error", i, resps[i], errs[i])
}
Expand Down
21 changes: 8 additions & 13 deletions internal/core/state_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import (
"time"
"unicode/utf8"

"github.com/bytedance/gg/gslice"

"github.com/ChristopherLiew/agent-quorum/internal/guard"
"github.com/ChristopherLiew/agent-quorum/internal/proto"
)
Expand Down Expand Up @@ -231,22 +233,15 @@ func TestPathsAreCleaned(t *testing.T) {
func TestConcurrentClaimsOneGrant(t *testing.T) {
env := newEnv()
s := newState(env)
resps := make([]proto.Response, 100)
var wg sync.WaitGroup
var mu sync.Mutex
grants := 0
for i := 0; i < 100; i++ {
wg.Add(1)
go func(i int) {
defer wg.Done()
resp := s.Handle(rq(proto.OpClaim, fmt.Sprintf("s%d", i), 1000+i, "/repo/hot.go"))
if resp.OK && resp.Decision == proto.Grant {
mu.Lock()
grants++
mu.Unlock()
}
}(i)
for i := range resps {
wg.Go(func() {
resps[i] = s.Handle(rq(proto.OpClaim, fmt.Sprintf("s%d", i), 1000+i, "/repo/hot.go"))
})
}
wg.Wait()
grants := gslice.CountBy(resps, func(r proto.Response) bool { return r.OK && r.Decision == proto.Grant })
if grants != 1 {
t.Fatalf("grants = %d, want 1", grants)
}
Expand Down
6 changes: 1 addition & 5 deletions internal/daemon/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,11 +155,7 @@ func Serve(ctx context.Context, o Options) error {
}
continue
}
wg.Add(1)
go func() {
defer wg.Done()
s.serveConn(conn)
}()
wg.Go(func() { s.serveConn(conn) })
}

drained := make(chan struct{})
Expand Down
Loading