Browse Source

e2e: avoid global test context (#7512)

pull/7516/head
Sam Kleinman 3 years ago
committed by GitHub
parent
commit
69f0a3b1c0
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 37 additions and 18 deletions
  1. +4
    -4
      test/e2e/tests/app_test.go
  2. +7
    -3
      test/e2e/tests/block_test.go
  3. +7
    -4
      test/e2e/tests/e2e_test.go
  4. +5
    -1
      test/e2e/tests/evidence_test.go
  5. +2
    -1
      test/e2e/tests/net_test.go
  6. +12
    -5
      test/e2e/tests/validator_test.go

+ 4
- 4
test/e2e/tests/app_test.go View File

@ -18,7 +18,7 @@ import (
// Tests that any initial state given in genesis has made it into the app. // Tests that any initial state given in genesis has made it into the app.
func TestApp_InitialState(t *testing.T) { 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 { if len(node.Testnet.InitialState) == 0 {
return return
} }
@ -37,7 +37,7 @@ func TestApp_InitialState(t *testing.T) {
// Tests that the app hash (as reported by the app) matches the last // Tests that the app hash (as reported by the app) matches the last
// block and the node sync status. // block and the node sync status.
func TestApp_Hash(t *testing.T) { 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() client, err := node.Client()
require.NoError(t, err) require.NoError(t, err)
info, err := client.ABCIInfo(ctx) 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. // Tests that the app and blockstore have and report the same height.
func TestApp_Height(t *testing.T) { 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() client, err := node.Client()
require.NoError(t, err) require.NoError(t, err)
info, err := client.ABCIInfo(ctx) info, err := client.ABCIInfo(ctx)
@ -147,7 +147,7 @@ func TestApp_Tx(t *testing.T) {
// testNode calls t.Parallel as well, so we should // testNode calls t.Parallel as well, so we should
// have a copy of the // have a copy of the
test := testCases[idx] 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() client, err := node.Client()
require.NoError(t, err) require.NoError(t, err)


+ 7
- 3
test/e2e/tests/block_test.go View File

@ -1,6 +1,7 @@
package e2e_test package e2e_test
import ( import (
"context"
"testing" "testing"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
@ -11,8 +12,11 @@ import (
// Tests that block headers are identical across nodes where present. // Tests that block headers are identical across nodes where present.
func TestBlock_Header(t *testing.T) { 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() client, err := node.Client()
require.NoError(t, err) require.NoError(t, err)
status, err := client.Status(ctx) status, err := client.Status(ctx)
@ -50,7 +54,7 @@ func TestBlock_Header(t *testing.T) {
// Tests that the node contains the expected block range. // Tests that the node contains the expected block range.
func TestBlock_Range(t *testing.T) { 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() client, err := node.Client()
require.NoError(t, err) require.NoError(t, err)
status, err := client.Status(ctx) status, err := client.Status(ctx)


+ 7
- 4
test/e2e/tests/e2e_test.go View File

@ -22,7 +22,6 @@ func init() {
} }
var ( var (
ctx = context.Background()
testnetCache = map[string]e2e.Testnet{} testnetCache = map[string]e2e.Testnet{}
testnetCacheMtx = sync.Mutex{} testnetCacheMtx = sync.Mutex{}
blocksCache = map[string][]*types.Block{} blocksCache = map[string][]*types.Block{}
@ -37,7 +36,7 @@ var (
// these tests are skipped so that they're not picked up during normal unit // 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, // test runs. If E2E_NODE is also set, only the specified node is tested,
// otherwise all nodes are 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() t.Helper()
testnet := loadTestnet(t) 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.Run(node.Name, func(t *testing.T) {
t.Parallel() 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 // fetchBlockChain fetches a complete, up-to-date block history from
// the freshest testnet archive node. // the freshest testnet archive node.
func fetchBlockChain(t *testing.T) []*types.Block {
func fetchBlockChain(ctx context.Context, t *testing.T) []*types.Block {
t.Helper() t.Helper()
testnet := loadTestnet(t) testnet := loadTestnet(t)


+ 5
- 1
test/e2e/tests/evidence_test.go View File

@ -1,6 +1,7 @@
package e2e_test package e2e_test
import ( import (
"context"
"testing" "testing"
"github.com/stretchr/testify/require" "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 // assert that all nodes that have blocks at the height of a misbehavior has evidence
// for that misbehavior // for that misbehavior
func TestEvidence_Misbehavior(t *testing.T) { func TestEvidence_Misbehavior(t *testing.T) {
blocks := fetchBlockChain(t)
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
blocks := fetchBlockChain(ctx, t)
testnet := loadTestnet(t) testnet := loadTestnet(t)
seenEvidence := 0 seenEvidence := 0
for _, block := range blocks { for _, block := range blocks {


+ 2
- 1
test/e2e/tests/net_test.go View File

@ -1,6 +1,7 @@
package e2e_test package e2e_test
import ( import (
"context"
"testing" "testing"
"github.com/stretchr/testify/require" "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 // FIXME Skip test since nodes aren't always able to fully mesh
t.SkipNow() 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() client, err := node.Client()
require.NoError(t, err) require.NoError(t, err)
netInfo, err := client.NetInfo(ctx) netInfo, err := client.NetInfo(ctx)


+ 12
- 5
test/e2e/tests/validator_test.go View File

@ -2,6 +2,7 @@ package e2e_test
import ( import (
"bytes" "bytes"
"context"
"testing" "testing"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
@ -13,7 +14,7 @@ import (
// Tests that validator sets are available and correct according to // Tests that validator sets are available and correct according to
// scheduled validator updates. // scheduled validator updates.
func TestValidator_Sets(t *testing.T) { 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() client, err := node.Client()
require.NoError(t, err) require.NoError(t, err)
status, err := client.Status(ctx) 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 // Tests that a validator proposes blocks when it's supposed to. It tolerates some
// missed blocks, e.g. due to testnet perturbations. // missed blocks, e.g. due to testnet perturbations.
func TestValidator_Propose(t *testing.T) { 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 { if node.Mode != e2e.ModeValidator {
return 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 // Tests that a validator signs blocks when it's supposed to. It tolerates some
// missed blocks, e.g. due to testnet perturbations. // missed blocks, e.g. due to testnet perturbations.
func TestValidator_Sign(t *testing.T) { 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 { if node.Mode != e2e.ModeValidator {
return return
} }


Loading…
Cancel
Save