-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmap_test.go
More file actions
50 lines (45 loc) · 776 Bytes
/
Copy pathmap_test.go
File metadata and controls
50 lines (45 loc) · 776 Bytes
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
package weakref_test
import (
"testing"
"time"
"runtime"
weakref "github.com/kmcsr/go-weakref"
)
func TestMap(t *testing.T){
type T struct{ byte }
m := weakref.NewMap()
m.Set(1, &T{})
m.GetOrSet(2, func()(interface{}){
var t T
return &t
})
t.Log("map:", m)
runtime.GC()
t.Log("=== After GC")
t.Log("map:", m)
}
func TestSyncMap(t *testing.T){
type T struct{ int }
m := weakref.NewMap()
for i := 0; i < 1000; i++ {
v := &T{i}
m.Set(i, v)
j := i
go func() {
time.Sleep(time.Millisecond * 20)
m.Pop(j)
}()
}
time.Sleep(time.Millisecond * 40)
}
func TestForEachMap(t *testing.T){
type T struct{ int }
m := weakref.NewMap()
for i := 0; i < 20; i++ {
v := &T{i}
m.Set(i, v)
}
for k, v := range m.AsMap() {
_, _ = k, v.(*T)
}
}