From 26f84ccc20eb92e32875eb247612a907e98d8a27 Mon Sep 17 00:00:00 2001 From: Simone Basso Date: Wed, 29 Sep 2021 20:33:39 +0200 Subject: [PATCH] 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. --- internal/netxlite/resolver_test.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/internal/netxlite/resolver_test.go b/internal/netxlite/resolver_test.go index 0e4848e..b20eca4 100644 --- a/internal/netxlite/resolver_test.go +++ b/internal/netxlite/resolver_test.go @@ -93,11 +93,12 @@ func TestResolverSystem(t *testing.T) { t.Run("with timeout and success", func(t *testing.T) { wg := &sync.WaitGroup{} wg.Add(1) + done := make(chan interface{}) r := &resolverSystem{ testableTimeout: 1 * time.Microsecond, testableLookupHost: func(ctx context.Context, domain string) ([]string, error) { defer wg.Done() - time.Sleep(1 * time.Millisecond) + <-done return []string{"8.8.8.8"}, nil }, } @@ -109,17 +110,19 @@ func TestResolverSystem(t *testing.T) { if addrs != nil { t.Fatal("invalid addrs") } + close(done) wg.Wait() }) t.Run("with timeout and failure", func(t *testing.T) { wg := &sync.WaitGroup{} wg.Add(1) + done := make(chan interface{}) r := &resolverSystem{ testableTimeout: 1 * time.Microsecond, testableLookupHost: func(ctx context.Context, domain string) ([]string, error) { defer wg.Done() - time.Sleep(1 * time.Millisecond) + <-done return nil, errors.New("no such host") }, } @@ -131,6 +134,7 @@ func TestResolverSystem(t *testing.T) { if addrs != nil { t.Fatal("invalid addrs") } + close(done) wg.Wait() })