Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(250)

Side by Side Diff: impl/memory/gkvlite_iter_test.go

Issue 1911263002: Fix memory corruption bug in impl/memory (Closed) Base URL: https://chromium.googlesource.com/external/github.com/luci/gae@master
Patch Set: fix comments Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « impl/memory/gkvlite_iter.go ('k') | impl/memory/gkvlite_tracing_utils.go » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 package memory 5 package memory
6 6
7 import ( 7 import (
8 "bytes" 8 "bytes"
9 "testing" 9 "testing"
10 10
(...skipping 16 matching lines...) Expand all
27 ret, _, err := cmpbin.ReadInt(bytes.NewBuffer(data)) 27 ret, _, err := cmpbin.ReadInt(bytes.NewBuffer(data))
28 memoryCorruption(err) 28 memoryCorruption(err)
29 29
30 return ret 30 return ret
31 } 31 }
32 32
33 func TestIterator(t *testing.T) { 33 func TestIterator(t *testing.T) {
34 t.Parallel() 34 t.Parallel()
35 35
36 s := newMemStore() 36 s := newMemStore()
37 » c := s.SetCollection("zup", nil) 37 » c := s.GetOrCreateCollection("zup")
38 prev := []byte{} 38 prev := []byte{}
39 for i := 5; i < 100; i++ { 39 for i := 5; i < 100; i++ {
40 data := mkNum(int64(i)) 40 data := mkNum(int64(i))
41 c.Set(data, prev) 41 c.Set(data, prev)
42 prev = data 42 prev = data
43 } 43 }
44 c = s.Snapshot().GetCollection("zup")
44 45
45 get := func(c C, t *iterator) interface{} { 46 get := func(c C, t *iterator) interface{} {
46 ret := interface{}(nil) 47 ret := interface{}(nil)
47 t.next(nil, func(i *gkvlite.Item) { 48 t.next(nil, func(i *gkvlite.Item) {
48 if i != nil { 49 if i != nil {
49 ret = readNum(i.Key) 50 ret = readNum(i.Key)
50 } 51 }
51 }) 52 })
52 return ret 53 return ret
53 } 54 }
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
184 for i, nms := range otherVals { 185 for i, nms := range otherVals {
185 numbs := make([][]byte, len(nms)) 186 numbs := make([][]byte, len(nms))
186 for i, n := range nms { 187 for i, n := range nms {
187 numbs[i] = mkNum(n) 188 numbs[i] = mkNum(n)
188 } 189 }
189 otherValBytes[i] = serialize.Join(numbs...) 190 otherValBytes[i] = serialize.Join(numbs...)
190 } 191 }
191 192
192 Convey("Test MultiIterator", t, func() { 193 Convey("Test MultiIterator", t, func() {
193 s := newMemStore() 194 s := newMemStore()
194 » » c := s.SetCollection("zup1", nil) 195 » » c := s.GetOrCreateCollection("zup1")
195 for _, row := range valBytes { 196 for _, row := range valBytes {
196 c.Set(row, []byte{}) 197 c.Set(row, []byte{})
197 } 198 }
198 » » c2 := s.SetCollection("zup2", nil) 199 » » c2 := s.GetOrCreateCollection("zup2")
199 for _, row := range otherValBytes { 200 for _, row := range otherValBytes {
200 c2.Set(row, []byte{}) 201 c2.Set(row, []byte{})
201 } 202 }
203 c = s.Snapshot().GetCollection("zup1")
204 c2 = s.Snapshot().GetCollection("zup2")
202 205
203 Convey("can join the same collection twice", func() { 206 Convey("can join the same collection twice", func() {
204 // get just the (1, *) 207 // get just the (1, *)
205 // starting at (1, 2) (i.e. >= 2) 208 // starting at (1, 2) (i.e. >= 2)
206 // ending at (1, 4) (i.e. < 7) 209 // ending at (1, 4) (i.e. < 7)
207 defs := []*iterDefinition{ 210 defs := []*iterDefinition{
208 {c: c, prefix: mkNum(1), prefixLen: len(mkNum(1) ), start: mkNum(2), end: mkNum(7)}, 211 {c: c, prefix: mkNum(1), prefixLen: len(mkNum(1) ), start: mkNum(2), end: mkNum(7)},
209 {c: c, prefix: mkNum(1), prefixLen: len(mkNum(1) ), start: mkNum(2), end: mkNum(7)}, 212 {c: c, prefix: mkNum(1), prefixLen: len(mkNum(1) ), start: mkNum(2), end: mkNum(7)},
210 } 213 }
211 214
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
271 So(readNum(suffix), ShouldEqual, vals[i][1]) 274 So(readNum(suffix), ShouldEqual, vals[i][1])
272 i++ 275 i++
273 return datastore.Stop 276 return datastore.Stop
274 }), shouldBeSuccessful) 277 }), shouldBeSuccessful)
275 So(i, ShouldEqual, 1) 278 So(i, ShouldEqual, 1)
276 }) 279 })
277 280
278 }) 281 })
279 282
280 } 283 }
OLDNEW
« no previous file with comments | « impl/memory/gkvlite_iter.go ('k') | impl/memory/gkvlite_tracing_utils.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698