@@ -6,30 +6,30 @@ import (
6
6
"testing"
7
7
)
8
8
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
-
32
9
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
+
33
33
runDBTest (t , func (dbt * DBTest ) {
34
34
oldGoroutineWrapper := GoroutineWrapper
35
35
t .Cleanup (func () {
@@ -40,7 +40,10 @@ func TestGoWrapper(t *testing.T) {
40
40
41
41
ctx := WithAsyncMode (context .Background ())
42
42
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 ()
44
47
45
48
assertTrueF (t , getGoWrapperCalled (), "channel should be closed, indicating our wrapper worked" )
46
49
})
0 commit comments