Skip to content

Commit

Permalink
Merge pull request #375 from etclabscore/merge/foundation-release/1.1…
Browse files Browse the repository at this point in the history
…0.1-resolved-testcmd-timeout

cmd/geth,internal/cmdtest: add KillTimeout field to TestCmd struct
  • Loading branch information
meowsbits authored May 11, 2021
2 parents b9a4ddd + de739a5 commit f912896
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
1 change: 1 addition & 0 deletions cmd/geth/consolecmd_cg_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ func TestGethStartupLogs(t *testing.T) {
for i, c := range cases {
t.Run(fmt.Sprintf("TestGethStartupLogs/%d: %v", i, c.flags), func(t *testing.T) {
geth := runGeth(t, append(c.flags, "--exec", "admin.nodeInfo.name", "console")...)
geth.KillTimeout = 10 * time.Second
geth.ExpectRegexp("(?ism).*CoreGeth.*")
geth.ExpectExit()
if status := geth.ExitStatus(); status != 0 {
Expand Down
11 changes: 6 additions & 5 deletions internal/cmdtest/test_cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,17 @@ import (
)

func NewTestCmd(t *testing.T, data interface{}) *TestCmd {
return &TestCmd{T: t, Data: data}
return &TestCmd{T: t, Data: data, KillTimeout: 5 * time.Second}
}

type TestCmd struct {
// For total convenience, all testing methods are available.
*testing.T

Func template.FuncMap
Data interface{}
Cleanup func()
Func template.FuncMap
Data interface{}
Cleanup func()
KillTimeout time.Duration

cmd *exec.Cmd
stdout *bufio.Reader
Expand Down Expand Up @@ -231,7 +232,7 @@ func (tt *TestCmd) Kill() {
}

func (tt *TestCmd) withKillTimeout(fn func()) {
timeout := time.AfterFunc(5*time.Second, func() {
timeout := time.AfterFunc(tt.KillTimeout, func() {
tt.Log("killing the child process (timeout)")
tt.Kill()
})
Expand Down

0 comments on commit f912896

Please sign in to comment.