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

Unified Diff: filter/txnBuf/txnbuf_test.go

Issue 1776833002: txnbuf: Add write count budget, size budget. (Closed) Base URL: https://chromium.googlesource.com/external/github.com/luci/gae@master
Patch Set: Created 4 years, 9 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « filter/txnBuf/state.go ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: filter/txnBuf/txnbuf_test.go
diff --git a/filter/txnBuf/txnbuf_test.go b/filter/txnBuf/txnbuf_test.go
index 4e30aef6269c811c308f49d294e0e97ac6fd461e..aabdc5ed839bbfd29a2361eb9de507968b20eb52 100644
--- a/filter/txnBuf/txnbuf_test.go
+++ b/filter/txnBuf/txnbuf_test.go
@@ -321,42 +321,74 @@ func TestTransactionBuffers(t *testing.T) {
func TestHuge(t *testing.T) {
t.Parallel()
- Convey("inner txn too big allows outer txn", t, func() {
+ Convey("testing datastore enforces thresholds", t, func() {
_, _, ds := mkds(dataMultiRoot)
- So(ds.RunInTransaction(func(c context.Context) error {
- ds := datastore.Get(c)
+ Convey("exceeding inner txn size threshold still allows outer", func() {
+ So(ds.RunInTransaction(func(c context.Context) error {
+ ds := datastore.Get(c)
+
+ So(18, fooSetTo(ds), hugeField)
+
+ So(ds.RunInTransaction(func(c context.Context) error {
+ ds := datastore.Get(c)
+ So(ds.PutMulti(hugeData), ShouldBeNil)
+ return nil
+ }, nil), ShouldErrLike, ErrTransactionTooLarge)
- So(18, fooSetTo(ds), hugeField)
+ return nil
+ }, &datastore.TransactionOptions{XG: true}), ShouldBeNil)
+ So(18, fooShouldHave(ds), hugeField)
+ })
+
+ Convey("exceeding inner txn count threshold still allows outer", func() {
So(ds.RunInTransaction(func(c context.Context) error {
ds := datastore.Get(c)
- So(ds.PutMulti(hugeData), ShouldBeNil)
- return nil
- }, nil), ShouldErrLike, ErrTransactionTooLarge)
- return nil
- }, &datastore.TransactionOptions{XG: true}), ShouldBeNil)
+ So(18, fooSetTo(ds), hugeField)
- So(18, fooShouldHave(ds), hugeField)
- })
+ So(ds.RunInTransaction(func(c context.Context) error {
+ ds := datastore.Get(c)
+ p := ds.MakeKey("mom", 1)
- Convey("outer txn too big prevents inner txn", t, func() {
- _, _, ds := mkds(dataMultiRoot)
+ // This will exceed the budget, since we've already done one write in
+ // the parent.
+ for i := 1; i <= DefaultWriteCountBudget; i++ {
+ So(ds.Put(&Foo{ID: int64(i), Parent: p}), ShouldBeNil)
+ }
+ return nil
+ }, nil), ShouldErrLike, ErrTransactionTooLarge)
- So(ds.RunInTransaction(func(c context.Context) error {
- ds := datastore.Get(c)
+ return nil
+ }, &datastore.TransactionOptions{XG: true}), ShouldBeNil)
- So(ds.PutMulti(hugeData), ShouldBeNil)
+ So(18, fooShouldHave(ds), hugeField)
+ })
+ Convey("exceeding threshold in the parent, then retreating in the child is okay", func() {
So(ds.RunInTransaction(func(c context.Context) error {
- panic("never!")
- }, nil), ShouldErrLike, ErrTransactionTooLarge)
+ ds := datastore.Get(c)
- return nil
- }, &datastore.TransactionOptions{XG: true}), ShouldBeNil)
+ So(ds.PutMulti(hugeData), ShouldBeNil)
+ So(18, fooSetTo(ds), hugeField)
- So(1, fooShouldHave(ds), hugeField)
+ // We're over threshold! But the child will delete most of this and
+ // bring us back to normal.
+ So(ds.RunInTransaction(func(c context.Context) error {
+ ds := datastore.Get(c)
+ keys := make([]*datastore.Key, len(hugeData))
+ for i, d := range hugeData {
+ keys[i] = ds.KeyForObj(d)
+ }
+ return ds.DeleteMulti(keys)
+ }, nil), ShouldBeNil)
+
+ return nil
+ }, &datastore.TransactionOptions{XG: true}), ShouldBeNil)
+
+ So(18, fooShouldHave(ds), hugeField)
+ })
})
}
« no previous file with comments | « filter/txnBuf/state.go ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698