mirror of
https://github.com/tailscale/tailscale.git
synced 2025-01-07 16:17:41 +00:00
derp/derphttp: close DERP client to avoid data race in test
Fixes #10041 Signed-off-by: Anton Tolchanov <anton@tailscale.com>
This commit is contained in:
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
|
// updates after a different thread breaks and reconnects the connection, while
|
||||||
// the watcher is waiting on recv().
|
// the watcher is waiting on recv().
|
||||||
func TestBreakWatcherConnRecv(t *testing.T) {
|
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
|
var wg sync.WaitGroup
|
||||||
defer wg.Wait()
|
defer wg.Wait()
|
||||||
// Make the watcher server
|
// Make the watcher server
|
||||||
@ -282,11 +289,6 @@ func TestBreakWatcherConnRecv(t *testing.T) {
|
|||||||
|
|
||||||
watcherChan := make(chan int, 1)
|
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)
|
// 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
|
wg.Add(1) // To avoid using t.Logf after the test ends. See https://golang.org/issue/40343
|
||||||
go func() {
|
go func() {
|
||||||
@ -329,6 +331,13 @@ func TestBreakWatcherConnRecv(t *testing.T) {
|
|||||||
// updates after a different thread breaks and reconnects the connection, while
|
// updates after a different thread breaks and reconnects the connection, while
|
||||||
// the watcher is not waiting on recv().
|
// the watcher is not waiting on recv().
|
||||||
func TestBreakWatcherConn(t *testing.T) {
|
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
|
var wg sync.WaitGroup
|
||||||
defer wg.Wait()
|
defer wg.Wait()
|
||||||
// Make the watcher server
|
// Make the watcher server
|
||||||
@ -351,11 +360,6 @@ func TestBreakWatcherConn(t *testing.T) {
|
|||||||
watcherChan := make(chan int, 1)
|
watcherChan := make(chan int, 1)
|
||||||
breakerChan := make(chan bool, 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)
|
// 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
|
wg.Add(1) // To avoid using t.Logf after the test ends. See https://golang.org/issue/40343
|
||||||
go func() {
|
go func() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user