|
|
@ -64,6 +64,9 @@ func Test_NewQueueWriteBatchSizeMulti(t *testing.T) {
|
|
|
|
if len(stmts) != 5 {
|
|
|
|
if len(stmts) != 5 {
|
|
|
|
t.Fatalf("received wrong length slice")
|
|
|
|
t.Fatalf("received wrong length slice")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if q.numTimeouts != 0 {
|
|
|
|
|
|
|
|
t.Fatalf("queue timeout expired?")
|
|
|
|
|
|
|
|
}
|
|
|
|
case <-time.NewTimer(5 * time.Second).C:
|
|
|
|
case <-time.NewTimer(5 * time.Second).C:
|
|
|
|
t.Fatalf("timed out waiting for first statements")
|
|
|
|
t.Fatalf("timed out waiting for first statements")
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -79,6 +82,9 @@ func Test_NewQueueWriteBatchSizeMulti(t *testing.T) {
|
|
|
|
if len(stmts) < 5 {
|
|
|
|
if len(stmts) < 5 {
|
|
|
|
t.Fatalf("received too-short slice")
|
|
|
|
t.Fatalf("received too-short slice")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if q.numTimeouts != 0 {
|
|
|
|
|
|
|
|
t.Fatalf("queue timeout expired?")
|
|
|
|
|
|
|
|
}
|
|
|
|
case <-time.NewTimer(5 * time.Second).C:
|
|
|
|
case <-time.NewTimer(5 * time.Second).C:
|
|
|
|
t.Fatalf("timed out waiting for second statements")
|
|
|
|
t.Fatalf("timed out waiting for second statements")
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -100,6 +106,9 @@ func Test_NewQueueWriteTimeout(t *testing.T) {
|
|
|
|
if stmts[0].Sql != "SELECT * FROM foo" {
|
|
|
|
if stmts[0].Sql != "SELECT * FROM foo" {
|
|
|
|
t.Fatalf("received wrong SQL")
|
|
|
|
t.Fatalf("received wrong SQL")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if q.numTimeouts != 1 {
|
|
|
|
|
|
|
|
t.Fatalf("queue timeout didn't expire")
|
|
|
|
|
|
|
|
}
|
|
|
|
case <-time.NewTimer(5 * time.Second).C:
|
|
|
|
case <-time.NewTimer(5 * time.Second).C:
|
|
|
|
t.Fatalf("timed out waiting for statement")
|
|
|
|
t.Fatalf("timed out waiting for statement")
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -122,6 +131,9 @@ func Test_NewQueueWriteTimeoutMulti(t *testing.T) {
|
|
|
|
if stmts[0].Sql != "SELECT * FROM foo" {
|
|
|
|
if stmts[0].Sql != "SELECT * FROM foo" {
|
|
|
|
t.Fatalf("received wrong SQL")
|
|
|
|
t.Fatalf("received wrong SQL")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if q.numTimeouts != 1 {
|
|
|
|
|
|
|
|
t.Fatalf("queue timeout didn't expire")
|
|
|
|
|
|
|
|
}
|
|
|
|
case <-time.NewTimer(5 * time.Second).C:
|
|
|
|
case <-time.NewTimer(5 * time.Second).C:
|
|
|
|
t.Fatalf("timed out waiting for first statement")
|
|
|
|
t.Fatalf("timed out waiting for first statement")
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -137,6 +149,9 @@ func Test_NewQueueWriteTimeoutMulti(t *testing.T) {
|
|
|
|
if stmts[0].Sql != "SELECT * FROM foo" {
|
|
|
|
if stmts[0].Sql != "SELECT * FROM foo" {
|
|
|
|
t.Fatalf("received wrong SQL")
|
|
|
|
t.Fatalf("received wrong SQL")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if q.numTimeouts != 2 {
|
|
|
|
|
|
|
|
t.Fatalf("queue timeout didn't expire")
|
|
|
|
|
|
|
|
}
|
|
|
|
case <-time.NewTimer(5 * time.Second).C:
|
|
|
|
case <-time.NewTimer(5 * time.Second).C:
|
|
|
|
t.Fatalf("timed out waiting for second statement")
|
|
|
|
t.Fatalf("timed out waiting for second statement")
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -145,7 +160,7 @@ func Test_NewQueueWriteTimeoutMulti(t *testing.T) {
|
|
|
|
// Test_NewQueueWriteTimeoutBatch ensures that timer expiring
|
|
|
|
// Test_NewQueueWriteTimeoutBatch ensures that timer expiring
|
|
|
|
// followed by a batch, works fine.
|
|
|
|
// followed by a batch, works fine.
|
|
|
|
func Test_NewQueueWriteTimeoutBatch(t *testing.T) {
|
|
|
|
func Test_NewQueueWriteTimeoutBatch(t *testing.T) {
|
|
|
|
q := New(1024, 2, 2*time.Second)
|
|
|
|
q := New(1024, 2, 1*time.Second)
|
|
|
|
defer q.Close()
|
|
|
|
defer q.Close()
|
|
|
|
|
|
|
|
|
|
|
|
if err := q.Write(testStmt); err != nil {
|
|
|
|
if err := q.Write(testStmt); err != nil {
|
|
|
@ -160,6 +175,9 @@ func Test_NewQueueWriteTimeoutBatch(t *testing.T) {
|
|
|
|
if stmts[0].Sql != "SELECT * FROM foo" {
|
|
|
|
if stmts[0].Sql != "SELECT * FROM foo" {
|
|
|
|
t.Fatalf("received wrong SQL")
|
|
|
|
t.Fatalf("received wrong SQL")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if q.numTimeouts != 1 {
|
|
|
|
|
|
|
|
t.Fatalf("queue timeout didn't expire")
|
|
|
|
|
|
|
|
}
|
|
|
|
case <-time.NewTimer(5 * time.Second).C:
|
|
|
|
case <-time.NewTimer(5 * time.Second).C:
|
|
|
|
t.Fatalf("timed out waiting for statement")
|
|
|
|
t.Fatalf("timed out waiting for statement")
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -172,14 +190,17 @@ func Test_NewQueueWriteTimeoutBatch(t *testing.T) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
select {
|
|
|
|
select {
|
|
|
|
case stmts := <-q.C:
|
|
|
|
case stmts := <-q.C:
|
|
|
|
|
|
|
|
// Should happen before the timeout expires.
|
|
|
|
if len(stmts) != 2 {
|
|
|
|
if len(stmts) != 2 {
|
|
|
|
t.Fatalf("received wrong length slice")
|
|
|
|
t.Fatalf("received wrong length slice")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if stmts[0].Sql != "SELECT * FROM foo" {
|
|
|
|
if stmts[0].Sql != "SELECT * FROM foo" {
|
|
|
|
t.Fatalf("received wrong SQL")
|
|
|
|
t.Fatalf("received wrong SQL")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
case <-time.NewTimer(500 * time.Millisecond).C:
|
|
|
|
if q.numTimeouts != 1 {
|
|
|
|
// Should happen before the timeout expires.
|
|
|
|
t.Fatalf("queue timeout expired?")
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
case <-time.NewTimer(5 * time.Second).C:
|
|
|
|
t.Fatalf("timed out waiting for statement")
|
|
|
|
t.Fatalf("timed out waiting for statement")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|