Skip to content

Commit

Permalink
cli: do not run test server on windows
Browse files Browse the repository at this point in the history
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"}
```
  • Loading branch information
AnnaShaleva committed Feb 8, 2022
1 parent 22ea3fb commit eedeb77
Showing 1 changed file with 27 additions and 22 deletions.
49 changes: 27 additions & 22 deletions cli/server_test.go
Expand Up @@ -6,6 +6,7 @@ import (
"io/ioutil"
"os"
"path/filepath"
"runtime"
"strings"
"testing"
"time"
Expand Down Expand Up @@ -96,29 +97,33 @@ func TestServerStart(t *testing.T) {
e.RunWithError(t, baseCmd...)
})
})
t.Run("good", func(t *testing.T) {
saveCfg(t, func(cfg *config.Config) {})
// We can't properly shutdown server on windows and release the resources.
// 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() {
e.Run(t, baseCmd...)
}()
go func() {
e.Run(t, baseCmd...)
}()

var line string
require.Eventually(t, func() bool {
line, err = e.Out.ReadString('\n')
if err != nil && err != io.EOF {
t.Fatalf(fmt.Sprintf("unexpected error while reading CLI output: %s", err))
var line string
require.Eventually(t, func() bool {
line, err = e.Out.ReadString('\n')
if err != nil && err != io.EOF {
t.Fatalf(fmt.Sprintf("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
}, 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)
}
e.checkNextLine(t, "")
e.checkEOF(t)
})
e.checkNextLine(t, "")
e.checkEOF(t)
})
}
}

0 comments on commit eedeb77

Please sign in to comment.