From 60bb02d0fef8e36fd1b4ebc9b4de8b2bf9d4763a Mon Sep 17 00:00:00 2001 From: lazar Date: Fri, 20 Sep 2024 11:29:59 +0200 Subject: [PATCH 1/3] execute all e2e in parallel --- Makefile | 2 +- e2etest/bitcoind_node_setup.go | 8 ++------ e2etest/reporter_e2e_test.go | 7 ++----- e2etest/test_manager.go | 21 ++------------------- testutil/tmpdir.go | 34 ++++++++++++++++++++++++++++++++++ 5 files changed, 41 insertions(+), 31 deletions(-) create mode 100644 testutil/tmpdir.go diff --git a/Makefile b/Makefile index f93c41d..1b1f174 100644 --- a/Makefile +++ b/Makefile @@ -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 \ diff --git a/e2etest/bitcoind_node_setup.go b/e2etest/bitcoind_node_setup.go index 7a7a096..06bc994 100644 --- a/e2etest/bitcoind_node_setup.go +++ b/e2etest/bitcoind_node_setup.go @@ -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" @@ -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) diff --git a/e2etest/reporter_e2e_test.go b/e2etest/reporter_e2e_test.go index 37b87bd..06c5678 100644 --- a/e2etest/reporter_e2e_test.go +++ b/e2etest/reporter_e2e_test.go @@ -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) @@ -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, diff --git a/e2etest/test_manager.go b/e2etest/test_manager.go index 33be188..96be549 100644 --- a/e2etest/test_manager.go +++ b/e2etest/test_manager.go @@ -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" @@ -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) @@ -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 -} diff --git a/testutil/tmpdir.go b/testutil/tmpdir.go new file mode 100644 index 0000000..d3ff144 --- /dev/null +++ b/testutil/tmpdir.go @@ -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) +} From 78e258c67b3a51428a06bac34da4f1747b9213a6 Mon Sep 17 00:00:00 2001 From: lazar Date: Fri, 20 Sep 2024 11:38:53 +0200 Subject: [PATCH 2/3] less parallel --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 1b1f174..f93c41d 100644 --- a/Makefile +++ b/Makefile @@ -48,7 +48,7 @@ test: go test -race ./... test-e2e: - go test -mod=readonly -failfast -timeout=15m -v $(PACKAGES_E2E) -count=1 --tags=e2e + go test -mod=readonly -failfast -timeout=15m -v $(PACKAGES_E2E) -count=1 --parallel 12 --tags=e2e build-docker: $(DOCKER) build --tag babylonlabs-io/vigilante -f Dockerfile \ From 1cc01fc2960924837c628e626c6db3b93082d335 Mon Sep 17 00:00:00 2001 From: lazar Date: Fri, 20 Sep 2024 12:02:08 +0200 Subject: [PATCH 3/3] test1 --- e2etest/reporter_e2e_test.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/e2etest/reporter_e2e_test.go b/e2etest/reporter_e2e_test.go index 06c5678..0da3b59 100644 --- a/e2etest/reporter_e2e_test.go +++ b/e2etest/reporter_e2e_test.go @@ -170,8 +170,7 @@ func TestRelayHeadersAndHandleRollbacks(t *testing.T) { } func TestHandleReorgAfterRestart(t *testing.T) { - t.Parallel() - // no need to much mature outputs, we are not going to submit transactions in this test + t.Skip() // no need to much mature outputs, we are not going to submit transactions in this test numMatureOutputs := uint32(150) tm := StartManager(t, numMatureOutputs, defaultEpochInterval)