fix(resolver_test.go): remove race and make deterministic (#524)
Should fix https://github.com/ooni/probe-cli/pull/523#issuecomment-930430124. Work part of https://github.com/ooni/probe-cli/pull/506.
This commit is contained in:
parent
b2b1a4b2f1
commit
26f84ccc20
|
@ -93,11 +93,12 @@ func TestResolverSystem(t *testing.T) {
|
||||||
t.Run("with timeout and success", func(t *testing.T) {
|
t.Run("with timeout and success", func(t *testing.T) {
|
||||||
wg := &sync.WaitGroup{}
|
wg := &sync.WaitGroup{}
|
||||||
wg.Add(1)
|
wg.Add(1)
|
||||||
|
done := make(chan interface{})
|
||||||
r := &resolverSystem{
|
r := &resolverSystem{
|
||||||
testableTimeout: 1 * time.Microsecond,
|
testableTimeout: 1 * time.Microsecond,
|
||||||
testableLookupHost: func(ctx context.Context, domain string) ([]string, error) {
|
testableLookupHost: func(ctx context.Context, domain string) ([]string, error) {
|
||||||
defer wg.Done()
|
defer wg.Done()
|
||||||
time.Sleep(1 * time.Millisecond)
|
<-done
|
||||||
return []string{"8.8.8.8"}, nil
|
return []string{"8.8.8.8"}, nil
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -109,17 +110,19 @@ func TestResolverSystem(t *testing.T) {
|
||||||
if addrs != nil {
|
if addrs != nil {
|
||||||
t.Fatal("invalid addrs")
|
t.Fatal("invalid addrs")
|
||||||
}
|
}
|
||||||
|
close(done)
|
||||||
wg.Wait()
|
wg.Wait()
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("with timeout and failure", func(t *testing.T) {
|
t.Run("with timeout and failure", func(t *testing.T) {
|
||||||
wg := &sync.WaitGroup{}
|
wg := &sync.WaitGroup{}
|
||||||
wg.Add(1)
|
wg.Add(1)
|
||||||
|
done := make(chan interface{})
|
||||||
r := &resolverSystem{
|
r := &resolverSystem{
|
||||||
testableTimeout: 1 * time.Microsecond,
|
testableTimeout: 1 * time.Microsecond,
|
||||||
testableLookupHost: func(ctx context.Context, domain string) ([]string, error) {
|
testableLookupHost: func(ctx context.Context, domain string) ([]string, error) {
|
||||||
defer wg.Done()
|
defer wg.Done()
|
||||||
time.Sleep(1 * time.Millisecond)
|
<-done
|
||||||
return nil, errors.New("no such host")
|
return nil, errors.New("no such host")
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -131,6 +134,7 @@ func TestResolverSystem(t *testing.T) {
|
||||||
if addrs != nil {
|
if addrs != nil {
|
||||||
t.Fatal("invalid addrs")
|
t.Fatal("invalid addrs")
|
||||||
}
|
}
|
||||||
|
close(done)
|
||||||
wg.Wait()
|
wg.Wait()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user