Skip to content

Commit

Permalink
NO-SNOW Fix TestGoWrapper
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-pfus committed Nov 27, 2024
1 parent 1f8ab79 commit 7ef70c2
Showing 1 changed file with 27 additions and 24 deletions.
51 changes: 27 additions & 24 deletions function_wrapper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,30 +6,30 @@ import (
"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) {
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() {
Expand All @@ -40,7 +40,10 @@ func TestGoWrapper(t *testing.T) {

ctx := WithAsyncMode(context.Background())
rows := dbt.mustQueryContext(ctx, "SELECT 1")
defer rows.Close()
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")
})
Expand Down

0 comments on commit 7ef70c2

Please sign in to comment.