1
2
3
4
5
12 package main
13
14 import (
15 "io"
16 "os"
17 "runtime"
18 "runtime/pprof"
19 "sync"
20 "time"
21 )
22
23 func init() {
24 register("Cockroach6181", Cockroach6181)
25 }
26
27 type testDescriptorDB_cockroach6181 struct {
28 cache *rangeDescriptorCache_cockroach6181
29 }
30
31 func initTestDescriptorDB_cockroach6181() *testDescriptorDB_cockroach6181 {
32 return &testDescriptorDB_cockroach6181{&rangeDescriptorCache_cockroach6181{}}
33 }
34
35 type rangeDescriptorCache_cockroach6181 struct {
36 rangeCacheMu sync.RWMutex
37 }
38
39 func (rdc *rangeDescriptorCache_cockroach6181) LookupRangeDescriptor() {
40 rdc.rangeCacheMu.RLock()
41 runtime.Gosched()
42 io.Discard.Write([]byte(rdc.String()))
43 rdc.rangeCacheMu.RUnlock()
44 rdc.rangeCacheMu.Lock()
45 rdc.rangeCacheMu.Unlock()
46 }
47
48 func (rdc *rangeDescriptorCache_cockroach6181) String() string {
49 rdc.rangeCacheMu.RLock()
50 defer rdc.rangeCacheMu.RUnlock()
51 return rdc.stringLocked()
52 }
53
54 func (rdc *rangeDescriptorCache_cockroach6181) stringLocked() string {
55 return "something here"
56 }
57
58 func doLookupWithToken_cockroach6181(rc *rangeDescriptorCache_cockroach6181) {
59 rc.LookupRangeDescriptor()
60 }
61
62 func testRangeCacheCoalescedRequests_cockroach6181() {
63 db := initTestDescriptorDB_cockroach6181()
64 pauseLookupResumeAndAssert := func() {
65 var wg sync.WaitGroup
66 for i := 0; i < 3; i++ {
67 wg.Add(1)
68 go func() {
69 doLookupWithToken_cockroach6181(db.cache)
70 wg.Done()
71 }()
72 }
73 wg.Wait()
74 }
75 pauseLookupResumeAndAssert()
76 }
77
78 func Cockroach6181() {
79 prof := pprof.Lookup("goroutineleak")
80 defer func() {
81 time.Sleep(100 * time.Millisecond)
82 prof.WriteTo(os.Stdout, 2)
83 }()
84 for i := 0; i < 100; i++ {
85 go testRangeCacheCoalescedRequests_cockroach6181()
86 }
87 }
88
View as plain text