-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add race detector flag to go test command for better concurrency checks. Fixes have been implemented for the race conditions detected in the above tests. Fixed a bug in the slice remove process.
- Loading branch information
1 parent
83603a2
commit d1f6a89
Showing
5 changed files
with
78 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package electrum | ||
|
||
import ( | ||
"context" | ||
"sync" | ||
"testing" | ||
|
||
"github.com/elementsproject/peerswap/swap" | ||
) | ||
|
||
type testtxo struct { | ||
swapid swap.SwapId | ||
} | ||
|
||
func (t *testtxo) GetSwapID() swap.SwapId { | ||
return t.swapid | ||
} | ||
|
||
func (t *testtxo) Callback(context.Context, BlocKHeight) (bool, error) { | ||
return true, nil | ||
} | ||
|
||
func TestConcurrentUpdate(t *testing.T) { | ||
t.Parallel() | ||
observers := make([]TXObserver, 10) | ||
for i := range observers { | ||
observers[i] = &testtxo{ | ||
swapid: *swap.NewSwapId(), | ||
} | ||
} | ||
|
||
h := &liquidBlockHeaderSubscriber{ | ||
txObservers: observers, | ||
} | ||
|
||
var wg sync.WaitGroup | ||
const concurrency = 100 | ||
for i := 0; i < concurrency; i++ { | ||
wg.Add(1) | ||
go func() { | ||
defer wg.Done() | ||
err := h.Update(context.Background(), BlocKHeight(0)) | ||
if err != nil { | ||
t.Errorf("Unexpected error: %v", err) | ||
} | ||
}() | ||
} | ||
wg.Wait() | ||
|
||
if len(h.txObservers) != 0 { | ||
t.Errorf("Expected length %d, but got %d", 0, len(h.txObservers)) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters