forked from mattn/go-oci8
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoci8_go18_test.go
77 lines (69 loc) · 1.47 KB
/
oci8_go18_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
// +build go1.8
package oci8
import (
"context"
"database/sql"
"sync"
"testing"
"time"
)
func TestNamedParam(t *testing.T) {
r := sqlstest(DB(), t, "select :foo||:bar as message from dual", sql.Named("foo", "hello"), sql.Named("bar", "world"))
if "helloworld" != r["MESSAGE"].(string) {
t.Fatal("message should be: helloworld", r)
}
}
/* FIXME
func TestOutputBind(t *testing.T) {
db := DB()
s1 := "-----------------------------"
s2 := 11
s3 := false
_, err := db.Exec(`begin :a := 42; :b := 'ddddd' ; :c := 2; end;`,
sql.Named("a", sql.Out{Dest: &s2}),
sql.Named("b", sql.Out{Dest: &s1}),
sql.Named("c", sql.Out{Dest: &s3}))
if err != nil {
t.Fatal(err)
}
s1want := "ddddd "
if s1 != s1want {
t.Fatalf("want %q but %q", s1want, s1)
}
if s2 != 42 {
t.Fatalf("want %v but %v", 42, s2)
}
if !s3 {
t.Fatalf("want %v but %v", true, s3)
}
}
*/
func TestTimeout(t *testing.T) {
db := DB()
for i := 0; i < 2000; i++ {
db.Exec("insert into foo(c3) values(:1)", i)
}
var wg sync.WaitGroup
f := func(wg *sync.WaitGroup) {
defer wg.Done()
stmt, err := db.Prepare(`select * from foo order by c3`)
if err != nil {
t.Fatal(err)
}
ctx, _ := context.WithTimeout(context.Background(), 200*time.Millisecond)
rows, err := stmt.QueryContext(ctx)
if err != nil {
t.Fatal(err)
}
defer rows.Close()
err = ctx.Err()
if err != nil {
t.Fatal(err)
}
}
for j := 0; j < 10; j++ {
wg.Add(1)
go f(&wg)
}
wg.Wait()
}