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

Side by Side Diff: impl/memory/datastore_index_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/datastore_index_selection.go ('k') | impl/memory/datastore_query_execution.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 "sort" 8 "sort"
9 "testing" 9 "testing"
10 "time" 10 "time"
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after
236 t.Parallel() 236 t.Parallel()
237 237
238 Convey("Test indexEntriesWithBuiltins", t, func() { 238 Convey("Test indexEntriesWithBuiltins", t, func() {
239 for _, tc := range rowGenTestCases { 239 for _, tc := range rowGenTestCases {
240 if tc.collections == nil { 240 if tc.collections == nil {
241 Convey(tc.name, nil) // shows up as 'skipped' 241 Convey(tc.name, nil) // shows up as 'skipped'
242 continue 242 continue
243 } 243 }
244 244
245 Convey(tc.name, func() { 245 Convey(tc.name, func() {
246 » » » » store := (*memStore)(nil) 246 » » » » store := (memStore)(nil)
247 if tc.withBuiltin { 247 if tc.withBuiltin {
248 store = indexEntriesWithBuiltins(fakeKey , tc.pmap, tc.idxs) 248 store = indexEntriesWithBuiltins(fakeKey , tc.pmap, tc.idxs)
249 } else { 249 } else {
250 sip := serialize.PropertyMapPartially(fa keKey, tc.pmap) 250 sip := serialize.PropertyMapPartially(fa keKey, tc.pmap)
251 store = indexEntries(sip, fakeKey.Namesp ace(), tc.idxs) 251 store = indexEntries(sip, fakeKey.Namesp ace(), tc.idxs)
252 } 252 }
253 for colName, vals := range tc.collections { 253 for colName, vals := range tc.collections {
254 i := 0 254 i := 0
255 » » » » » coll := store.GetCollection(colName) 255 » » » » » coll := store.Snapshot().GetCollection(c olName)
256 numItems, _ := coll.GetTotals() 256 numItems, _ := coll.GetTotals()
257 So(numItems, ShouldEqual, len(tc.collect ions[colName])) 257 So(numItems, ShouldEqual, len(tc.collect ions[colName]))
258 coll.VisitItemsAscend(nil, true, func(it m *gkvlite.Item) bool { 258 coll.VisitItemsAscend(nil, true, func(it m *gkvlite.Item) bool {
259 So(itm.Key, ShouldResemble, vals [i]) 259 So(itm.Key, ShouldResemble, vals [i])
260 i++ 260 i++
261 return true 261 return true
262 }) 262 })
263 So(i, ShouldEqual, len(vals)) 263 So(i, ShouldEqual, len(vals))
264 } 264 }
265 }) 265 })
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
347 }, 347 },
348 } 348 }
349 349
350 func TestUpdateIndexes(t *testing.T) { 350 func TestUpdateIndexes(t *testing.T) {
351 t.Parallel() 351 t.Parallel()
352 352
353 Convey("Test updateIndexes", t, func() { 353 Convey("Test updateIndexes", t, func() {
354 for _, tc := range updateIndexesTests { 354 for _, tc := range updateIndexesTests {
355 Convey(tc.name, func() { 355 Convey(tc.name, func() {
356 store := newMemStore() 356 store := newMemStore()
357 » » » » idxColl := store.SetCollection("idx", nil) 357 » » » » idxColl := store.GetOrCreateCollection("idx")
358 for _, i := range tc.idxs { 358 for _, i := range tc.idxs {
359 idxColl.Set(cat(i.PrepForIdxTable()), [] byte{}) 359 idxColl.Set(cat(i.PrepForIdxTable()), [] byte{})
360 } 360 }
361 361
362 tmpLoader := map[string]ds.PropertyMap{} 362 tmpLoader := map[string]ds.PropertyMap{}
363 for _, itm := range tc.data { 363 for _, itm := range tc.data {
364 ks := itm.key.String() 364 ks := itm.key.String()
365 prev := tmpLoader[ks] 365 prev := tmpLoader[ks]
366 updateIndexes(store, itm.key, prev, itm. props) 366 updateIndexes(store, itm.key, prev, itm. props)
367 tmpLoader[ks] = itm.props 367 tmpLoader[ks] = itm.props
368 } 368 }
369 tmpLoader = nil 369 tmpLoader = nil
370 370
371 for colName, data := range tc.expected { 371 for colName, data := range tc.expected {
372 » » » » » coll := store.GetCollection(colName) 372 » » » » » coll := store.Snapshot().GetCollection(c olName)
373 So(coll, ShouldNotBeNil) 373 So(coll, ShouldNotBeNil)
374 i := 0 374 i := 0
375 coll.VisitItemsAscend(nil, false, func(i tm *gkvlite.Item) bool { 375 coll.VisitItemsAscend(nil, false, func(i tm *gkvlite.Item) bool {
376 So(data[i], ShouldResemble, itm. Key) 376 So(data[i], ShouldResemble, itm. Key)
377 i++ 377 i++
378 return true 378 return true
379 }) 379 })
380 So(i, ShouldEqual, len(data)) 380 So(i, ShouldEqual, len(data))
381 } 381 }
382 }) 382 })
383 } 383 }
384 }) 384 })
385 } 385 }
OLDNEW
« no previous file with comments | « impl/memory/datastore_index_selection.go ('k') | impl/memory/datastore_query_execution.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698