forked from mitchellh/go-mruby
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gc_test.go
49 lines (36 loc) · 885 Bytes
/
gc_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
package mruby
import "testing"
func TestEnableDisableGC(t *testing.T) {
mrb := NewMrb()
defer mrb.Close()
mrb.FullGC()
mrb.DisableGC()
_, err := mrb.LoadString("b = []; a = []; a = []")
if err != nil {
t.Fatal(err)
}
orig := mrb.LiveObjectCount()
mrb.FullGC()
if orig != mrb.LiveObjectCount() {
t.Fatalf("Object count was not what was expected after full GC: %d %d", orig, mrb.LiveObjectCount())
}
mrb.EnableGC()
mrb.FullGC()
if orig-2 != mrb.LiveObjectCount() {
t.Fatalf("Object count was not what was expected after full GC: %d %d", orig-2, mrb.LiveObjectCount())
}
}
func TestIsDead(t *testing.T) {
mrb := NewMrb()
val, err := mrb.LoadString("$a = []")
if err != nil {
t.Fatal(err)
}
if val.IsDead() {
t.Fatal("Value is already dead and should not be")
}
mrb.Close()
if !val.IsDead() {
t.Fatal("Value should be dead and is not")
}
}