mirror of
https://github.com/AdguardTeam/AdGuardHome.git
synced 2024-11-17 10:58:29 -07:00
27f4f05273
Merge in DNS/adguard-home from imp-tests to master Squashed commit of the following: commit 6171420068d66808f069f280a81e0c60e61e5ce3 Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Thu Mar 25 17:43:36 2021 +0300 aghnet: imp test msgs commit ed2880ff03ab0e41a77f07aad2caf13bf5f4bd9f Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Thu Mar 25 17:39:44 2021 +0300 all: imp some tests
64 lines
1.3 KiB
Go
64 lines
1.3 KiB
Go
// +build windows
|
|
|
|
package aghtest
|
|
|
|
import (
|
|
"io/ioutil"
|
|
"os"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
const (
|
|
maxRetryDur = 1000 * time.Millisecond
|
|
retryDur = 5 * time.Millisecond
|
|
)
|
|
|
|
func prepareTestDir(t *testing.T) (dir string) {
|
|
// Windows, including the version of Windows Server that Github Actions
|
|
// uses, apparently likes to overly eagerly inspect new directories with
|
|
// its Windows Defender. Disabling it might require additional
|
|
// workarounds, and until we've figured it out, just retry the deletion
|
|
// until the error goes away.
|
|
//
|
|
// The code is largely inspired by the one that has been introduced into
|
|
// the go command itself. We should probably make a proposal to use the
|
|
// same mechanism in t.TempDir.
|
|
//
|
|
// See https://go-review.googlesource.com/c/go/+/172337.
|
|
//
|
|
// See https://github.com/golang/go/issues/44919.
|
|
|
|
t.Helper()
|
|
|
|
wd, err := os.Getwd()
|
|
require.NoError(t, err)
|
|
|
|
dir, err = ioutil.TempDir(wd, "agh-test")
|
|
require.NoError(t, err)
|
|
require.NotEmpty(t, dir)
|
|
|
|
t.Cleanup(func() {
|
|
start := time.Now()
|
|
for {
|
|
err = os.RemoveAll(dir)
|
|
if err == nil {
|
|
break
|
|
}
|
|
|
|
if time.Since(start) >= maxRetryDur {
|
|
break
|
|
}
|
|
|
|
time.Sleep(retryDur)
|
|
}
|
|
|
|
assert.NoError(t, err, "after %s", time.Since(start))
|
|
})
|
|
|
|
return dir
|
|
}
|