forked from yuin/gopher-lua
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathinterrupt_test.go
58 lines (56 loc) · 951 Bytes
/
interrupt_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
55
56
57
58
package lua
import (
"context"
"testing"
"time"
)
func Benchmark_Test_loop_close(b *testing.B) {
var s1 = `
function f()
while true do
print("Hello World")
end
end
f()
`
var luaVM = NewState()
ctx, cancel := context.WithCancel(context.Background())
luaVM.SetContext(ctx)
go func() {
err := luaVM.DoString(s1)
if err != nil {
b.Fail()
}
}()
time.Sleep(1 * time.Second)
cancel()
b.Log("luaVM.cancel()")
luaVM.Close()
b.Log("luaVM.Close()")
time.Sleep(2 * time.Second)
}
func Test_loop_close(t *testing.T) {
var s1 = `
function f()
while true do
-- print("Hello World")
end
end
f()
`
var luaVM = NewState()
ctx, cancel := context.WithCancel(context.Background())
luaVM.SetContext(ctx)
go func() {
err := luaVM.DoString(s1)
if err != nil {
t.Fail()
}
}()
time.Sleep(1 * time.Second)
cancel()
t.Log("luaVM.cancel()")
luaVM.Close()
t.Log("luaVM.Close()")
time.Sleep(2 * time.Second)
}