Skip to content

Commit

Permalink
Remove require from non main go-routine (#61)
Browse files Browse the repository at this point in the history
A failure in a `require` statement calls `t.FailNow` which was occuring
from the non main go-routine. This is not a correct usage of `require`.
  • Loading branch information
trianglesphere authored Nov 8, 2022
1 parent 61035c5 commit ba6cbca
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions simulators/optimism/p2p/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,22 +165,29 @@ func runP2PTests(t *hivesim.T) {

ctx, cancel := context.WithTimeout(context.Background(), time.Minute)
readyCh := make(chan struct{})
errCh := make(chan error, 20)
t.Log("awaiting initial sync")
go func() {
tick := time.NewTicker(250 * time.Millisecond)
for {
select {
case <-tick.C:
seqHead, err := seqRollupCl.SyncStatus(ctx)
require.NoError(t, err)
if err != nil {
errCh <- err
return
}
if seqHead.UnsafeL2.Number == seqHead.SafeL2.Number {
continue
}
ready := true
for i := 1; i <= replicaCount; i++ {
repRollupCl := d.GetOpNode(i).RollupClient()
repHead, err := repRollupCl.SyncStatus(ctx)
require.NoError(t, err)
if err != nil {
errCh <- err
return
}
if seqHead.UnsafeL2.Number-repHead.UnsafeL2.Number >= 2 {
ready = false
break
Expand All @@ -196,6 +203,9 @@ func runP2PTests(t *hivesim.T) {
}()

select {
case err := <-errCh:
t.Fatalf("Error awaiting for initial sync", "err", err)

case <-readyCh:
cancel()
t.Log("initial sync complete")
Expand All @@ -204,7 +214,7 @@ func runP2PTests(t *hivesim.T) {
}

ctx, cancel = context.WithTimeout(context.Background(), 5*time.Minute)
errCh := make(chan error, 20)
errCh = make(chan error, 20)
defer cancel()

getSyncStat := func(ctx context.Context, i int) *driver.SyncStatus {
Expand Down

0 comments on commit ba6cbca

Please sign in to comment.