derp/derphttp: close DERP client to avoid data race in test

Fixes #10041

Signed-off-by: Anton Tolchanov <anton@tailscale.com>
pull/10060/head
Anton Tolchanov 1 year ago committed by Brad Fitzpatrick
parent 66c7af3dd3
commit c3313133b9

@ -261,6 +261,13 @@ func (c *Client) breakConnection(brokenClient *derp.Client) {
// updates after a different thread breaks and reconnects the connection, while
// the watcher is waiting on recv().
func TestBreakWatcherConnRecv(t *testing.T) {
// Set the wait time before a retry after connection failure to be much lower.
// This needs to be early in the test, for defer to run right at the end after
// the DERP client has finished.
origRetryInterval := retryInterval
retryInterval = 50 * time.Millisecond
defer func() { retryInterval = origRetryInterval }()
var wg sync.WaitGroup
defer wg.Wait()
// Make the watcher server
@ -282,11 +289,6 @@ func TestBreakWatcherConnRecv(t *testing.T) {
watcherChan := make(chan int, 1)
// Set the wait time after a connection fails to much lower
origRetryInterval := retryInterval
retryInterval = 50 * time.Millisecond
defer func() { retryInterval = origRetryInterval }()
// Start the watcher thread (which connects to the watched server)
wg.Add(1) // To avoid using t.Logf after the test ends. See https://golang.org/issue/40343
go func() {
@ -329,6 +331,13 @@ func TestBreakWatcherConnRecv(t *testing.T) {
// updates after a different thread breaks and reconnects the connection, while
// the watcher is not waiting on recv().
func TestBreakWatcherConn(t *testing.T) {
// Set the wait time before a retry after connection failure to be much lower.
// This needs to be early in the test, for defer to run right at the end after
// the DERP client has finished.
origRetryInterval := retryInterval
retryInterval = 50 * time.Millisecond
defer func() { retryInterval = origRetryInterval }()
var wg sync.WaitGroup
defer wg.Wait()
// Make the watcher server
@ -351,11 +360,6 @@ func TestBreakWatcherConn(t *testing.T) {
watcherChan := make(chan int, 1)
breakerChan := make(chan bool, 1)
// Set the wait time after a connection fails to much lower
origRetryInterval := retryInterval
retryInterval = 50 * time.Millisecond
defer func() { retryInterval = origRetryInterval }()
// Start the watcher thread (which connects to the watched server)
wg.Add(1) // To avoid using t.Logf after the test ends. See https://golang.org/issue/40343
go func() {

Loading…
Cancel
Save