Skip to content

Commit

Permalink
Fix race conditions
Browse files Browse the repository at this point in the history
  • Loading branch information
Maelkum committed Sep 12, 2023
1 parent 9047858 commit 8fa6997
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 6 deletions.
4 changes: 2 additions & 2 deletions node/execute_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ This is the end of my program
go func() {
defer nodesWG.Done()

err = head.node.Run(ctx)
err := head.node.Run(ctx)
require.NoError(t, err)

t.Log("head node stopped")
Expand All @@ -113,7 +113,7 @@ This is the end of my program
go func() {
defer nodesWG.Done()

err = worker.node.Run(ctx)
err := worker.node.Run(ctx)
require.NoError(t, err)

t.Log("worker node stopped")
Expand Down
2 changes: 2 additions & 0 deletions node/handlers_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ func TestNode_Handlers(t *testing.T) {
requestID = "dummy-request-id-2"
)

node.rollCall.create(requestID)

// We only want responses with the code `Accepted`.
res := response.RollCall{
Type: blockless.MessageRollCallResponse,
Expand Down
4 changes: 2 additions & 2 deletions node/message_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func TestNode_Messaging(t *testing.T) {
require.Equal(t, rec, received)
})

err = node.send(context.Background(), client.ID(), rec)
err := node.send(context.Background(), client.ID(), rec)
require.NoError(t, err)

wg.Wait()
Expand All @@ -66,7 +66,7 @@ func TestNode_Messaging(t *testing.T) {

// Establish a connection between peers.
clientInfo := hostGetAddrInfo(t, client)
err = node.host.Connect(ctx, *clientInfo)
err := node.host.Connect(ctx, *clientInfo)
require.NoError(t, err)

// Have both client and node subscribe to the same topic.
Expand Down
3 changes: 1 addition & 2 deletions node/queue.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,14 @@ func (q *rollCallQueue) exists(reqID string) bool {
// responses will return a channel that can be used to iterate through all of the responses.
func (q *rollCallQueue) responses(reqID string) <-chan response.RollCall {
q.Lock()
defer q.Unlock()

_, ok := q.m[reqID]
if !ok {
// Technically we shouldn't be here since we already called `create`, but there's also no harm in it.
q.m[reqID] = make(chan response.RollCall, q.size)
}

q.Unlock()

return q.m[reqID]
}

Expand Down

0 comments on commit 8fa6997

Please sign in to comment.