Skip to content

Commit

Permalink
vm: refactor VM CLI tests as they take too long to pass
Browse files Browse the repository at this point in the history
These tests are slow on Windows, so refactor them a bit and avoid the following
error:
```
--- FAIL: TestRunWithDifferentArguments (4.01s)
        cli_test.go:96:
                Error Trace:    cli_test.go:96
                                                                                cli_test.go:321
                Error:          command took too long time
                Test:           TestRunWithDifferentArguments
```
  • Loading branch information
AnnaShaleva committed Feb 10, 2022
1 parent f8796f1 commit ce9e3a3
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions pkg/vm/cli/cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@ func newTestVMCLIWithLogo(t *testing.T, printLogo bool) *executor {
}

func (e *executor) runProg(t *testing.T, commands ...string) {
e.runProgWithTimeout(t, 4*time.Second, commands...)
}

func (e *executor) runProgWithTimeout(t *testing.T, timeout time.Duration, commands ...string) {
cmd := strings.Join(commands, "\n") + "\n"
e.in.WriteString(cmd + "\n")
go func() {
Expand All @@ -92,7 +96,7 @@ func (e *executor) runProg(t *testing.T, commands ...string) {
}()
select {
case <-e.ch:
case <-time.After(4 * time.Second):
case <-time.After(timeout):
require.Fail(t, "command took too long time")
}
}
Expand Down Expand Up @@ -213,7 +217,7 @@ go 1.16`)
require.NoError(t, ioutil.WriteFile(filepath.Join(tmpDir, "go.mod"), goMod, os.ModePerm))

e := newTestVMCLI(t)
e.runProg(t,
e.runProgWithTimeout(t, 10*time.Second,
"loadgo",
"loadgo "+filenameErr,
"loadgo "+filename,
Expand Down Expand Up @@ -318,7 +322,7 @@ func TestRunWithDifferentArguments(t *testing.T) {

filename = "'" + filename + "'"
e := newTestVMCLI(t)
e.runProg(t,
e.runProgWithTimeout(t, 30*time.Second,
"loadgo "+filename, "run notexists",
"loadgo "+filename, "run negate false",
"loadgo "+filename, "run negate true",
Expand Down

0 comments on commit ce9e3a3

Please sign in to comment.