mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-17 18:30:45 +00:00
ethclient/gethclient: fix flaky TestSubscribePendingTxHashes test
Co-authored-by: s1na <1591639+s1na@users.noreply.github.com>
This commit is contained in:
parent
b346c85e19
commit
3e0889571b
1 changed files with 18 additions and 8 deletions
|
|
@ -23,6 +23,7 @@ import (
|
||||||
"math/big"
|
"math/big"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum"
|
"github.com/ethereum/go-ethereum"
|
||||||
"github.com/ethereum/go-ethereum/common"
|
"github.com/ethereum/go-ethereum/common"
|
||||||
|
|
@ -419,11 +420,11 @@ func testSubscribePendingTransactions(t *testing.T, client *rpc.Client) {
|
||||||
ethcl := ethclient.NewClient(client)
|
ethcl := ethclient.NewClient(client)
|
||||||
|
|
||||||
// Subscribe to Transactions
|
// Subscribe to Transactions
|
||||||
ch1 := make(chan common.Hash)
|
ch1 := make(chan common.Hash, 128)
|
||||||
ec.SubscribePendingTransactions(context.Background(), ch1)
|
ec.SubscribePendingTransactions(context.Background(), ch1)
|
||||||
|
|
||||||
// Subscribe to Transactions
|
// Subscribe to Transactions
|
||||||
ch2 := make(chan *types.Transaction)
|
ch2 := make(chan *types.Transaction, 128)
|
||||||
ec.SubscribeFullPendingTransactions(context.Background(), ch2)
|
ec.SubscribeFullPendingTransactions(context.Background(), ch2)
|
||||||
|
|
||||||
// Send a transaction
|
// Send a transaction
|
||||||
|
|
@ -452,14 +453,23 @@ func testSubscribePendingTransactions(t *testing.T, client *rpc.Client) {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
// Check that the transaction was sent over the channel
|
// Check that the transaction was sent over the channel
|
||||||
hash := <-ch1
|
timeout := 10 * time.Second
|
||||||
if hash != signedTx.Hash() {
|
select {
|
||||||
t.Fatalf("Invalid tx hash received, got %v, want %v", hash, signedTx.Hash())
|
case hash := <-ch1:
|
||||||
|
if hash != signedTx.Hash() {
|
||||||
|
t.Fatalf("Invalid tx hash received, got %v, want %v", hash, signedTx.Hash())
|
||||||
|
}
|
||||||
|
case <-time.After(timeout):
|
||||||
|
t.Fatal("Timed out waiting for pending tx hash notification")
|
||||||
}
|
}
|
||||||
// Check that the transaction was sent over the channel
|
// Check that the transaction was sent over the channel
|
||||||
tx = <-ch2
|
select {
|
||||||
if tx.Hash() != signedTx.Hash() {
|
case tx := <-ch2:
|
||||||
t.Fatalf("Invalid tx hash received, got %v, want %v", tx.Hash(), signedTx.Hash())
|
if tx.Hash() != signedTx.Hash() {
|
||||||
|
t.Fatalf("Invalid tx hash received, got %v, want %v", tx.Hash(), signedTx.Hash())
|
||||||
|
}
|
||||||
|
case <-time.After(timeout):
|
||||||
|
t.Fatal("Timed out waiting for pending full tx notification")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue