-
Notifications
You must be signed in to change notification settings - Fork 127
/
Copy pathfunction_wrapper_test.go
50 lines (42 loc) · 1.18 KB
/
function_wrapper_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
package gosnowflake
import (
"context"
"sync"
"testing"
)
func TestGoWrapper(t *testing.T) {
var (
goWrapperCalled = false
testGoRoutineWrapperLock sync.Mutex
)
setGoWrapperCalled := func(value bool) {
testGoRoutineWrapperLock.Lock()
defer testGoRoutineWrapperLock.Unlock()
goWrapperCalled = value
}
getGoWrapperCalled := func() bool {
testGoRoutineWrapperLock.Lock()
defer testGoRoutineWrapperLock.Unlock()
return goWrapperCalled
}
// this is the go wrapper function we are going to pass into GoroutineWrapper.
// we will know that this has been called if the channel is closed
var closeGoWrapperCalledChannel = func(ctx context.Context, f func()) {
setGoWrapperCalled(true)
f()
}
runDBTest(t, func(dbt *DBTest) {
oldGoroutineWrapper := GoroutineWrapper
t.Cleanup(func() {
GoroutineWrapper = oldGoroutineWrapper
})
GoroutineWrapper = closeGoWrapperCalledChannel
ctx := WithAsyncMode(context.Background())
rows := dbt.mustQueryContext(ctx, "SELECT 1")
assertTrueE(t, rows.Next())
var i int
assertNilF(t, rows.Scan(&i))
rows.Close()
assertTrueF(t, getGoWrapperCalled(), "channel should be closed, indicating our wrapper worked")
})
}