TestStressConnPool now runs for X iterations

...instead of T time. Also run in parallel.
v3-numeric-wip
Jack Christensen 2017-03-03 15:44:17 -06:00
parent 91dea95b68
commit eb484e1368
1 changed files with 9 additions and 8 deletions

View File

@ -3,11 +3,12 @@ package pgx_test
import ( import (
"errors" "errors"
"fmt" "fmt"
"golang.org/x/net/context"
"math/rand" "math/rand"
"testing" "testing"
"time" "time"
"golang.org/x/net/context"
"github.com/jackc/fake" "github.com/jackc/fake"
"github.com/jackc/pgx" "github.com/jackc/pgx"
) )
@ -23,6 +24,8 @@ type queryRower interface {
} }
func TestStressConnPool(t *testing.T) { func TestStressConnPool(t *testing.T) {
t.Parallel()
maxConnections := 8 maxConnections := 8
pool := createConnPool(t, maxConnections) pool := createConnPool(t, maxConnections)
defer pool.Close() defer pool.Close()
@ -49,11 +52,12 @@ func TestStressConnPool(t *testing.T) {
{"canceledExecContext", canceledExecContext}, {"canceledExecContext", canceledExecContext},
} }
var timer *time.Timer var actionCount int
if testing.Short() { if testing.Short() {
timer = time.NewTimer(5 * time.Second) actionCount = 1000
} else { } else {
timer = time.NewTimer(60 * time.Second) actionCount = 10000
} }
workerCount := 16 workerCount := 16
@ -77,11 +81,8 @@ func TestStressConnPool(t *testing.T) {
go work() go work()
} }
var stop bool for i := 0; i < actionCount; i++ {
for i := 0; !stop; i++ {
select { select {
case <-timer.C:
stop = true
case workChan <- i: case workChan <- i:
case err := <-errChan: case err := <-errChan:
close(workChan) close(workChan)