Skip to content

Commit

Permalink
Merge pull request #1654 from statechannels/fix-block-num-flicker
Browse files Browse the repository at this point in the history
Fix BlockNum flicker by waiting for block num
  • Loading branch information
bitwiseguy authored Sep 9, 2023
2 parents 757eb06 + c283696 commit 8d2d032
Showing 1 changed file with 26 additions and 14 deletions.
40 changes: 26 additions & 14 deletions node_test/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"math/big"
"testing"
"time"

"github.com/ethereum/go-ethereum/common"
"github.com/statechannels/go-nitro/internal/testactors"
Expand Down Expand Up @@ -225,20 +226,31 @@ func RunIntegrationTestCase(tc TestCase, t *testing.T) {
chainLastConfirmedBlockNum = latestBlock.NumberU64() - chainservice.REQUIRED_BLOCK_CONFIRMATIONS
}

lastBlockNumA, err := clientA.GetLastBlockNum()
if err != nil {
t.Fatal(err)
}
if lastBlockNumA != chainLastConfirmedBlockNum {
t.Fatalf("clientA.GetLastBlockNumSeen: expected %d, got %d", chainLastConfirmedBlockNum, lastBlockNumA)
}
waitForClientBlockNum(t, clientA, chainLastConfirmedBlockNum, 10*time.Second)
waitForClientBlockNum(t, clientB, chainLastConfirmedBlockNum, 10*time.Second)
})
}

lastBlockNumB, err := clientB.GetLastBlockNum()
if err != nil {
t.Fatal(err)
}
if lastBlockNumB != chainLastConfirmedBlockNum {
t.Fatalf("clientB.GetLastBlockNumSeen: expected %d, got %d", chainLastConfirmedBlockNum, lastBlockNumB)
func waitForClientBlockNum(t *testing.T, n node.Node, targetBlockNum uint64, timeout time.Duration) {
// Setup up a context with a timeout so we exit if we don't get the block num in time
ctx, cancel := context.WithTimeout(context.Background(), timeout)
defer cancel()

lastBlockNum := uint64(0)
var err error
for {
select {
case <-ctx.Done():
t.Fatalf("expected block num of at least %d, got %d", targetBlockNum, lastBlockNum)
default:
lastBlockNum, err = n.GetLastBlockNum()
if err != nil {
t.Fatal(err)
}
if lastBlockNum >= targetBlockNum {
return
}
time.Sleep(100 * time.Millisecond)
}
})
}
}

0 comments on commit 8d2d032

Please sign in to comment.