feat(test): let integration-test log verbosity be configurable (#409)

This commit is contained in:
maskpp
2023-04-04 16:20:12 +08:00
committed by GitHub
parent 41e2d960d8
commit de7c38a903
2 changed files with 31 additions and 10 deletions

View File

@@ -31,6 +31,8 @@ type Cmd struct {
checkFuncs cmap.ConcurrentMap //map[string]checkFunc
// open log flag.
openLog bool
// error channel
ErrChan chan error
}
@@ -64,7 +66,7 @@ func (c *Cmd) runCmd() {
// RunCmd parallel running when parallel is true.
func (c *Cmd) RunCmd(parallel bool) {
fmt.Println("cmd: ", c.args)
fmt.Println("cmd:", c.args)
if parallel {
go c.runCmd()
} else {
@@ -72,12 +74,17 @@ func (c *Cmd) RunCmd(parallel bool) {
}
}
// OpenLog open cmd log by this api.
func (c *Cmd) OpenLog(open bool) {
c.openLog = open
}
func (c *Cmd) Write(data []byte) (int, error) {
out := string(data)
if verbose {
fmt.Printf("%s: %v", c.name, out)
if verbose || c.openLog {
fmt.Printf("%s:\n\t%v", c.name, out)
} else if strings.Contains(out, "error") || strings.Contains(out, "warning") {
fmt.Printf("%s: %v", c.name, out)
fmt.Printf("%s:\n\t%v", c.name, out)
}
go c.checkFuncs.IterCb(func(_ string, value interface{}) {
check := value.(checkFunc)

View File

@@ -78,6 +78,7 @@ func free(t *testing.T) {
}
type appAPI interface {
OpenLog(open bool)
WaitResult(t *testing.T, timeout time.Duration, keyword string) bool
RunApp(waitResult func() bool)
WaitExit()
@@ -86,33 +87,44 @@ type appAPI interface {
func runMsgRelayerApp(t *testing.T, args ...string) appAPI {
args = append(args, "--log.debug", "--config", bridgeFile)
return cmd.NewCmd("message-relayer-test", args...)
app := cmd.NewCmd("message-relayer-test", args...)
app.OpenLog(true)
return app
}
func runGasOracleApp(t *testing.T, args ...string) appAPI {
args = append(args, "--log.debug", "--config", bridgeFile)
return cmd.NewCmd("gas-oracle-test", args...)
app := cmd.NewCmd("gas-oracle-test", args...)
app.OpenLog(true)
return app
}
func runRollupRelayerApp(t *testing.T, args ...string) appAPI {
args = append(args, "--log.debug", "--config", bridgeFile)
return cmd.NewCmd("rollup-relayer-test", args...)
app := cmd.NewCmd("rollup-relayer-test", args...)
app.OpenLog(true)
return app
}
func runEventWatcherApp(t *testing.T, args ...string) appAPI {
args = append(args, "--log.debug", "--config", bridgeFile)
return cmd.NewCmd("event-watcher-test", args...)
app := cmd.NewCmd("event-watcher-test", args...)
app.OpenLog(true)
return app
}
func runCoordinatorApp(t *testing.T, args ...string) appAPI {
args = append(args, "--log.debug", "--config", coordinatorFile, "--ws", "--ws.port", strconv.Itoa(int(wsPort)))
// start process
return cmd.NewCmd("coordinator-test", args...)
app := cmd.NewCmd("coordinator-test", args...)
app.OpenLog(true)
return app
}
func runDBCliApp(t *testing.T, option, keyword string) {
args := []string{option, "--config", dbFile}
app := cmd.NewCmd("db_cli-test", args...)
app.OpenLog(true)
defer app.WaitExit()
// Wait expect result.
@@ -122,7 +134,9 @@ func runDBCliApp(t *testing.T, option, keyword string) {
func runRollerApp(t *testing.T, args ...string) appAPI {
args = append(args, "--log.debug", "--config", rollerFile)
return cmd.NewCmd("roller-test", args...)
app := cmd.NewCmd("roller-test", args...)
app.OpenLog(true)
return app
}
func runSender(t *testing.T, endpoint string) *sender.Sender {