forked from TrueCloudLab/neoneo-go
vm: refactor VM CLI tests as they take too long to pass
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 ```
This commit is contained in:
parent
d73f95e988
commit
a9872063fe
1 changed files with 7 additions and 3 deletions
|
@ -84,6 +84,10 @@ func newTestVMCLIWithLogo(t *testing.T, printLogo bool) *executor {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *executor) runProg(t *testing.T, commands ...string) {
|
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"
|
cmd := strings.Join(commands, "\n") + "\n"
|
||||||
e.in.WriteString(cmd + "\n")
|
e.in.WriteString(cmd + "\n")
|
||||||
go func() {
|
go func() {
|
||||||
|
@ -92,7 +96,7 @@ func (e *executor) runProg(t *testing.T, commands ...string) {
|
||||||
}()
|
}()
|
||||||
select {
|
select {
|
||||||
case <-e.ch:
|
case <-e.ch:
|
||||||
case <-time.After(4 * time.Second):
|
case <-time.After(timeout):
|
||||||
require.Fail(t, "command took too long time")
|
require.Fail(t, "command took too long time")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -213,7 +217,7 @@ go 1.16`)
|
||||||
require.NoError(t, ioutil.WriteFile(filepath.Join(tmpDir, "go.mod"), goMod, os.ModePerm))
|
require.NoError(t, ioutil.WriteFile(filepath.Join(tmpDir, "go.mod"), goMod, os.ModePerm))
|
||||||
|
|
||||||
e := newTestVMCLI(t)
|
e := newTestVMCLI(t)
|
||||||
e.runProg(t,
|
e.runProgWithTimeout(t, 10*time.Second,
|
||||||
"loadgo",
|
"loadgo",
|
||||||
"loadgo "+filenameErr,
|
"loadgo "+filenameErr,
|
||||||
"loadgo "+filename,
|
"loadgo "+filename,
|
||||||
|
@ -318,7 +322,7 @@ func TestRunWithDifferentArguments(t *testing.T) {
|
||||||
|
|
||||||
filename = "'" + filename + "'"
|
filename = "'" + filename + "'"
|
||||||
e := newTestVMCLI(t)
|
e := newTestVMCLI(t)
|
||||||
e.runProg(t,
|
e.runProgWithTimeout(t, 30*time.Second,
|
||||||
"loadgo "+filename, "run notexists",
|
"loadgo "+filename, "run notexists",
|
||||||
"loadgo "+filename, "run negate false",
|
"loadgo "+filename, "run negate false",
|
||||||
"loadgo "+filename, "run negate true",
|
"loadgo "+filename, "run negate true",
|
||||||
|
|
Loading…
Reference in a new issue