Skip to content

Commit

Permalink
execute all e2e in parallel
Browse files Browse the repository at this point in the history
  • Loading branch information
Lazar955 committed Sep 20, 2024
1 parent 1da3bf0 commit 60bb02d
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 31 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ test:
go test -race ./...

test-e2e:
go test -mod=readonly -failfast -timeout=15m -v $(PACKAGES_E2E) -count=1 --parallel 12 --tags=e2e
go test -mod=readonly -failfast -timeout=15m -v $(PACKAGES_E2E) -count=1 --tags=e2e

build-docker:
$(DOCKER) build --tag babylonlabs-io/vigilante -f Dockerfile \
Expand Down
8 changes: 2 additions & 6 deletions e2etest/bitcoind_node_setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import (
"encoding/json"
"fmt"
"github.com/babylonlabs-io/vigilante/e2etest/container"
"github.com/babylonlabs-io/vigilante/testutil"
"github.com/ory/dockertest/v3"
"github.com/stretchr/testify/require"
"os"
"strconv"
"strings"
"testing"
Expand Down Expand Up @@ -42,13 +42,9 @@ func NewBitcoindHandler(t *testing.T, manager *container.Manager) *BitcoindTestH
}

func (h *BitcoindTestHandler) Start(t *testing.T) *dockertest.Resource {
tempPath, err := os.MkdirTemp("", "vigilante-test-*")
tempPath, err := testutil.TempDir(t)
require.NoError(h.t, err)

h.t.Cleanup(func() {
_ = os.RemoveAll(tempPath)
})

bitcoinResource, err := h.m.RunBitcoindResource(t, tempPath)
require.NoError(h.t, err)

Expand Down
7 changes: 2 additions & 5 deletions e2etest/reporter_e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func (tm *TestManager) GenerateAndSubmitBlockNBlockStartingFromDepth(t *testing.
}

func TestReporter_BoostrapUnderFrequentBTCHeaders(t *testing.T) {
//t.Parallel() // todo(lazar): this test when run in parallel is very flaky, investigate why
t.Parallel()
// no need to much mature outputs, we are not going to submit transactions in this test
numMatureOutputs := uint32(150)

Expand Down Expand Up @@ -217,14 +217,11 @@ func TestHandleReorgAfterRestart(t *testing.T) {
// // we will start from block before tip and submit 2 new block this should trigger rollback
tm.GenerateAndSubmitBlockNBlockStartingFromDepth(t, 2, 1)

btcClient := initBTCClientWithSubscriber(t, tm.Config) //current tm.btcClient already has an active zmq subscription, would panic
defer btcClient.Stop()

// Start new reporter
vigilantReporterNew, err := reporter.New(
&tm.Config.Reporter,
logger,
btcClient,
tm.BTCClient,
tm.BabylonClient,
btcNotifier,
tm.Config.Common.RetrySleepTime,
Expand Down
21 changes: 2 additions & 19 deletions e2etest/test_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import (
"encoding/json"
"fmt"
"github.com/babylonlabs-io/vigilante/e2etest/container"
"github.com/babylonlabs-io/vigilante/testutil"
"github.com/btcsuite/btcd/txscript"
"go.uber.org/zap"
"os"
"path/filepath"
"testing"
"time"
Expand Down Expand Up @@ -130,7 +130,7 @@ func StartManager(t *testing.T, numMatureOutputsInWallet uint32, epochInterval u

// start Babylon node

tmpDir, err := tempDir(t)
tmpDir, err := testutil.TempDir(t)
require.NoError(t, err)

babylond, err := manager.RunBabylondResource(t, tmpDir, baseHeaderHex, hex.EncodeToString(pkScript), epochInterval)
Expand Down Expand Up @@ -273,20 +273,3 @@ func importPrivateKey(btcHandler *BitcoindTestHandler) (*btcec.PrivateKey, error

return privKey, nil
}

func tempDir(t *testing.T) (string, error) {
tempPath, err := os.MkdirTemp(os.TempDir(), "babylon-test-*")
if err != nil {
return "", err
}

if err = os.Chmod(tempPath, 0777); err != nil {
return "", err
}

t.Cleanup(func() {
_ = os.RemoveAll(tempPath)
})

return tempPath, err
}
34 changes: 34 additions & 0 deletions testutil/tmpdir.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package testutil

import (
"crypto/rand"
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/stretchr/testify/require"
"math/big"
"os"
"testing"
)

func TempDir(t *testing.T) (string, error) {
tempPath, err := os.MkdirTemp(os.TempDir(), randStr(t))
if err != nil {
return "", err
}

if err = os.Chmod(tempPath, 0777); err != nil {
return "", err
}

t.Cleanup(func() {
_ = os.RemoveAll(tempPath)
})

return tempPath, err
}

func randStr(t *testing.T) string {
n, err := rand.Int(rand.Reader, big.NewInt(1e18))
require.NoError(t, err)

return hexutil.EncodeBig(n)
}

0 comments on commit 60bb02d

Please sign in to comment.