Skip to content

Commit

Permalink
testdriver: expose max errlogmatch wait time (govim#621)
Browse files Browse the repository at this point in the history
Currently we have a default errlogmatch wait time of 30s which can be
overridden by the environment variable GOVIM_ERRLOGMATCH_WAIT. But this
value is internal to the testdriver package.

In test cases in subsequent PRs we need to assert that we do not receive
a notification from gopls. This obviously means we cannot use
errlogmatch to wait for a notification. Instead we need to wait for an
indeterminate period of time and then assert we did not receive a
notification in that time. We might as well therefore wait for the
default length of time that errlogmatch waits when looking for a match.

Hence we expose DefaultErrLogMatchWait from testdriver and expose it as
an environment variable DEFAULT_ERRLOGMATCH_WAIT in all scripts so that
they can simply:

    sleep $DEFAULT_ERRLOGMATCH_WAIT

and then use errlogmatch with a count or similar.
  • Loading branch information
myitcv committed Dec 12, 2019
1 parent d1c7a12 commit 393cb5a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
1 change: 1 addition & 0 deletions cmd/govim/main_test.go
Expand Up @@ -83,6 +83,7 @@ func TestScripts(t *testing.T) {
}
home := filepath.Join(e.WorkDir, ".home")
e.Vars = append(e.Vars,
"DEFAULT_ERRLOGMATCH_WAIT="+testdriver.DefaultErrLogMatchWait,
"TMPDIR="+tmp,
"GOPROXY="+proxy.URL,
"GONOSUMDB=*",
Expand Down
23 changes: 17 additions & 6 deletions testdriver/testdriver.go
Expand Up @@ -34,6 +34,22 @@ const (
KeyErrLog = "errLog"
)

var (
DefaultErrLogMatchWait string
)

func init() {
v := os.Getenv("GOVIM_ERRLOGMATCH_WAIT")
if v == "" {
DefaultErrLogMatchWait = "30s"
} else {
if _, err := time.ParseDuration(v); err != nil {
panic(fmt.Errorf("failed to parse duration %q from GOVIM_ERRLOGMATCH_WAIT: %v", v, err))
}
DefaultErrLogMatchWait = v
}
}

// TODO - this code is a mess and needs to be fixed

type TestDriver struct {
Expand Down Expand Up @@ -796,11 +812,6 @@ func ErrLogMatch(ts *testscript.TestScript, neg bool, args []string) {
ts.Fatalf("errlogmatch %v was not the right type", KeyErrLog)
}

defaultWait := os.Getenv("GOVIM_ERRLOGMATCH_WAIT")
if defaultWait == "" {
defaultWait = "30s"
}

fs := flag.NewFlagSet("errlogmatch", flag.ContinueOnError)
fStart := fs.Bool("start", false, "search from beginning, not last snapshot")
fPeek := fs.Bool("peek", false, "do not adjust the NextSearchInx field on the errlog")
Expand All @@ -821,7 +832,7 @@ func ErrLogMatch(ts *testscript.TestScript, neg bool, args []string) {
ts.Fatalf("-wait is not compatible with negating the command")
}
if !neg && *fWait == "" {
fWait = &defaultWait
fWait = &DefaultErrLogMatchWait
}

switch {
Expand Down

0 comments on commit 393cb5a

Please sign in to comment.