12 func TestSmall(t *testing.T) {
18 t.Error("Expected len 3, got ", l.Len())
21 //fmt.Printf("%p %v\n", el1, el1)
22 //fmt.Printf("%p %v\n", el2, el2)
23 //fmt.Printf("%p %v\n", el3, el3)
27 //fmt.Printf("%p %v\n", el1, el1)
28 //fmt.Printf("%p %v\n", el2, el2)
29 //fmt.Printf("%p %v\n", el3, el3)
33 //fmt.Printf("%p %v\n", el1, el1)
34 //fmt.Printf("%p %v\n", el2, el2)
35 //fmt.Printf("%p %v\n", el3, el3)
40 t.Error("Expected 1, got ", r1)
43 t.Error("Expected 2, got ", r2)
46 t.Error("Expected 3, got ", r3)
49 t.Error("Expected len 0, got ", l.Len())
55 This test is quite hacky because it relies on SetFinalizer
56 which isn't guaranteed to run at all.
59 func _TestGCFifo(t *testing.T) {
61 const numElements = 1000000
63 gcCount := new(uint64)
65 // SetFinalizer doesn't work well with circular structures,
66 // so we construct a trivial non-circular structure to
71 done := make(chan struct{})
73 for i := 0; i < numElements; i++ {
77 runtime.SetFinalizer(v, func(v *value) {
78 atomic.AddUint64(gcCount, 1)
82 for el := l.Front(); el != nil; {
91 time.Sleep(time.Second * 3)
93 time.Sleep(time.Second * 3)
96 if *gcCount != numElements {
97 t.Errorf("Expected gcCount to be %v, got %v", numElements,
103 This test is quite hacky because it relies on SetFinalizer
104 which isn't guaranteed to run at all.
107 func _TestGCRandom(t *testing.T) {
109 const numElements = 1000000
113 // SetFinalizer doesn't work well with circular structures,
114 // so we construct a trivial non-circular structure to
120 for i := 0; i < numElements; i++ {
124 runtime.SetFinalizer(v, func(v *value) {
129 els := make([]*CElement, 0, numElements)
130 for el := l.Front(); el != nil; el = el.Next() {
131 els = append(els, el)
134 for _, i := range rand.Perm(numElements) {
141 time.Sleep(time.Second * 3)
143 if gcCount != numElements {
144 t.Errorf("Expected gcCount to be %v, got %v", numElements,
149 func TestScanRightDeleteRandom(t *testing.T) {
151 const numElements = 10000
152 const numTimes = 1000
153 const numScanners = 10
156 stop := make(chan struct{})
158 els := make([]*CElement, numElements)
159 for i := 0; i < numElements; i++ {
164 // Launch scanner routines that will rapidly iterate over elements.
165 for i := 0; i < numScanners; i++ {
166 go func(scannerID int) {
174 fmt.Println("stopped")
185 fmt.Printf("Scanner %v restartCounter: %v counter: %v\n", scannerID, restartCounter, counter)
189 // Remove an element, push back an element.
190 for i := 0; i < numTimes; i++ {
191 // Pick an element to remove
192 rmElIdx := rand.Intn(len(els))
199 // Insert a new element
200 newEl := l.PushBack(-1*i - 1)
204 fmt.Printf("Pushed %vK elements so far...\n", i/1000)
211 time.Sleep(time.Second * 1)
213 // And remove all the elements.
214 for el := l.Front(); el != nil; el = el.Next() {
218 t.Fatal("Failed to remove all elements from CList")