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

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

Issue 1366793002: Add Consistent(bool) to Testing interface (Closed) Base URL: https://github.com/luci/gae.git@move_serialization_helpers
Patch Set: Created 5 years, 3 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
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 "fmt" 8 "fmt"
9 "testing" 9 "testing"
10 "time" 10 "time"
(...skipping 439 matching lines...) Expand 10 before | Expand all | Expand 10 after
450 calls := 0 450 calls := 0
451 So(ds.RunInTransaction(func(c co ntext.Context) error { 451 So(ds.RunInTransaction(func(c co ntext.Context) error {
452 calls++ 452 calls++
453 return fmt.Errorf("omg") 453 return fmt.Errorf("omg")
454 }, nil).Error(), ShouldEqual, "o mg") 454 }, nil).Error(), ShouldEqual, "o mg")
455 So(calls, ShouldEqual, 1) 455 So(calls, ShouldEqual, 1)
456 }) 456 })
457 }) 457 })
458 }) 458 })
459 }) 459 })
460
461 Convey("Testable.Consistent", func() {
462 Convey("false", func() {
463 ds.Testable().Consistent(false) // the default
464 for i := 0; i < 10; i++ {
465 So(ds.Put(&Foo{ID: int64(i + 1), Val: i + 1}), ShouldBeNil)
466 }
467 q := dsS.NewQuery("Foo").Gt("Val", 3)
468 count, err := ds.Count(q)
469 So(err, ShouldBeNil)
470 So(count, ShouldEqual, 0)
471
472 ds.Delete(ds.MakeKey("Foo", 4))
473
474 count, err = ds.Count(q)
475 So(err, ShouldBeNil)
476 So(count, ShouldEqual, 0)
477
478 ds.Testable().Consistent(true)
479 count, err = ds.Count(q)
480 So(err, ShouldBeNil)
481 So(count, ShouldEqual, 6)
482 })
483
484 Convey("true", func() {
485 ds.Testable().Consistent(true)
486 for i := 0; i < 10; i++ {
487 So(ds.Put(&Foo{ID: int64(i + 1), Val: i + 1}), ShouldBeNil)
488 }
489 q := dsS.NewQuery("Foo").Gt("Val", 3)
490 count, err := ds.Count(q)
491 So(err, ShouldBeNil)
492 So(count, ShouldEqual, 7)
493
494 ds.Delete(ds.MakeKey("Foo", 4))
495
496 count, err = ds.Count(q)
497 So(err, ShouldBeNil)
498 So(count, ShouldEqual, 6)
499 })
500 })
460 }) 501 })
461 } 502 }
462 503
463 func TestCompoundIndexes(t *testing.T) { 504 func TestCompoundIndexes(t *testing.T) {
464 t.Parallel() 505 t.Parallel()
465 506
466 idxKey := func(def dsS.IndexDefinition) string { 507 idxKey := func(def dsS.IndexDefinition) string {
467 So(def, ShouldNotBeNil) 508 So(def, ShouldNotBeNil)
468 return "idx::" + string(serialize.ToBytes(*def.PrepForIdxTable() )) 509 return "idx::" + string(serialize.ToBytes(*def.PrepForIdxTable() ))
469 } 510 }
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
527 ds := dsS.Get(Use(context.Background())) 568 ds := dsS.Get(Use(context.Background()))
528 m := Model{ID: 1} 569 m := Model{ID: 1}
529 So(ds.Put(&m), ShouldBeNil) 570 So(ds.Put(&m), ShouldBeNil)
530 571
531 // Reset to something non zero to ensure zero is fetched. 572 // Reset to something non zero to ensure zero is fetched.
532 m.Time = time.Now().UTC() 573 m.Time = time.Now().UTC()
533 So(ds.Get(&m), ShouldBeNil) 574 So(ds.Get(&m), ShouldBeNil)
534 So(m.Time.IsZero(), ShouldBeTrue) 575 So(m.Time.IsZero(), ShouldBeTrue)
535 }) 576 })
536 } 577 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698