Other: Fix race conditions in internal/dialer

Some race conditions came from the tests themselves. But we had a race
condition reading the proxyAddress; this change protects it with a
mutex.
This commit is contained in:
James Houlahan
2022-10-24 16:41:17 +02:00
parent d6260d960c
commit 350544e801
3 changed files with 29 additions and 9 deletions

View File

@ -197,10 +197,16 @@ func TestProxyDialer_UseProxy_RevertAfterTime(t *testing.T) {
provider.dohLookup = func(ctx context.Context, q, p string) ([]string, error) { return []string{trustedProxy.URL}, nil }
err := d.switchToReachableServer()
require.NoError(t, err)
d.locker.Lock()
require.Equal(t, formatAsAddress(trustedProxy.URL), d.proxyAddress)
d.locker.Unlock()
time.Sleep(2 * time.Second)
d.locker.Lock()
require.Equal(t, ":443", d.proxyAddress)
d.locker.Unlock()
}
func TestProxyDialer_UseProxy_RevertIfProxyStopsWorkingAndOriginalAPIIsReachable(t *testing.T) {