mirror of
https://github.com/tendermint/tendermint.git
synced 2026-01-05 21:14:53 +00:00
e2e: avoid global test context (#7512)
This commit is contained in:
@@ -18,7 +18,7 @@ import (
|
||||
|
||||
// Tests that any initial state given in genesis has made it into the app.
|
||||
func TestApp_InitialState(t *testing.T) {
|
||||
testNode(t, func(t *testing.T, node e2e.Node) {
|
||||
testNode(t, func(ctx context.Context, t *testing.T, node e2e.Node) {
|
||||
if len(node.Testnet.InitialState) == 0 {
|
||||
return
|
||||
}
|
||||
@@ -37,7 +37,7 @@ func TestApp_InitialState(t *testing.T) {
|
||||
// Tests that the app hash (as reported by the app) matches the last
|
||||
// block and the node sync status.
|
||||
func TestApp_Hash(t *testing.T) {
|
||||
testNode(t, func(t *testing.T, node e2e.Node) {
|
||||
testNode(t, func(ctx context.Context, t *testing.T, node e2e.Node) {
|
||||
client, err := node.Client()
|
||||
require.NoError(t, err)
|
||||
info, err := client.ABCIInfo(ctx)
|
||||
@@ -65,7 +65,7 @@ func TestApp_Hash(t *testing.T) {
|
||||
|
||||
// Tests that the app and blockstore have and report the same height.
|
||||
func TestApp_Height(t *testing.T) {
|
||||
testNode(t, func(t *testing.T, node e2e.Node) {
|
||||
testNode(t, func(ctx context.Context, t *testing.T, node e2e.Node) {
|
||||
client, err := node.Client()
|
||||
require.NoError(t, err)
|
||||
info, err := client.ABCIInfo(ctx)
|
||||
@@ -147,7 +147,7 @@ func TestApp_Tx(t *testing.T) {
|
||||
// testNode calls t.Parallel as well, so we should
|
||||
// have a copy of the
|
||||
test := testCases[idx]
|
||||
testNode(t, func(t *testing.T, node e2e.Node) {
|
||||
testNode(t, func(ctx context.Context, t *testing.T, node e2e.Node) {
|
||||
client, err := node.Client()
|
||||
require.NoError(t, err)
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package e2e_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
@@ -11,8 +12,11 @@ import (
|
||||
|
||||
// Tests that block headers are identical across nodes where present.
|
||||
func TestBlock_Header(t *testing.T) {
|
||||
blocks := fetchBlockChain(t)
|
||||
testNode(t, func(t *testing.T, node e2e.Node) {
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
defer cancel()
|
||||
|
||||
blocks := fetchBlockChain(ctx, t)
|
||||
testNode(t, func(ctx context.Context, t *testing.T, node e2e.Node) {
|
||||
client, err := node.Client()
|
||||
require.NoError(t, err)
|
||||
status, err := client.Status(ctx)
|
||||
@@ -50,7 +54,7 @@ func TestBlock_Header(t *testing.T) {
|
||||
|
||||
// Tests that the node contains the expected block range.
|
||||
func TestBlock_Range(t *testing.T) {
|
||||
testNode(t, func(t *testing.T, node e2e.Node) {
|
||||
testNode(t, func(ctx context.Context, t *testing.T, node e2e.Node) {
|
||||
client, err := node.Client()
|
||||
require.NoError(t, err)
|
||||
status, err := client.Status(ctx)
|
||||
|
||||
@@ -22,7 +22,6 @@ func init() {
|
||||
}
|
||||
|
||||
var (
|
||||
ctx = context.Background()
|
||||
testnetCache = map[string]e2e.Testnet{}
|
||||
testnetCacheMtx = sync.Mutex{}
|
||||
blocksCache = map[string][]*types.Block{}
|
||||
@@ -37,7 +36,7 @@ var (
|
||||
// these tests are skipped so that they're not picked up during normal unit
|
||||
// test runs. If E2E_NODE is also set, only the specified node is tested,
|
||||
// otherwise all nodes are tested.
|
||||
func testNode(t *testing.T, testFunc func(*testing.T, e2e.Node)) {
|
||||
func testNode(t *testing.T, testFunc func(context.Context, *testing.T, e2e.Node)) {
|
||||
t.Helper()
|
||||
|
||||
testnet := loadTestnet(t)
|
||||
@@ -58,7 +57,11 @@ func testNode(t *testing.T, testFunc func(*testing.T, e2e.Node)) {
|
||||
|
||||
t.Run(node.Name, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
testFunc(t, node)
|
||||
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
defer cancel()
|
||||
|
||||
testFunc(ctx, t, node)
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -86,7 +89,7 @@ func loadTestnet(t *testing.T) e2e.Testnet {
|
||||
|
||||
// fetchBlockChain fetches a complete, up-to-date block history from
|
||||
// the freshest testnet archive node.
|
||||
func fetchBlockChain(t *testing.T) []*types.Block {
|
||||
func fetchBlockChain(ctx context.Context, t *testing.T) []*types.Block {
|
||||
t.Helper()
|
||||
|
||||
testnet := loadTestnet(t)
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package e2e_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
@@ -9,7 +10,10 @@ import (
|
||||
// assert that all nodes that have blocks at the height of a misbehavior has evidence
|
||||
// for that misbehavior
|
||||
func TestEvidence_Misbehavior(t *testing.T) {
|
||||
blocks := fetchBlockChain(t)
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
defer cancel()
|
||||
|
||||
blocks := fetchBlockChain(ctx, t)
|
||||
testnet := loadTestnet(t)
|
||||
seenEvidence := 0
|
||||
for _, block := range blocks {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package e2e_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
@@ -13,7 +14,7 @@ func TestNet_Peers(t *testing.T) {
|
||||
// FIXME Skip test since nodes aren't always able to fully mesh
|
||||
t.SkipNow()
|
||||
|
||||
testNode(t, func(t *testing.T, node e2e.Node) {
|
||||
testNode(t, func(ctx context.Context, t *testing.T, node e2e.Node) {
|
||||
client, err := node.Client()
|
||||
require.NoError(t, err)
|
||||
netInfo, err := client.NetInfo(ctx)
|
||||
|
||||
@@ -2,6 +2,7 @@ package e2e_test
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
@@ -13,7 +14,7 @@ import (
|
||||
// Tests that validator sets are available and correct according to
|
||||
// scheduled validator updates.
|
||||
func TestValidator_Sets(t *testing.T) {
|
||||
testNode(t, func(t *testing.T, node e2e.Node) {
|
||||
testNode(t, func(ctx context.Context, t *testing.T, node e2e.Node) {
|
||||
client, err := node.Client()
|
||||
require.NoError(t, err)
|
||||
status, err := client.Status(ctx)
|
||||
@@ -59,8 +60,11 @@ func TestValidator_Sets(t *testing.T) {
|
||||
// Tests that a validator proposes blocks when it's supposed to. It tolerates some
|
||||
// missed blocks, e.g. due to testnet perturbations.
|
||||
func TestValidator_Propose(t *testing.T) {
|
||||
blocks := fetchBlockChain(t)
|
||||
testNode(t, func(t *testing.T, node e2e.Node) {
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
defer cancel()
|
||||
|
||||
blocks := fetchBlockChain(ctx, t)
|
||||
testNode(t, func(ctx context.Context, t *testing.T, node e2e.Node) {
|
||||
if node.Mode != e2e.ModeValidator {
|
||||
return
|
||||
}
|
||||
@@ -90,8 +94,11 @@ func TestValidator_Propose(t *testing.T) {
|
||||
// Tests that a validator signs blocks when it's supposed to. It tolerates some
|
||||
// missed blocks, e.g. due to testnet perturbations.
|
||||
func TestValidator_Sign(t *testing.T) {
|
||||
blocks := fetchBlockChain(t)
|
||||
testNode(t, func(t *testing.T, node e2e.Node) {
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
defer cancel()
|
||||
|
||||
blocks := fetchBlockChain(ctx, t)
|
||||
testNode(t, func(ctx context.Context, t *testing.T, node e2e.Node) {
|
||||
if node.Mode != e2e.ModeValidator {
|
||||
return
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user