From 3dbacc78e0a1853eb46626e3bf2055453620dfe4 Mon Sep 17 00:00:00 2001 From: Goran Rojovic <100121253+goran-ethernal@users.noreply.github.com> Date: Tue, 11 Apr 2023 13:19:39 +0200 Subject: [PATCH] Change folders hierarchy for property tests logs (#1371) * Change folders hierarchy for property tests logs * Remove unnecessary env variable * Update yml and Make files * Comments fix * Add logging of test parameters * Comments fix * Lint fix --- .github/workflows/e2e-polybft.yml | 1 - .github/workflows/property-polybft.yml | 1 - Makefile | 4 ++-- e2e-polybft/framework/test-cluster.go | 31 +++++++++++++++++++++----- e2e-polybft/property/property_test.go | 6 ++++- 5 files changed, 33 insertions(+), 10 deletions(-) diff --git a/.github/workflows/e2e-polybft.yml b/.github/workflows/e2e-polybft.yml index 032e473279..f40fc5980e 100644 --- a/.github/workflows/e2e-polybft.yml +++ b/.github/workflows/e2e-polybft.yml @@ -18,7 +18,6 @@ jobs: env: E2E_TESTS: true E2E_LOGS: true - E2E_TESTS_TYPE: 'integration' CI_VERBOSE: true outputs: e2e_output_failure: ${{ steps.run_e2e_failure.outputs.test_output }} diff --git a/.github/workflows/property-polybft.yml b/.github/workflows/property-polybft.yml index 1435408a50..dc59f4feaa 100644 --- a/.github/workflows/property-polybft.yml +++ b/.github/workflows/property-polybft.yml @@ -17,7 +17,6 @@ jobs: env: E2E_TESTS: true E2E_LOGS: true - E2E_TESTS_TYPE: 'property' CI_VERBOSE: true outputs: property_output_failure: ${{ steps.run_property_failure.outputs.test_output }} diff --git a/Makefile b/Makefile index 975dcd83fd..b2fb2d5989 100644 --- a/Makefile +++ b/Makefile @@ -58,14 +58,14 @@ test-e2e: test-e2e-polybft: # We can not build with race because of a bug in boltdb dependency go build -o artifacts/polygon-edge . - env EDGE_BINARY=${PWD}/artifacts/polygon-edge E2E_TESTS=true E2E_LOGS=true E2E_TESTS_TYPE=integration \ + env EDGE_BINARY=${PWD}/artifacts/polygon-edge E2E_TESTS=true E2E_LOGS=true \ go test -v -timeout=45m ./e2e-polybft/e2e/... .PHONY: test-property-polybft test-property-polybft: # We can not build with race because of a bug in boltdb dependency go build -o artifacts/polygon-edge . - env EDGE_BINARY=${PWD}/artifacts/polygon-edge E2E_TESTS=true E2E_LOGS=true E2E_TESTS_TYPE=property go test -v -timeout=30m ./e2e-polybft/property/... + env EDGE_BINARY=${PWD}/artifacts/polygon-edge E2E_TESTS=true E2E_LOGS=true go test -v -timeout=30m ./e2e-polybft/property/... .PHONY: compile-core-contracts compile-core-contracts: diff --git a/e2e-polybft/framework/test-cluster.go b/e2e-polybft/framework/test-cluster.go index 98c49170bd..8f491df10e 100644 --- a/e2e-polybft/framework/test-cluster.go +++ b/e2e-polybft/framework/test-cluster.go @@ -43,9 +43,6 @@ const ( // envStdoutEnabled signal whether the output of the nodes get piped to stdout envStdoutEnabled = "E2E_STDOUT" - // envE2ETestsType used just to display type of test if skipped - envE2ETestsType = "E2E_TESTS_TYPE" - // prefix for validator directory defaultValidatorPrefix = "test-chain-" ) @@ -98,6 +95,8 @@ type TestClusterConfig struct { InitialTrieDB string InitialStateRoot types.Hash + IsPropertyTest bool + logsDirOnce sync.Once } @@ -145,6 +144,12 @@ func (c *TestClusterConfig) GetStdout(name string, custom ...io.Writer) io.Write func (c *TestClusterConfig) initLogsDir() { logsDir := path.Join("../..", fmt.Sprintf("e2e-logs-%d", startTime), c.t.Name()) + if c.IsPropertyTest { + // property tests run cluster multiple times, so each cluster run will be in the main folder + // e2e-logs-{someNumber}/NameOfPropertyTest/NameOfPropertyTest-{someNumber} + // to have a separation between logs of each cluster run + logsDir = path.Join(logsDir, fmt.Sprintf("%v-%d", c.t.Name(), time.Now().UTC().Unix())) + } if err := common.CreateDirSafe(logsDir, 0750); err != nil { c.t.Fatal(err) @@ -268,10 +273,24 @@ func WithTransactionsAllowListEnabled(addr types.Address) ClusterOption { } } +func WithPropertyTestLogging() ClusterOption { + return func(h *TestClusterConfig) { + h.IsPropertyTest = true + } +} + func isTrueEnv(e string) bool { return strings.ToLower(os.Getenv(e)) == "true" } +func NewPropertyTestCluster(t *testing.T, validatorsCount int, opts ...ClusterOption) *TestCluster { + t.Helper() + + opts = append(opts, WithPropertyTestLogging()) + + return NewTestCluster(t, validatorsCount, opts...) +} + func NewTestCluster(t *testing.T, validatorsCount int, opts ...ClusterOption) *TestCluster { t.Helper() @@ -298,8 +317,10 @@ func NewTestCluster(t *testing.T, validatorsCount int, opts ...ClusterOption) *T } if !isTrueEnv(envE2ETestsEnabled) { - testType := os.Getenv(envE2ETestsType) - if testType == "" { + var testType string + if config.IsPropertyTest { + testType = "property" + } else { testType = "integration" } diff --git a/e2e-polybft/property/property_test.go b/e2e-polybft/property/property_test.go index 9231cb829a..25f7511481 100644 --- a/e2e-polybft/property/property_test.go +++ b/e2e-polybft/property/property_test.go @@ -3,6 +3,7 @@ package property import ( "fmt" "math" + "path/filepath" "testing" "time" @@ -34,7 +35,7 @@ func TestProperty_DifferentVotingPower(t *testing.T) { premine[i] = rapid.Uint64Range(1, maxPremine).Draw(tt, fmt.Sprintf("stake for node %d", i+1)) } - cluster := framework.NewTestCluster(t, int(numNodes), + cluster := framework.NewPropertyTestCluster(t, int(numNodes), framework.WithEpochSize(epochSize), framework.WithSecretsCallback(func(adresses []types.Address, config *framework.TestClusterConfig) { for i, a := range adresses { @@ -43,6 +44,9 @@ func TestProperty_DifferentVotingPower(t *testing.T) { })) defer cluster.Stop() + t.Logf("Test %v, run with %d nodes, epoch size: %d. Number of blocks to mine: %d", + filepath.Base(cluster.Config.LogsDir), numNodes, epochSize, numBlocks) + // wait for single epoch to process withdrawal require.NoError(t, cluster.WaitForBlock(numBlocks, blockTime*time.Duration(numBlocks))) })