Skip to content

Commit

Permalink
Test runtime shaving (#526)
Browse files Browse the repository at this point in the history
* Cut down on TestNewFilter_Logs

* Cut down on TestFilterValue

* Cut down on TestGenesisCustomBlockGasLimit

* remove obsolete encoding test

* reduce TestIbft_Transfer duration

* Remove useless TestCustomBlockGasLimitPropagation

* Cut down on TestIbft_TransactionFeeRecipient

* Remove 1M test case from TestAddTxns

* remove double test TestSignedTransaction; same as TestIbftTransfer

* Remove useless Dev stress test

* remove obsolete test: TestTxPool_ErrorCodes (tested by TestAddTxErrors)

* run tests in parallel (TestAddTxErrors)

* call t.Parallel on top level (go spec)

* Parallelize tests

* remove TestTxPool_TransactionCoalescing; tested in TestPromoteHandler

* parallelize TestPromoteHandler

* Add further paralelization

* Resolve linting errors

* Remove double parallel

* Optimize TestBroadcast e2e test  (#527)

* Optimize TestBroadcast

* Add AtomicErrors in e2e framework

* Fix lint error

* Change sync.Mutex to RWMutex in AtomicErrors

* removed TestTxPoolStressAddition - txpool benchmarking is done in txpool package

* remove unused import

* Update GH actions script (#531)

* Remove recursive submodule fetch from lint action

* Swap out the checkout version to v3

* Upgrade go setup action

* Remove useless go race build

* Add OS matrix strategy

* Remove matrix execution, as it offers little value for now

* Remove the verbose flag

* Bring back race builds

* Fix go parallel loop bug

* Remove unused TestDemote

* Standardize the 10s timeout usage

Co-authored-by: dbrajovic <dbrajovic3@gmail.com>
Co-authored-by: kourin <kourin.code@gmail.com>
  • Loading branch information
3 people authored May 6, 2022
1 parent 8f7d5eb commit 61e5829
Show file tree
Hide file tree
Showing 35 changed files with 665 additions and 654 deletions.
21 changes: 10 additions & 11 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,15 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Install Go
uses: actions/setup-go@v2
uses: actions/setup-go@v3
with:
go-version: 1.16.x

- name: Checkout code
uses: actions/checkout@v2
with:
submodules: recursive
uses: actions/checkout@v3

- name: Lint
uses: golangci/golangci-lint-action@v2
uses: golangci/golangci-lint-action@v3
with:
version: latest
args:
Expand Down Expand Up @@ -49,25 +47,26 @@ jobs:
-E dupl
-E errname
-E errorlint
skip-go-installation: true
test:
runs-on: ubuntu-latest
steps:
- name: Install Go
uses: actions/setup-go@v2
uses: actions/setup-go@v3
with:
go-version: 1.16.x

- name: Checkout code
uses: actions/checkout@v2
uses: actions/checkout@v3
with:
submodules: recursive


# We need to build the binary with the race flag enabled
# because it will get picked up and run during e2e tests
# and the e2e tests should error out if any kind of race is found
- name: Go build with race
run: CGO_ENABLED=1 GOOS=linux go build -race -a -o artifacts/polygon-edge .

- name: Add race artifacts directory to the path
- name: Add artifacts directory to the path
run: echo "$(pwd)/artifacts" >> $GITHUB_PATH

- name: Go test
Expand All @@ -76,7 +75,7 @@ jobs:
- name: Go build without race
run: CGO_ENABLED=0 GOOS=linux go build -a -o artifacts/polygon-edge .

- name: Replace artificats
- name: Replace artifacts
run: echo "$(pwd)/artifacts" >> $GITHUB_PATH

- name: Extract branch name
Expand Down
5 changes: 5 additions & 0 deletions archive/backup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ func (m *systemClientMock) BlockByNumber(
}

func Test_determineTo(t *testing.T) {
t.Parallel()

toPtr := func(x uint64) *uint64 {
return &x
}
Expand Down Expand Up @@ -154,7 +156,10 @@ func Test_determineTo(t *testing.T) {
}

for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
t.Parallel()

resTo, resToHash, err := determineTo(context.Background(), tt.systemClientMock, tt.targetTo)
assert.Equal(t, tt.err, err)
if tt.err == nil {
Expand Down
12 changes: 12 additions & 0 deletions chain/chain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ func hash(str string) types.Hash {
}

func TestGenesisAlloc(t *testing.T) {
t.Parallel()

cases := []struct {
input string
output map[types.Address]GenesisAccount
Expand Down Expand Up @@ -81,7 +83,11 @@ func TestGenesisAlloc(t *testing.T) {
}

for _, c := range cases {
c := c

t.Run("", func(t *testing.T) {
t.Parallel()

var dec map[types.Address]GenesisAccount
if err := json.Unmarshal([]byte(c.input), &dec); err != nil {
if c.output != nil {
Expand All @@ -95,6 +101,8 @@ func TestGenesisAlloc(t *testing.T) {
}

func TestGenesisX(t *testing.T) {
t.Parallel()

cases := []struct {
input string
output *Genesis
Expand Down Expand Up @@ -128,7 +136,11 @@ func TestGenesisX(t *testing.T) {
}

for _, c := range cases {
c := c

t.Run("", func(t *testing.T) {
t.Parallel()

var dec *Genesis
if err := json.Unmarshal([]byte(c.input), &dec); err != nil {
if c.output != nil {
Expand Down
11 changes: 11 additions & 0 deletions crypto/crypto_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ func TestKeyEncoding(t *testing.T) {
}

func TestCreate2(t *testing.T) {
t.Parallel()

cases := []struct {
address string
salt string
Expand Down Expand Up @@ -88,7 +90,11 @@ func TestCreate2(t *testing.T) {
}

for _, c := range cases {
c := c

t.Run("", func(t *testing.T) {
t.Parallel()

address := types.StringToAddress(c.address)
initCode := hex.MustDecodeHex(c.initCode)

Expand Down Expand Up @@ -157,6 +163,8 @@ func TestValidateSignatureValues(t *testing.T) {
}

func TestPrivateKeyRead(t *testing.T) {
t.Parallel()

// Write private keys to disk, check if read is ok
testTable := []struct {
name string
Expand Down Expand Up @@ -192,7 +200,10 @@ func TestPrivateKeyRead(t *testing.T) {
}

for _, testCase := range testTable {
testCase := testCase
t.Run(testCase.name, func(t *testing.T) {
t.Parallel()

privateKey, err := BytesToPrivateKey([]byte(testCase.privateKeyHex))
if err != nil && !testCase.shouldFail {
t.Fatalf("Unable to parse private key, %v", err)
Expand Down
5 changes: 5 additions & 0 deletions crypto/txsigner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ func TestFrontierSigner(t *testing.T) {
}

func TestEIP155Signer_Sender(t *testing.T) {
t.Parallel()

toAddress := types.StringToAddress("1")

testTable := []struct {
Expand Down Expand Up @@ -70,7 +72,10 @@ func TestEIP155Signer_Sender(t *testing.T) {
}

for _, testCase := range testTable {
testCase := testCase
t.Run(testCase.name, func(t *testing.T) {
t.Parallel()

key, keyGenError := GenerateKey()
if keyGenError != nil {
t.Fatalf("Unable to generate key")
Expand Down
45 changes: 38 additions & 7 deletions e2e/broadcast_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"fmt"
"math/big"
"sync"
"testing"
"time"

Expand Down Expand Up @@ -44,12 +45,21 @@ func TestBroadcast(t *testing.T) {
}

for _, tt := range testCases {
tt := tt

t.Run(tt.name, func(t *testing.T) {
srvs := framework.NewTestServers(t, tt.numNodes, conf)

framework.MultiJoinSerial(t, srvs[0:tt.numConnectedNodes])

// Check the connections
connectionErrors := framework.NewAtomicErrors(len(srvs))

var wgForConnections sync.WaitGroup

for i, srv := range srvs {
srv := srv

// Required number of connections
numRequiredConnections := 0
if i < tt.numConnectedNodes {
Expand All @@ -59,12 +69,29 @@ func TestBroadcast(t *testing.T) {
numRequiredConnections = 2
}
}
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
defer cancel()
_, err := framework.WaitUntilPeerConnects(ctx, srv, numRequiredConnections)
if err != nil {
t.Fatal(err)
}

wgForConnections.Add(1)
go func() {
defer wgForConnections.Done()

ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
defer cancel()

_, err := framework.WaitUntilPeerConnects(ctx, srv, numRequiredConnections)
if err != nil {
connectionErrors.Append(err)
}
}()
}

wgForConnections.Wait()

for _, err := range connectionErrors.Errors() {
t.Error(err)
}

if len(connectionErrors.Errors()) > 0 {
t.Fail()
}

// wait until gossip protocol build mesh network
Expand All @@ -90,6 +117,8 @@ func TestBroadcast(t *testing.T) {
}

for i, srv := range srvs {
srv := srv

shouldHaveTxPool := false
subTestName := fmt.Sprintf("node %d shouldn't have tx in txpool", i)
if i < tt.numConnectedNodes {
Expand All @@ -98,7 +127,9 @@ func TestBroadcast(t *testing.T) {
}

t.Run(subTestName, func(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
t.Parallel()

ctx, cancel := context.WithTimeout(context.Background(), framework.DefaultTimeout)
defer cancel()
res, err := framework.WaitUntilTxPoolFilled(ctx, srv, 1)

Expand Down
47 changes: 0 additions & 47 deletions e2e/encoding_test.go

This file was deleted.

Loading

0 comments on commit 61e5829

Please sign in to comment.