From 5d6392b65d25818f52a19c23d4a2f7bb5716fdb3 Mon Sep 17 00:00:00 2001 From: Josh Rickmar Date: Wed, 16 Mar 2016 11:55:27 -0400 Subject: [PATCH] Fix race in TestThrottle test. Closes #355. --- rpc/legacyrpc/rpcserver_test.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/rpc/legacyrpc/rpcserver_test.go b/rpc/legacyrpc/rpcserver_test.go index 570092f..bb4e0b1 100644 --- a/rpc/legacyrpc/rpcserver_test.go +++ b/rpc/legacyrpc/rpcserver_test.go @@ -9,15 +9,15 @@ import ( "net/http/httptest" "reflect" "testing" - "time" ) func TestThrottle(t *testing.T) { const threshold = 1 + busy := make(chan struct{}) srv := httptest.NewServer(throttledFn(threshold, func(w http.ResponseWriter, r *http.Request) { - time.Sleep(20 * time.Millisecond) + <-busy }), ) @@ -35,6 +35,10 @@ func TestThrottle(t *testing.T) { got := make(map[int]int, cap(codes)) for i := 0; i < cap(codes); i++ { got[<-codes]++ + + if i == 0 { + close(busy) + } } want := map[int]int{200: 1, 429: 1}