From 5ce33b6eef0e1eaf355b14703a109b267d83e7cb Mon Sep 17 00:00:00 2001 From: Ox Cart Date: Wed, 28 Jan 2015 15:09:23 -0600 Subject: [PATCH] Made connectAndRead concurrent --- connpool_test.go | 31 +++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/connpool_test.go b/connpool_test.go index 5c24f11..dcb33d8 100644 --- a/connpool_test.go +++ b/connpool_test.go @@ -5,6 +5,7 @@ import ( "io/ioutil" "math/rand" "net" + "sync" "sync/atomic" "testing" "time" @@ -158,18 +159,28 @@ func TestPropertyChange(t *testing.T) { } func connectAndRead(t *testing.T, p Pool, loops int) { + var wg sync.WaitGroup + for i := 0; i < loops; i++ { - c, err := p.Get() - if err != nil { - t.Fatalf("Error getting connection: %s", err) - } - read, err := ioutil.ReadAll(c) - if err != nil { - t.Fatalf("Error reading from connection: %s", err) - } - assert.Equal(t, msg, read, "Should have received %s from server", string(msg)) - c.Close() + wg.Add(1) + + func(wg *sync.WaitGroup) { + c, err := p.Get() + if err != nil { + t.Fatalf("Error getting connection: %s", err) + } + read, err := ioutil.ReadAll(c) + if err != nil { + t.Fatalf("Error reading from connection: %s", err) + } + assert.Equal(t, msg, read, "Should have received %s from server", string(msg)) + c.Close() + + wg.Done() + }(&wg) } + + wg.Wait() } func startTestServer() (string, error) {