From 393cb5a4d686ee3e9a0ef7fe086e7e61011cec47 Mon Sep 17 00:00:00 2001 From: Paul Jolly Date: Thu, 12 Dec 2019 11:42:50 +0000 Subject: [PATCH] testdriver: expose max errlogmatch wait time (#621) 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. --- cmd/govim/main_test.go | 1 + testdriver/testdriver.go | 23 +++++++++++++++++------ 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/cmd/govim/main_test.go b/cmd/govim/main_test.go index e3f68be9d..bfeb5d011 100644 --- a/cmd/govim/main_test.go +++ b/cmd/govim/main_test.go @@ -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=*", diff --git a/testdriver/testdriver.go b/testdriver/testdriver.go index fb740846f..d2ab6cefd 100644 --- a/testdriver/testdriver.go +++ b/testdriver/testdriver.go @@ -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 { @@ -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") @@ -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 {