Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resolve data races in tests utilizing go routines #29

Merged
merged 6 commits into from
Oct 14, 2022
Merged
Show file tree
Hide file tree
Changes from 4 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
15 changes: 15 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,18 @@ jobs:
uses: codecov/codecov-action@v3
with:
files: coverage.out
test-race:
runs-on: ubuntu-latest
steps:
- name: Install Go
uses: actions/setup-go@v3
with:
go-version: 1.18.x

- name: Checkout code
uses: actions/checkout@v3
with:
submodules: recursive

- name: Go race test
run: go test -race -shuffle=on -timeout 28m ./...
zivkovicmilos marked this conversation as resolved.
Show resolved Hide resolved
zivkovicmilos marked this conversation as resolved.
Show resolved Hide resolved
15 changes: 15 additions & 0 deletions core/ibft_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -948,6 +948,8 @@ func TestRunCommit(t *testing.T) {
t.Parallel()

var (
wg sync.WaitGroup

proposal = []byte("block proposal")
proposalHash = []byte("proposal hash")
signer = []byte("signer")
Expand Down Expand Up @@ -1023,9 +1025,12 @@ func TestRunCommit(t *testing.T) {

ctx, cancelFn := context.WithCancel(context.Background())

wg.Add(1)

go func(i *IBFT) {
defer func() {
cancelFn()
wg.Done()
}()

select {
Expand Down Expand Up @@ -1054,6 +1059,7 @@ func TestRunCommit(t *testing.T) {
assert.Equal(t, insertedCommittedSeals, committedSeals)

// Make sure the proper done channel was notified
wg.Wait()
assert.True(t, doneReceived)
},
)
Expand Down Expand Up @@ -2089,6 +2095,8 @@ func TestIBFT_WatchForFutureRCC(t *testing.T) {
setRoundForMessages(roundChangeMessages, rccRound)

var (
wg sync.WaitGroup

receivedRound = uint64(0)
notifyCh = make(chan uint64, 1)

Expand Down Expand Up @@ -2128,8 +2136,14 @@ func TestIBFT_WatchForFutureRCC(t *testing.T) {
ctx, cancelFn := context.WithCancel(context.Background())
defer cancelFn()

wg.Add(1)

go func() {
defer cancelFn()
defer func() {
cancelFn()
JekaMas marked this conversation as resolved.
Show resolved Hide resolved
wg.Done()
}()

select {
case r := <-i.roundCertificate:
Expand All @@ -2146,6 +2160,7 @@ func TestIBFT_WatchForFutureRCC(t *testing.T) {
i.wg.Wait()

// Make sure the notification round was correct
wg.Wait()
assert.Equal(t, rccRound, receivedRound)
}

Expand Down
2 changes: 1 addition & 1 deletion core/mock_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ func (wg *mockNodeWg) getDone() int64 {
}

func (wg *mockNodeWg) resetDone() {
wg.count = 0
atomic.StoreInt64(&wg.count, 0)
zivkovicmilos marked this conversation as resolved.
Show resolved Hide resolved
}

// mockCluster represents a mock IBFT cluster
Expand Down