Skip to content

Commit

Permalink
Made connectAndRead concurrent
Browse files Browse the repository at this point in the history
  • Loading branch information
oxtoacart committed Jan 28, 2015
1 parent cab2b30 commit 5ce33b6
Showing 1 changed file with 21 additions and 10 deletions.
31 changes: 21 additions & 10 deletions connpool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"io/ioutil"
"math/rand"
"net"
"sync"
"sync/atomic"
"testing"
"time"
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 5ce33b6

Please sign in to comment.