|
|
|
@ -11,10 +11,8 @@ import (
|
|
|
|
|
var (
|
|
|
|
|
testStmtFoo = &command.Statement{Sql: "SELECT * FROM foo"}
|
|
|
|
|
testStmtBar = &command.Statement{Sql: "SELECT * FROM bar"}
|
|
|
|
|
testStmtQux = &command.Statement{Sql: "SELECT * FROM qux"}
|
|
|
|
|
testStmtsFoo = []*command.Statement{testStmtFoo}
|
|
|
|
|
testStmtsBar = []*command.Statement{testStmtBar}
|
|
|
|
|
testStmtsNilFoo = []*command.Statement{nil, testStmtFoo}
|
|
|
|
|
testStmtsFooBar = []*command.Statement{testStmtFoo, testStmtBar}
|
|
|
|
|
testStmtsFooBarFoo = []*command.Statement{testStmtFoo, testStmtBar, testStmtFoo}
|
|
|
|
|
flushChan1 = make(FlushChannel)
|
|
|
|
@ -63,13 +61,6 @@ func Test_MergeQueuedStatements(t *testing.T) {
|
|
|
|
|
},
|
|
|
|
|
exp: &Request{2, testStmtsFooBarFoo, nil},
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
qs: []*queuedStatements{
|
|
|
|
|
{1, testStmtsFooBar, nil},
|
|
|
|
|
{2, testStmtsFoo, nil},
|
|
|
|
|
},
|
|
|
|
|
exp: &Request{2, testStmtsFooBarFoo, nil},
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
qs: []*queuedStatements{
|
|
|
|
|
{1, testStmtsFooBar, flushChan1},
|
|
|
|
@ -156,7 +147,7 @@ func Test_NewQueueWriteBatchSizeSingle(t *testing.T) {
|
|
|
|
|
if req.Statements[0].Sql != "SELECT * FROM foo" {
|
|
|
|
|
t.Fatalf("received wrong SQL")
|
|
|
|
|
}
|
|
|
|
|
case <-time.NewTimer(5 * time.Second).C:
|
|
|
|
|
case <-time.After(5 * time.Second):
|
|
|
|
|
t.Fatalf("timed out waiting for statement")
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -181,7 +172,7 @@ func Test_NewQueueWriteBatchSizeDouble(t *testing.T) {
|
|
|
|
|
if req.Statements[0].Sql != "SELECT * FROM foo" {
|
|
|
|
|
t.Fatalf("received wrong SQL")
|
|
|
|
|
}
|
|
|
|
|
case <-time.NewTimer(5 * time.Second).C:
|
|
|
|
|
case <-time.After(5 * time.Second):
|
|
|
|
|
t.Fatalf("timed out waiting for statement")
|
|
|
|
|
}
|
|
|
|
|
select {
|
|
|
|
@ -192,7 +183,7 @@ func Test_NewQueueWriteBatchSizeDouble(t *testing.T) {
|
|
|
|
|
if req.Statements[0].Sql != "SELECT * FROM bar" {
|
|
|
|
|
t.Fatalf("received wrong SQL")
|
|
|
|
|
}
|
|
|
|
|
case <-time.NewTimer(5 * time.Second).C:
|
|
|
|
|
case <-time.After(5 * time.Second):
|
|
|
|
|
t.Fatalf("timed out waiting for statement")
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -214,7 +205,7 @@ func Test_NewQueueWriteNilAndOne(t *testing.T) {
|
|
|
|
|
t.Fatalf("received wrong length slice, exp %d, got %d", exp, got)
|
|
|
|
|
}
|
|
|
|
|
req.Close()
|
|
|
|
|
case <-time.NewTimer(5 * time.Second).C:
|
|
|
|
|
case <-time.After(5 * time.Second):
|
|
|
|
|
t.Fatalf("timed out waiting for statement")
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -237,7 +228,7 @@ func Test_NewQueueWriteBatchSizeSingleChan(t *testing.T) {
|
|
|
|
|
t.Fatalf("received wrong SQL")
|
|
|
|
|
}
|
|
|
|
|
req.Close()
|
|
|
|
|
case <-time.NewTimer(5 * time.Second).C:
|
|
|
|
|
case <-time.After(5 * time.Second):
|
|
|
|
|
t.Fatalf("timed out waiting for statement")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -268,7 +259,7 @@ func Test_NewQueueWriteNilSingleChan(t *testing.T) {
|
|
|
|
|
t.Fatalf("flush chans is not correct")
|
|
|
|
|
}
|
|
|
|
|
req.Close()
|
|
|
|
|
case <-time.NewTimer(5 * time.Second).C:
|
|
|
|
|
case <-time.After(5 * time.Second):
|
|
|
|
|
t.Fatalf("timed out waiting for statement")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -299,7 +290,7 @@ func Test_NewQueueWriteBatchSizeMulti(t *testing.T) {
|
|
|
|
|
if q.numTimeouts != 0 {
|
|
|
|
|
t.Fatalf("queue timeout expired?")
|
|
|
|
|
}
|
|
|
|
|
case <-time.NewTimer(5 * time.Second).C:
|
|
|
|
|
case <-time.After(5 * time.Second):
|
|
|
|
|
t.Fatalf("timed out waiting for first statements")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -317,7 +308,7 @@ func Test_NewQueueWriteBatchSizeMulti(t *testing.T) {
|
|
|
|
|
if q.numTimeouts != 0 {
|
|
|
|
|
t.Fatalf("queue timeout expired?")
|
|
|
|
|
}
|
|
|
|
|
case <-time.NewTimer(5 * time.Second).C:
|
|
|
|
|
case <-time.After(5 * time.Second):
|
|
|
|
|
t.Fatalf("timed out waiting for second statements")
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -341,7 +332,7 @@ func Test_NewQueueWriteTimeout(t *testing.T) {
|
|
|
|
|
if q.numTimeouts != 1 {
|
|
|
|
|
t.Fatalf("queue timeout didn't expire")
|
|
|
|
|
}
|
|
|
|
|
case <-time.NewTimer(5 * time.Second).C:
|
|
|
|
|
case <-time.After(5 * time.Second):
|
|
|
|
|
t.Fatalf("timed out waiting for statement")
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -366,7 +357,7 @@ func Test_NewQueueWriteTimeoutMulti(t *testing.T) {
|
|
|
|
|
if q.numTimeouts != 1 {
|
|
|
|
|
t.Fatalf("queue timeout didn't expire")
|
|
|
|
|
}
|
|
|
|
|
case <-time.NewTimer(5 * time.Second).C:
|
|
|
|
|
case <-time.After(5 * time.Second):
|
|
|
|
|
t.Fatalf("timed out waiting for first statement")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -384,7 +375,7 @@ func Test_NewQueueWriteTimeoutMulti(t *testing.T) {
|
|
|
|
|
if q.numTimeouts != 2 {
|
|
|
|
|
t.Fatalf("queue timeout didn't expire")
|
|
|
|
|
}
|
|
|
|
|
case <-time.NewTimer(5 * time.Second).C:
|
|
|
|
|
case <-time.After(5 * time.Second):
|
|
|
|
|
t.Fatalf("timed out waiting for second statement")
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -410,7 +401,7 @@ func Test_NewQueueWriteTimeoutBatch(t *testing.T) {
|
|
|
|
|
if q.numTimeouts != 1 {
|
|
|
|
|
t.Fatalf("queue timeout didn't expire")
|
|
|
|
|
}
|
|
|
|
|
case <-time.NewTimer(5 * time.Second).C:
|
|
|
|
|
case <-time.After(5 * time.Second):
|
|
|
|
|
t.Fatalf("timed out waiting for statement")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -432,7 +423,7 @@ func Test_NewQueueWriteTimeoutBatch(t *testing.T) {
|
|
|
|
|
if q.numTimeouts != 1 {
|
|
|
|
|
t.Fatalf("queue timeout expired?")
|
|
|
|
|
}
|
|
|
|
|
case <-time.NewTimer(5 * time.Second).C:
|
|
|
|
|
case <-time.After(5 * time.Second):
|
|
|
|
|
t.Fatalf("timed out waiting for statement")
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|