mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 10:52:25 +00:00
cmd/swarm/swarm-smoke-pss: add command that can run all tests
This commit is contained in:
parent
48b0374cbc
commit
0d8c530333
3 changed files with 61 additions and 43 deletions
|
|
@ -112,22 +112,24 @@ func main() {
|
||||||
app.Commands = []cli.Command{
|
app.Commands = []cli.Command{
|
||||||
{
|
{
|
||||||
Name: "asym",
|
Name: "asym",
|
||||||
Aliases: []string{"a"},
|
Usage: "send and receive multiple messages across random nodes using asymmetric encryption",
|
||||||
Usage: "PSS: send and receive multiple messages across random nodes using asymmetric encryption",
|
|
||||||
Action: wrapCliCommand("asym", pssAsymCheck),
|
Action: wrapCliCommand("asym", pssAsymCheck),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Name: "sym",
|
Name: "sym",
|
||||||
Aliases: []string{"s"},
|
Usage: "send and receive multiple messages across random nodes using symmetric encryption",
|
||||||
Usage: "PSS: send and receive multiple messages across random nodes using symmetric encryption",
|
|
||||||
Action: wrapCliCommand("sym", pssSymCheck),
|
Action: wrapCliCommand("sym", pssSymCheck),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Name: "raw",
|
Name: "raw",
|
||||||
Aliases: []string{"r"},
|
Usage: "send and receive multiple raw messages across random nodes",
|
||||||
Usage: "PSS: send and receive multiple raw messages across random nodes",
|
|
||||||
Action: wrapCliCommand("raw", pssRawCheck),
|
Action: wrapCliCommand("raw", pssRawCheck),
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
Name: "all",
|
||||||
|
Usage: "send and receive raw, sym and asym messages across randome nodes",
|
||||||
|
Action: wrapCliCommand("raw", pssAllCheck),
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
sort.Sort(cli.FlagsByName(app.Flags))
|
sort.Sort(cli.FlagsByName(app.Flags))
|
||||||
|
|
|
||||||
|
|
@ -53,19 +53,39 @@ type pssSession struct {
|
||||||
jobs map[string]*pssJob
|
jobs map[string]*pssJob
|
||||||
}
|
}
|
||||||
|
|
||||||
func pssAsymCheck(ctx *cli.Context, tuid string) error {
|
func pssAsymCheck(ctx *cli.Context) error {
|
||||||
return runCheck(pssModeAsym, pssMessageCount)
|
return runCheck(pssModeAsym, pssMessageCount, pssMessageSize)
|
||||||
}
|
}
|
||||||
|
|
||||||
func pssSymCheck(ctx *cli.Context, tuid string) error {
|
func pssSymCheck(ctx *cli.Context) error {
|
||||||
return runCheck(pssModeSym, pssMessageCount)
|
return runCheck(pssModeSym, pssMessageCount, pssMessageSize)
|
||||||
}
|
}
|
||||||
func pssRawCheck(ctx *cli.Context, tuid string) error {
|
func pssRawCheck(ctx *cli.Context) error {
|
||||||
return runCheck(pssModeRaw, pssMessageCount)
|
return runCheck(pssModeRaw, pssMessageCount, pssMessageSize)
|
||||||
}
|
}
|
||||||
|
|
||||||
func runCheck(mode pssMode, count int) error {
|
func pssAllCheck(ctx *cli.Context) error {
|
||||||
log.Info(fmt.Sprintf("pss.%s test started", mode), "msgCount", count)
|
gotErr := false
|
||||||
|
if err := pssRawCheck(ctx); err != nil {
|
||||||
|
log.Error("error when running raw tests", "err", err)
|
||||||
|
gotErr = true
|
||||||
|
}
|
||||||
|
if err := pssSymCheck(ctx); err != nil {
|
||||||
|
log.Error("error when running sym tests", "err", err)
|
||||||
|
gotErr = true
|
||||||
|
}
|
||||||
|
if err := pssAsymCheck(ctx); err != nil {
|
||||||
|
log.Error("error when running asym tests", "err", err)
|
||||||
|
gotErr = true
|
||||||
|
}
|
||||||
|
if gotErr {
|
||||||
|
return errors.New("some tests failed")
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func runCheck(mode pssMode, count int, msgSizeBytes int) error {
|
||||||
|
log.Info(fmt.Sprintf("pss.%s test started", mode), "msgCount", count, "msgBytes", msgSizeBytes)
|
||||||
|
|
||||||
session := pssSetup()
|
session := pssSetup()
|
||||||
|
|
||||||
|
|
@ -79,11 +99,12 @@ func runCheck(mode pssMode, count int) error {
|
||||||
return errors.New("at least 2 nodes are required to be working")
|
return errors.New("at least 2 nodes are required to be working")
|
||||||
}
|
}
|
||||||
|
|
||||||
jobs := session.genJobs(count, mode)
|
jobs := session.genJobs(count, mode, msgSizeBytes)
|
||||||
|
|
||||||
errc := make(chan error)
|
errc := make(chan error)
|
||||||
go func() {
|
go func() {
|
||||||
var failCount, successCount int64
|
var failCount, successCount int64
|
||||||
|
t := time.Now()
|
||||||
sc, err := session.processJobs(jobs)
|
sc, err := session.processJobs(jobs)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("error processing some jobs", "err", err)
|
log.Error("error processing some jobs", "err", err)
|
||||||
|
|
@ -91,10 +112,13 @@ func runCheck(mode pssMode, count int) error {
|
||||||
successCount = int64(sc)
|
successCount = int64(sc)
|
||||||
failCount = int64(count - sc)
|
failCount = int64(count - sc)
|
||||||
|
|
||||||
metrics.GetOrRegisterCounter(fmt.Sprintf("pss.%s.failMsg", mode), nil).Inc(failCount)
|
metrics.GetOrRegisterCounter(fmt.Sprintf("pss.%s.msgs.fail", mode), nil).Inc(failCount)
|
||||||
metrics.GetOrRegisterCounter(fmt.Sprintf("pss.%s.successMsg", mode), nil).Inc(successCount)
|
metrics.GetOrRegisterCounter(fmt.Sprintf("pss.%s.msgs.success", mode), nil).Inc(successCount)
|
||||||
|
|
||||||
log.Info(fmt.Sprintf("pss.%s test ended", mode), "success", successCount, "failures", failCount)
|
totalTime := time.Since(t)
|
||||||
|
|
||||||
|
metrics.GetOrRegisterResettingTimer(fmt.Sprintf("pss.%s.total-time", mode), nil).Update(totalTime)
|
||||||
|
log.Info(fmt.Sprintf("pss.%s test ended", mode), "time", totalTime, "success", successCount, "failures", failCount)
|
||||||
|
|
||||||
if failCount > 0 {
|
if failCount > 0 {
|
||||||
errc <- errors.New("some messages were not delivered")
|
errc <- errors.New("some messages were not delivered")
|
||||||
|
|
@ -223,17 +247,17 @@ func (s *pssSession) processJobs(jobs []pssJob) (int, error) {
|
||||||
return len(jobs), nil
|
return len(jobs), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *pssSession) genJobs(count int, mode pssMode) []pssJob {
|
func (s *pssSession) genJobs(count int, mode pssMode, msgSizeBytes int) []pssJob {
|
||||||
jobs := make([]pssJob, count)
|
jobs := make([]pssJob, count)
|
||||||
for i := 0; i < count; i++ {
|
for i := 0; i < count; i++ {
|
||||||
jobs[i] = s.genJob(mode)
|
jobs[i] = s.genJob(mode, msgSizeBytes)
|
||||||
}
|
}
|
||||||
return jobs
|
return jobs
|
||||||
}
|
}
|
||||||
|
|
||||||
// genJob generates a pssJob with random message that will be sent
|
// genJob generates a pssJob with random message that will be sent
|
||||||
// from a random sending node to a random receiving node
|
// from a random sending node to a random receiving node
|
||||||
func (s *pssSession) genJob(mode pssMode) pssJob {
|
func (s *pssSession) genJob(mode pssMode, msgSizeBytes int) pssJob {
|
||||||
senderNodeIdx := rand.Intn(len(s.nodes))
|
senderNodeIdx := rand.Intn(len(s.nodes))
|
||||||
senderNode := s.nodes[senderNodeIdx]
|
senderNode := s.nodes[senderNodeIdx]
|
||||||
log.Trace("sender node", "pss_baseAddr", hexutil.Encode(senderNode.addr), "host", hosts[senderNodeIdx])
|
log.Trace("sender node", "pss_baseAddr", hexutil.Encode(senderNode.addr), "host", hosts[senderNodeIdx])
|
||||||
|
|
@ -247,9 +271,9 @@ func (s *pssSession) genJob(mode pssMode) pssJob {
|
||||||
log.Trace("recv node", "pss_baseAddr", hexutil.Encode(recvNode.addr), "host", hosts[recvNodeIdx])
|
log.Trace("recv node", "pss_baseAddr", hexutil.Encode(recvNode.addr), "host", hosts[recvNodeIdx])
|
||||||
|
|
||||||
// create new message and add it to job index to check for receives
|
// create new message and add it to job index to check for receives
|
||||||
randomMsg := testutil.RandomBytes(seed, pssMessageSize)
|
randomMsg := testutil.RandomBytes(seed, msgSizeBytes)
|
||||||
// change seed so that the next random message is different
|
// change seed so that the next random message is different
|
||||||
seed = seed + 1
|
seed++
|
||||||
|
|
||||||
j := pssJob{
|
j := pssJob{
|
||||||
sender: senderNode,
|
sender: senderNode,
|
||||||
|
|
@ -261,12 +285,12 @@ func (s *pssSession) genJob(mode pssMode) pssJob {
|
||||||
msgIdx := toMsgIdx(randomMsg)
|
msgIdx := toMsgIdx(randomMsg)
|
||||||
s.jobs[msgIdx] = &j
|
s.jobs[msgIdx] = &j
|
||||||
|
|
||||||
log.Debug("generated job", "job", hexutil.Encode([]byte(msgIdx)), "sender", hosts[j.sender.hostIdx], "recv", hosts[j.receiver.hostIdx])
|
log.Debug("gen job", "job", hexutil.Encode([]byte(msgIdx)), "sender", hosts[j.sender.hostIdx], "recv", hosts[j.receiver.hostIdx])
|
||||||
|
|
||||||
return j
|
return j
|
||||||
}
|
}
|
||||||
|
|
||||||
// waitForJob blocks until a msg is received or a timeout is reached
|
// waitForMsg blocks until a msg is received or a timeout is reached
|
||||||
func (s *pssSession) waitForMsg() error {
|
func (s *pssSession) waitForMsg() error {
|
||||||
select {
|
select {
|
||||||
case res := <-s.msgC:
|
case res := <-s.msgC:
|
||||||
|
|
|
||||||
|
|
@ -25,7 +25,6 @@ import (
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/log"
|
"github.com/ethereum/go-ethereum/log"
|
||||||
"github.com/ethereum/go-ethereum/metrics"
|
"github.com/ethereum/go-ethereum/metrics"
|
||||||
"github.com/pborman/uuid"
|
|
||||||
cli "gopkg.in/urfave/cli.v1"
|
cli "gopkg.in/urfave/cli.v1"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -34,22 +33,15 @@ var (
|
||||||
seed = int(time.Now().UTC().UnixNano())
|
seed = int(time.Now().UTC().UnixNano())
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
|
||||||
rand.Seed(int64(seed))
|
|
||||||
}
|
|
||||||
|
|
||||||
func wsEndpoint(host string) string {
|
func wsEndpoint(host string) string {
|
||||||
return fmt.Sprintf("ws://%s:%d", host, wsPort)
|
return fmt.Sprintf("ws://%s:%d", host, wsPort)
|
||||||
}
|
}
|
||||||
|
|
||||||
func wrapCliCommand(name string, command func(*cli.Context, string) error) func(*cli.Context) error {
|
func wrapCliCommand(name string, command func(*cli.Context) error) func(*cli.Context) error {
|
||||||
return func(ctx *cli.Context) error {
|
return func(ctx *cli.Context) error {
|
||||||
log.PrintOrigins(true)
|
log.PrintOrigins(true)
|
||||||
log.Root().SetHandler(log.LvlFilterHandler(log.Lvl(verbosity), log.StreamHandler(os.Stdout, log.TerminalFormat(false))))
|
log.Root().SetHandler(log.LvlFilterHandler(log.Lvl(verbosity), log.StreamHandler(os.Stdout, log.TerminalFormat(false))))
|
||||||
|
|
||||||
// test uuid
|
|
||||||
tuid := uuid.New()[:8]
|
|
||||||
|
|
||||||
commandName = name
|
commandName = name
|
||||||
|
|
||||||
hosts = strings.Split(allhosts, ",")
|
hosts = strings.Split(allhosts, ",")
|
||||||
|
|
@ -66,13 +58,13 @@ func wrapCliCommand(name string, command func(*cli.Context, string) error) func(
|
||||||
|
|
||||||
defer func(now time.Time) {
|
defer func(now time.Time) {
|
||||||
totalTime := time.Since(now)
|
totalTime := time.Since(now)
|
||||||
log.Info("total time", "tuid", tuid, "time", totalTime)
|
log.Info("total time", "time", totalTime)
|
||||||
metrics.GetOrRegisterResettingTimer(name+".total-time", nil).Update(totalTime)
|
metrics.GetOrRegisterResettingTimer(name+".total-time", nil).Update(totalTime)
|
||||||
}(time.Now())
|
}(time.Now())
|
||||||
|
|
||||||
log.Info("smoke test starting", "tuid", tuid, "task", name, "timeout", timeout)
|
log.Info("pss smoke test starting", "task", name, "timeout", timeout)
|
||||||
metrics.GetOrRegisterCounter(name, nil).Inc(1)
|
metrics.GetOrRegisterCounter(name, nil).Inc(1)
|
||||||
|
|
||||||
return command(ctx, tuid)
|
return command(ctx)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue