Skip to content

Commit 171ddf2

Browse files
authored
NO-SNOW Fix TestGoWrapper (snowflakedb#1257)
1 parent 1f8ab79 commit 171ddf2

File tree

1 file changed

+27
-24
lines changed

1 file changed

+27
-24
lines changed

function_wrapper_test.go

Lines changed: 27 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -6,30 +6,30 @@ import (
66
"testing"
77
)
88

9-
var (
10-
goWrapperCalled = false
11-
testGoRoutineWrapperLock sync.Mutex
12-
)
13-
14-
func setGoWrapperCalled(value bool) {
15-
testGoRoutineWrapperLock.Lock()
16-
defer testGoRoutineWrapperLock.Unlock()
17-
goWrapperCalled = value
18-
}
19-
func getGoWrapperCalled() bool {
20-
testGoRoutineWrapperLock.Lock()
21-
defer testGoRoutineWrapperLock.Unlock()
22-
return goWrapperCalled
23-
}
24-
25-
// this is the go wrapper function we are going to pass into GoroutineWrapper.
26-
// we will know that this has been called if the channel is closed
27-
var closeGoWrapperCalledChannel = func(ctx context.Context, f func()) {
28-
setGoWrapperCalled(true)
29-
f()
30-
}
31-
329
func TestGoWrapper(t *testing.T) {
10+
var (
11+
goWrapperCalled = false
12+
testGoRoutineWrapperLock sync.Mutex
13+
)
14+
15+
setGoWrapperCalled := func(value bool) {
16+
testGoRoutineWrapperLock.Lock()
17+
defer testGoRoutineWrapperLock.Unlock()
18+
goWrapperCalled = value
19+
}
20+
getGoWrapperCalled := func() bool {
21+
testGoRoutineWrapperLock.Lock()
22+
defer testGoRoutineWrapperLock.Unlock()
23+
return goWrapperCalled
24+
}
25+
26+
// this is the go wrapper function we are going to pass into GoroutineWrapper.
27+
// we will know that this has been called if the channel is closed
28+
var closeGoWrapperCalledChannel = func(ctx context.Context, f func()) {
29+
setGoWrapperCalled(true)
30+
f()
31+
}
32+
3333
runDBTest(t, func(dbt *DBTest) {
3434
oldGoroutineWrapper := GoroutineWrapper
3535
t.Cleanup(func() {
@@ -40,7 +40,10 @@ func TestGoWrapper(t *testing.T) {
4040

4141
ctx := WithAsyncMode(context.Background())
4242
rows := dbt.mustQueryContext(ctx, "SELECT 1")
43-
defer rows.Close()
43+
assertTrueE(t, rows.Next())
44+
var i int
45+
assertNilF(t, rows.Scan(&i))
46+
rows.Close()
4447

4548
assertTrueF(t, getGoWrapperCalled(), "channel should be closed, indicating our wrapper worked")
4649
})

0 commit comments

Comments
 (0)