Skip to content

Commit

Permalink
[Fix] SIG-18794: Fix getAsync() to not panic on context exceeded + te…
Browse files Browse the repository at this point in the history
…st. (#56)
  • Loading branch information
mtoader authored and Agam Brahma committed Jun 8, 2022
1 parent 294bd4d commit 4c04398
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions async_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"context"
"fmt"
"testing"
"time"
)

func TestAsyncMode(t *testing.T) {
Expand Down Expand Up @@ -89,6 +90,7 @@ func TestMultipleAsyncQueries(t *testing.T) {

go retrieveRows(rows1, ch1)
go retrieveRows(rows2, ch2)

select {
case res := <-ch1:
t.Fatalf("value %v should not have been called earlier.", res)
Expand All @@ -100,6 +102,40 @@ func TestMultipleAsyncQueries(t *testing.T) {
})
}

func TestMultipleAsyncSuccessAndFailedQueries(t *testing.T) {
ctx := WithAsyncMode(context.Background())
ctx, cancel := context.WithTimeout(ctx, time.Second*5)
defer cancel()

s1 := "foo"
s2 := "bar"
ch1 := make(chan string)
ch2 := make(chan string)

runTests(t, dsn, func(dbt *DBTest) {
rows1 := dbt.mustQueryContext(ctx, fmt.Sprintf("select distinct '%s' from table (generator(timelimit=>3))", s1))
defer rows1.Close()

rows2 := dbt.mustQueryContext(ctx, fmt.Sprintf("select distinct '%s' from table (generator(timelimit=>7))", s2))
defer rows2.Close()

go retrieveRows(rows1, ch1)
go retrieveRows(rows2, ch2)

res1 := <-ch1
if res1 != s1 {
t.Fatalf("query failed. expected: %v, got: %v", s1, res1)
}

// wait until rows2 is done
<-ch2
driverErr, ok := rows2.Err().(*SnowflakeError)
if !ok || driverErr == nil || driverErr.Number != ErrAsync {
t.Fatalf("Snowflake ErrAsync expected. got: %T, %v", rows2.Err(), rows2.Err())
}
})
}

func retrieveRows(rows *RowsExtended, ch chan string) {
var s string
for rows.Next() {
Expand Down

0 comments on commit 4c04398

Please sign in to comment.