Skip to content

Commit

Permalink
Make E2E more consistent, change log file setup (prysmaticlabs#4696)
Browse files Browse the repository at this point in the history
* Make E2E more consistent, change log file setup
* Merge branch 'master' into fix-e2e-sync
  • Loading branch information
0xKiwi authored and cryptomental committed Feb 24, 2020
1 parent f3af357 commit c24d7b6
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 19 deletions.
7 changes: 2 additions & 5 deletions endtoend/beacon_node.go
Expand Up @@ -3,9 +3,7 @@ package endtoend
import (
"fmt"
"io/ioutil"
"os"
"os/exec"
"path"
"strings"
"testing"

Expand Down Expand Up @@ -50,7 +48,7 @@ func startNewBeaconNode(t *testing.T, config *end2EndConfig, beaconNodes []*ev.B
t.Fatal("beacon chain binary not found")
}

stdOutFile, err := os.Create(path.Join(tmpPath, fmt.Sprintf(beaconNodeLogFileName, index)))
stdOutFile, err := deleteAndCreateFile(tmpPath, fmt.Sprintf(beaconNodeLogFileName, index))
if err != nil {
t.Fatal(err)
}
Expand All @@ -70,6 +68,7 @@ func startNewBeaconNode(t *testing.T, config *end2EndConfig, beaconNodes []*ev.B
fmt.Sprintf("--grpc-gateway-port=%d", 3400+index),
fmt.Sprintf("--contract-deployment-block=%d", 0),
fmt.Sprintf("--rpc-max-page-size=%d", params.BeaconConfig().MinGenesisActiveValidatorCount),
fmt.Sprintf("--log-file=%s", stdOutFile.Name()),
}
args = append(args, config.beaconFlags...)

Expand All @@ -82,8 +81,6 @@ func startNewBeaconNode(t *testing.T, config *end2EndConfig, beaconNodes []*ev.B

t.Logf("Starting beacon chain %d with flags: %s", index, strings.Join(args, " "))
cmd := exec.Command(binaryPath, args...)
cmd.Stdout = stdOutFile
cmd.Stderr = stdOutFile
if err := cmd.Start(); err != nil {
t.Fatalf("Failed to start beacon node: %v", err)
}
Expand Down
7 changes: 4 additions & 3 deletions endtoend/endtoend_test.go
Expand Up @@ -100,11 +100,11 @@ func runEndToEndTest(t *testing.T, config *end2EndConfig) {

syncNodeInfo := startNewBeaconNode(t, config, beaconNodes)
beaconNodes = append(beaconNodes, syncNodeInfo)
index := len(beaconNodes) - 1
index := uint64(len(beaconNodes)-1)

// Sleep until the next epoch to give time for the newly started node to sync.
nextEpochSeconds := (config.epochsToRun+2)*epochSeconds + epochSeconds/2
genesisTime.Add(time.Duration(nextEpochSeconds) * time.Second)
extraTimeToSync := (config.epochsToRun+3)*epochSeconds+60
genesisTime.Add(time.Duration(extraTimeToSync) * time.Second)
// Wait until middle of epoch to request to prevent conflicts.
time.Sleep(time.Until(genesisTime))

Expand All @@ -128,5 +128,6 @@ func runEndToEndTest(t *testing.T, config *end2EndConfig) {
}
})

defer logErrorOutput(t, syncLogFile, "beacon chain node", index)
defer killProcesses(t, []int{syncNodeInfo.ProcessID})
}
26 changes: 20 additions & 6 deletions endtoend/helpers.go
Expand Up @@ -14,7 +14,7 @@ import (
)

const (
maxPollingWaitTime = 36 * time.Second
maxPollingWaitTime = 60 * time.Second
filePollingInterval = 1 * time.Second
)

Expand All @@ -33,6 +33,20 @@ func killProcesses(t *testing.T, pIDs []int) {
}
}

func deleteAndCreateFile(tmpPath string, fileName string) (*os.File, error) {
filePath := path.Join(tmpPath, fileName)
if _, err := os.Stat(filePath); os.IsExist(err) {
if err := os.Remove(filePath); err != nil {
return nil, err
}
}
newFile, err := os.Create(path.Join(tmpPath, fileName))
if err != nil {
return nil, err
}
return newFile, nil
}

func waitForTextInFile(file *os.File, text string) error {
d := time.Now().Add(maxPollingWaitTime)
ctx, cancel := context.WithDeadline(context.Background(), d)
Expand All @@ -48,12 +62,8 @@ func waitForTextInFile(file *os.File, text string) error {
if err != nil {
return err
}
return fmt.Errorf("could not find requested text \"%s\" in logs:\n%s", text, string(contents))
return fmt.Errorf("could not find requested text \"%s\" in logs:\n%s", text, contents)
case <-ticker.C:
_, err := file.Seek(0, io.SeekStart)
if err != nil {
return err
}
fileScanner := bufio.NewScanner(file)
for fileScanner.Scan() {
scanned := fileScanner.Text()
Expand All @@ -64,6 +74,10 @@ func waitForTextInFile(file *os.File, text string) error {
if err := fileScanner.Err(); err != nil {
return err
}
_, err := file.Seek(0, io.SeekStart)
if err != nil {
return err
}
}
}
}
Expand Down
7 changes: 2 additions & 5 deletions endtoend/validator.go
Expand Up @@ -6,9 +6,7 @@ import (
"fmt"
"io/ioutil"
"math/big"
"os"
"os/exec"
"path"
"strings"
"testing"

Expand Down Expand Up @@ -50,7 +48,7 @@ func initializeValidators(
valClients := make([]*validatorClientInfo, beaconNodeNum)
validatorsPerNode := validatorNum / beaconNodeNum
for n := uint64(0); n < beaconNodeNum; n++ {
file, err := os.Create(path.Join(tmpPath, fmt.Sprintf(validatorLogFileName, n)))
file, err := deleteAndCreateFile(tmpPath, fmt.Sprintf(validatorLogFileName, n))
if err != nil {
t.Fatal(err)
}
Expand All @@ -61,12 +59,11 @@ func initializeValidators(
fmt.Sprintf("--monitoring-port=%d", 9280+n),
fmt.Sprintf("--datadir=%s/eth2-val-%d", tmpPath, n),
fmt.Sprintf("--beacon-rpc-provider=localhost:%d", 4200+n),
fmt.Sprintf("--log-file=%s",file.Name()),
}
args = append(args, config.validatorFlags...)

cmd := exec.Command(binaryPath, args...)
cmd.Stdout = file
cmd.Stderr = file
t.Logf("Starting validator client %d with flags: %s", n, strings.Join(args, " "))
if err := cmd.Start(); err != nil {
t.Fatal(err)
Expand Down

0 comments on commit c24d7b6

Please sign in to comment.