Skip to content

Commit

Permalink
Change folders hierarchy for property tests logs (#1371)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
goran-ethernal authored Apr 11, 2023
1 parent c8236e0 commit 3dbacc7
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 10 deletions.
1 change: 0 additions & 1 deletion .github/workflows/e2e-polybft.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down
1 change: 0 additions & 1 deletion .github/workflows/property-polybft.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
31 changes: 26 additions & 5 deletions e2e-polybft/framework/test-cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -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-"
)
Expand Down Expand Up @@ -98,6 +95,8 @@ type TestClusterConfig struct {
InitialTrieDB string
InitialStateRoot types.Hash

IsPropertyTest bool

logsDirOnce sync.Once
}

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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()

Expand All @@ -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"
}

Expand Down
6 changes: 5 additions & 1 deletion e2e-polybft/property/property_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package property
import (
"fmt"
"math"
"path/filepath"
"testing"
"time"

Expand Down Expand Up @@ -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 {
Expand All @@ -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)))
})
Expand Down

0 comments on commit 3dbacc7

Please sign in to comment.