From 6e9439d22e21b5dec2f25fe2831f71f84a805671 Mon Sep 17 00:00:00 2001 From: Nimi Wariboko Jr Date: Tue, 2 Aug 2016 12:39:15 -0700 Subject: [PATCH] Proxy: Fix data race in test. --- caddyhttp/proxy/proxy_test.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/caddyhttp/proxy/proxy_test.go b/caddyhttp/proxy/proxy_test.go index 1535cf7fd..469b4c1f6 100644 --- a/caddyhttp/proxy/proxy_test.go +++ b/caddyhttp/proxy/proxy_test.go @@ -15,6 +15,7 @@ import ( "path/filepath" "runtime" "strings" + "sync/atomic" "testing" "time" @@ -102,8 +103,8 @@ func TestReverseProxyInsecureSkipVerify(t *testing.T) { func TestWebSocketReverseProxyServeHTTPHandler(t *testing.T) { // No-op websocket backend simply allows the WS connection to be // accepted then it will be immediately closed. Perfect for testing. - var connCount int - wsNop := httptest.NewServer(websocket.Handler(func(ws *websocket.Conn) { connCount++ })) + var connCount int32 + wsNop := httptest.NewServer(websocket.Handler(func(ws *websocket.Conn) { atomic.AddInt32(&connCount, 1) })) defer wsNop.Close() // Get proxy to use for the test @@ -136,7 +137,7 @@ func TestWebSocketReverseProxyServeHTTPHandler(t *testing.T) { if !bytes.Equal(actual, expected) { t.Errorf("Expected backend to accept response:\n'%s'\nActually got:\n'%s'", expected, actual) } - if connCount != 1 { + if atomic.LoadInt32(&connCount) != 1 { t.Errorf("Expected 1 websocket connection, got %d", connCount) } }