prysm-pulse/endtoend/components/slasher.go
Ivan Martinez 260847e92f
Fix long running E2E deposits testing (#6208)
* Fix long running e2e deposit processing
* Merge branch 'master' of github.com:prysmaticlabs/prysm into fix-long-e2e
* Remove logs
* Uncomment
* typing
* Reorder
* Add const for node count
* Merge refs/heads/master into fix-long-e2e
* Add trace logging
* Merge branch 'fix-long-e2e' of github.com:prysmaticlabs/prysm into fix-long-e2e
2020-06-11 06:38:15 +00:00

60 lines
1.8 KiB
Go

package components
import (
"fmt"
"os"
"os/exec"
"path"
"strings"
"testing"
"github.com/bazelbuild/rules_go/go/tools/bazel"
"github.com/prysmaticlabs/prysm/endtoend/helpers"
e2e "github.com/prysmaticlabs/prysm/endtoend/params"
)
// StartSlashers starts slasher clients for use within E2E, connected to all beacon nodes.
// It returns the process IDs of the slashers.
func StartSlashers(t *testing.T) []int {
binaryPath, found := bazel.FindBinary("slasher", "slasher")
if !found {
t.Log(binaryPath)
t.Fatal("Slasher binary not found")
}
var processIDs []int
for i := 0; i < e2e.TestParams.BeaconNodeCount; i++ {
stdOutFile, err := helpers.DeleteAndCreateFile(e2e.TestParams.LogPath, fmt.Sprintf(e2e.SlasherLogFileName, i))
if err != nil {
t.Fatal(err)
}
args := []string{
fmt.Sprintf("--datadir=%s/slasher-data-%d/", e2e.TestParams.TestPath, i),
fmt.Sprintf("--log-file=%s", stdOutFile.Name()),
fmt.Sprintf("--rpc-port=%d", e2e.TestParams.SlasherRPCPort+i),
fmt.Sprintf("--monitoring-port=%d", e2e.TestParams.SlasherMetricsPort+i),
fmt.Sprintf("--beacon-rpc-provider=localhost:%d", e2e.TestParams.BeaconNodeRPCPort+i),
"--force-clear-db",
"--e2e-config",
}
t.Logf("Starting slasher %d with flags: %s", i, strings.Join(args[2:], " "))
cmd := exec.Command(binaryPath, args...)
if err := cmd.Start(); err != nil {
t.Fatalf("Failed to start slasher client: %v", err)
}
processIDs = append(processIDs, cmd.Process.Pid)
}
stdOutFile, err := os.Open(path.Join(e2e.TestParams.LogPath, fmt.Sprintf(e2e.SlasherLogFileName, 0)))
if err != nil {
t.Fatal(err)
}
if err = helpers.WaitForTextInFile(stdOutFile, "Beacon node is fully synced, starting slashing detection"); err != nil {
t.Fatalf("could not find starting logs for slasher, this means it had issues starting: %v", err)
}
return processIDs
}