Skip to content

Commit 8f75d4f

Browse files
authored
fix(test): fix minor race in tests (#314)
Super minor fixes for a race that exists in tests only
1 parent 9e71225 commit 8f75d4f

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

headertest/dummy_header.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"encoding/json"
77
"errors"
88
"math"
9+
"sync"
910
"testing"
1011
"time"
1112

@@ -22,7 +23,8 @@ type DummyHeader struct {
2223
HeightI uint64
2324
Timestamp time.Time
2425

25-
hash header.Hash
26+
hashMu sync.Mutex
27+
hash header.Hash
2628

2729
// VerifyFailure allows for testing scenarios where a header would fail
2830
// verification. When set to true, it forces a failure.
@@ -63,6 +65,8 @@ func (d *DummyHeader) ChainID() string {
6365
}
6466

6567
func (d *DummyHeader) Hash() header.Hash {
68+
d.hashMu.Lock()
69+
defer d.hashMu.Unlock()
6670
if len(d.hash) == 0 {
6771
if err := d.rehash(); err != nil {
6872
panic(err)

store/store_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,7 @@ func TestStoreGetByHeight_whenGaps(t *testing.T) {
387387

388388
head, err := store.GetByHeight(ctx, wantLastHead.Height())
389389
require.NoError(t, err)
390-
require.Equal(t, head, wantLastHead)
390+
require.Equal(t, head.Hash(), wantLastHead.Hash())
391391
default:
392392
t.Fatal("store.GetByHeight on last height MUST NOT be blocked")
393393
}

0 commit comments

Comments
 (0)