cli: do not run test server on windows

Currently we can't properly stop running server on Windows and SIGHUP
is also not supported. This leads to occupied resources and failed
test cleanup:
```
--- FAIL: TestServerStart (0.35s)
    --- FAIL: TestServerStart/good (0.10s)
        testing.go:894: TempDir RemoveAll cleanup: remove C:\Users\Anna\AppData\Local\Temp\TestServerStart_good337747932\001\neogotestchain\000001.log:
The process cannot access the file because it is being used by another process.
2022-02-08T14:11:20.959+0300    INFO    persisted to disk       {"blocks": 0, "keys": 112, "headerHeight": 0, "blockHeight": 0, "took": "10.0049ms"}
```
This commit is contained in:
Anna Shaleva 2022-02-08 17:03:17 +03:00 committed by Anna Shaleva
parent 8ff7cd865d
commit d73f95e988

View file

@ -1,11 +1,11 @@
package main package main
import ( import (
"fmt"
"io" "io"
"io/ioutil" "io/ioutil"
"os" "os"
"path/filepath" "path/filepath"
"runtime"
"strings" "strings"
"testing" "testing"
"time" "time"
@ -96,29 +96,33 @@ func TestServerStart(t *testing.T) {
e.RunWithError(t, baseCmd...) e.RunWithError(t, baseCmd...)
}) })
}) })
t.Run("good", func(t *testing.T) { // We can't properly shutdown server on windows and release the resources.
saveCfg(t, func(cfg *config.Config) {}) // Also, windows doesn't support SIGHUP and SIGINT.
if runtime.GOOS != "windows" {
t.Run("good", func(t *testing.T) {
saveCfg(t, func(cfg *config.Config) {})
go func() { go func() {
e.Run(t, baseCmd...) e.Run(t, baseCmd...)
}() }()
var line string var line string
require.Eventually(t, func() bool { require.Eventually(t, func() bool {
line, err = e.Out.ReadString('\n') line, err = e.Out.ReadString('\n')
if err != nil && err != io.EOF { if err != nil && err != io.EOF {
t.Fatalf(fmt.Sprintf("unexpected error while reading CLI output: %s", err)) t.Fatalf("unexpected error while reading CLI output: %s", err)
}
return err == nil
}, 2*time.Second, 100*time.Millisecond)
lines := strings.Split(server.Logo(), "\n")
for _, expected := range lines {
// It should be regexp, so escape all backslashes.
expected = strings.ReplaceAll(expected, `\`, `\\`)
e.checkLine(t, line, expected)
line = e.getNextLine(t)
} }
return err == nil e.checkNextLine(t, "")
}, 2*time.Second, 100*time.Millisecond) e.checkEOF(t)
lines := strings.Split(server.Logo(), "\n") })
for _, expected := range lines { }
// It should be regexp, so escape all backslashes.
expected = strings.ReplaceAll(expected, `\`, `\\`)
e.checkLine(t, line, expected)
line = e.getNextLine(t)
}
e.checkNextLine(t, "")
e.checkEOF(t)
})
} }