From d73f95e9884fc1d1f3a0d24462fa45fce563d71d Mon Sep 17 00:00:00 2001 From: Anna Shaleva Date: Tue, 8 Feb 2022 17:03:17 +0300 Subject: [PATCH] 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"} ``` --- cli/server_test.go | 50 +++++++++++++++++++++++++--------------------- 1 file changed, 27 insertions(+), 23 deletions(-) diff --git a/cli/server_test.go b/cli/server_test.go index 308ce98fc..6b6415e01 100644 --- a/cli/server_test.go +++ b/cli/server_test.go @@ -1,11 +1,11 @@ package main import ( - "fmt" "io" "io/ioutil" "os" "path/filepath" + "runtime" "strings" "testing" "time" @@ -96,29 +96,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("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) + }) + } }