Skip to content

Commit f2d6310

Browse files
holisticodezelig
authored andcommitted
p2p/protocols: fix race condition in TestAccountingSimulation (#19228)
p2p/protocols: Fix race condition in TestAccountingSimulation
1 parent ce3ea8c commit f2d6310

1 file changed

Lines changed: 5 additions & 2 deletions

File tree

‎p2p/protocols/accounting_simulation_test.go‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,8 +159,9 @@ func TestAccountingSimulation(t *testing.T) {
159159
// (n entries in the array will not be filled -
160160
// the balance of a node with itself)
161161
type matrix struct {
162-
n int //number of nodes
163-
m []int64 //array of balances
162+
n int //number of nodes
163+
m []int64 //array of balances
164+
lock sync.RWMutex
164165
}
165166

166167
// create a new matrix
@@ -177,7 +178,9 @@ func (m *matrix) add(i, j int, v int64) error {
177178
// i * number of nodes + remote node
178179
mi := i*m.n + j
179180
// register that balance
181+
m.lock.Lock()
180182
m.m[mi] += v
183+
m.lock.Unlock()
181184
return nil
182185
}
183186

0 commit comments

Comments
 (0)