-
Notifications
You must be signed in to change notification settings - Fork 125
/
function_wrapper_test.go
47 lines (39 loc) · 1.09 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
package gosnowflake
import (
"context"
"sync"
"testing"
)
var (
goWrapperCalled = false
testGoRoutineWrapperLock sync.Mutex
)
func setGoWrapperCalled(value bool) {
testGoRoutineWrapperLock.Lock()
defer testGoRoutineWrapperLock.Unlock()
goWrapperCalled = value
}
func getGoWrapperCalled() 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()
}
func TestGoWrapper(t *testing.T) {
runDBTest(t, func(dbt *DBTest) {
oldGoroutineWrapper := GoroutineWrapper
t.Cleanup(func() {
GoroutineWrapper = oldGoroutineWrapper
})
GoroutineWrapper = closeGoWrapperCalledChannel
ctx := WithAsyncMode(context.Background())
rows := dbt.mustQueryContext(ctx, "SELECT 1")
defer rows.Close()
assertTrueF(t, getGoWrapperCalled(), "channel should be closed, indicating our wrapper worked")
})
}