Skip to content
This repository was archived by the owner on Oct 11, 2024. It is now read-only.

Commit 01e7a82

Browse files
committed
Make new core tests serial
1 parent 926d281 commit 01e7a82

File tree

2 files changed

+36
-5
lines changed

2 files changed

+36
-5
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ test-go-parallel:
4646

4747
.PHONY: test-go-serial
4848
test-go-serial:
49-
go test ./zeroex/ordervalidator ./zeroex/orderwatch -race -timeout 90s -p=1 --serial
49+
go test ./zeroex/ordervalidator ./zeroex/orderwatch ./core -race -timeout 90s -p=1 --serial
5050

5151

5252
.PHONY: test-browser-integration

core/core_test.go

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,18 @@ package core
44

55
import (
66
"context"
7+
"flag"
78
"math/big"
89
"testing"
910
"time"
1011

1112
"github.com/0xProject/0x-mesh/constants"
13+
"github.com/0xProject/0x-mesh/ethereum"
1214
"github.com/0xProject/0x-mesh/meshdb"
1315
"github.com/0xProject/0x-mesh/scenario"
1416
"github.com/0xProject/0x-mesh/zeroex"
1517
"github.com/ethereum/go-ethereum/ethclient"
18+
ethrpc "github.com/ethereum/go-ethereum/rpc"
1619
"github.com/google/uuid"
1720
"github.com/libp2p/go-libp2p-core/peer"
1821
"github.com/stretchr/testify/assert"
@@ -61,7 +64,38 @@ func newTestApp(t *testing.T) *App {
6164
return app
6265
}
6366

67+
var (
68+
rpcClient *ethrpc.Client
69+
ethClient *ethclient.Client
70+
blockchainLifecycle *ethereum.BlockchainLifecycle
71+
)
72+
73+
// Since these tests must be run sequentially, we don't want them to run as part of
74+
// the normal testing process. They will only be run if the "--serial" flag is used.
75+
var serialTestsEnabled bool
76+
77+
func init() {
78+
flag.BoolVar(&serialTestsEnabled, "serial", false, "enable serial tests")
79+
testing.Init()
80+
flag.Parse()
81+
82+
var err error
83+
rpcClient, err = ethrpc.Dial(constants.GanacheEndpoint)
84+
if err != nil {
85+
panic(err)
86+
}
87+
ethClient = ethclient.NewClient(rpcClient)
88+
blockchainLifecycle, err = ethereum.NewBlockchainLifecycle(rpcClient)
89+
if err != nil {
90+
panic(err)
91+
}
92+
}
93+
6494
func TestOrderSync(t *testing.T) {
95+
if !serialTestsEnabled {
96+
t.Skip("Serial tests (tests which cannot run in parallel) are disabled. You can enable them with the --serial flag")
97+
}
98+
6599
// Set up two Mesh nodes. originalNode starts with some orders. newNode enters
66100
// the network without any orders.
67101
ctx, cancel := context.WithCancel(context.Background())
@@ -75,15 +109,12 @@ func TestOrderSync(t *testing.T) {
75109
require.NoError(t, newNode.Start(ctx))
76110
}()
77111

78-
ethClient, err := ethclient.Dial(constants.GanacheEndpoint)
79-
require.NoError(t, err)
80-
81112
// Manually add some orders to originalNode.
82113
originalOrders := make([]*zeroex.SignedOrder, 10)
83114
for i := range originalOrders {
84115
originalOrders[i] = scenario.CreateWETHForZRXSignedTestOrder(t, ethClient, constants.GanacheAccount1, constants.GanacheAccount2, big.NewInt(20), big.NewInt(5))
85116
}
86-
_, err = originalNode.orderWatcher.ValidateAndStoreValidOrders(ctx, originalOrders, true, constants.TestChainID)
117+
_, err := originalNode.orderWatcher.ValidateAndStoreValidOrders(ctx, originalOrders, true, constants.TestChainID)
87118
require.NoError(t, err)
88119

89120
err = originalNode.AddPeer(peer.AddrInfo{

0 commit comments

Comments
 (0)