Skip to content

Commit

Permalink
querylog: fix tests for windows
Browse files Browse the repository at this point in the history
  • Loading branch information
EugeneOne1 committed Feb 8, 2021
1 parent b616ea5 commit c4af71b
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions internal/querylog/qlog_test.go
Expand Up @@ -6,6 +6,7 @@ import (
"math/rand"
"net"
"os"
"runtime"
"sort"
"testing"
"time"
Expand All @@ -26,12 +27,30 @@ func TestMain(m *testing.M) {
func prepareTestDir(t *testing.T) string {
t.Helper()

dir, err := ioutil.TempDir("", "agh-tests")
wd, err := os.Getwd()
require.Nil(t, err)

dir, err := ioutil.TempDir(wd, "agh-tests")
require.Nil(t, err)
require.NotEmpty(t, dir)

t.Cleanup(func() {
assert.Nil(t, os.RemoveAll(dir))
// TODO(e.burkov): Replace with t.TempDir methods after updating
// go version to 1.15.
start := time.Now()
for {
err := os.RemoveAll(dir)
if err == nil {
break
}

if runtime.GOOS != "windows" || time.Since(start) >= 500*time.Millisecond {
break
}
time.Sleep(5 * time.Millisecond)
}

assert.Nil(t, err)
})

return dir
Expand Down

0 comments on commit c4af71b

Please sign in to comment.