forked from DataDog/go-python3
-
Notifications
You must be signed in to change notification settings - Fork 0
/
thread_test.go
54 lines (34 loc) · 903 Bytes
/
thread_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
51
52
53
54
package python3
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestThreadInitialization(t *testing.T) {
Py_Initialize()
PyEval_InitThreads()
assert.True(t, PyEval_ThreadsInitialized())
PyEval_ReInitThreads()
}
func TestGIL(t *testing.T) {
Py_Initialize()
PyEval_InitThreads()
gil := PyGILState_Ensure()
assert.True(t, PyGILState_Check())
PyGILState_Release(gil)
}
func TestThreadState(t *testing.T) {
Py_Initialize()
PyEval_InitThreads()
threadState := PyGILState_GetThisThreadState()
threadState2 := PyThreadState_Get()
assert.Equal(t, threadState, threadState2)
threadState3 := PyThreadState_Swap(threadState)
assert.Equal(t, threadState, threadState3)
}
func TestThreadSaveRestore(t *testing.T) {
Py_Initialize()
PyEval_InitThreads()
threadState := PyEval_SaveThread()
assert.False(t, PyGILState_Check())
PyEval_RestoreThread(threadState)
}