...
1
16
17 package caching
18
19 import (
20 `sync`
21 `testing`
22
23 `github.com/bytedance/sonic/internal/rt`
24 )
25
26 func TestPcacheRace(t *testing.T) {
27 t.Parallel()
28
29 pc := CreateProgramCache()
30 wg := sync.WaitGroup{}
31 wg.Add(2)
32 start := make(chan struct{}, 2)
33
34 go func(){
35 defer wg.Done()
36 var k = map[string]interface{}{}
37 <- start
38 for i:=0; i<100; i++ {
39 _, _ = pc.Compute(rt.UnpackEface(k).Type, func(*rt.GoType, ... interface{}) (interface{}, error) {
40 return map[string]interface{}{}, nil
41 })
42 }
43 }()
44
45 go func(){
46 defer wg.Done()
47 var k = map[string]interface{}{}
48 <- start
49 for i:=0; i<100; i++ {
50 pc.Get(rt.UnpackEface(k).Type)
51 }
52 }()
53
54 start <- struct{}{}
55 start <- struct{}{}
56 wg.Wait()
57 }
View as plain text