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

Unified Diff: service/datastore/query_test.go

Issue 1910293002: Remove race from query finalization. (Closed) Base URL: https://chromium.googlesource.com/external/github.com/luci/gae@master
Patch Set: 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 side-by-side diff with in-line comments
Download patch
« service/datastore/query.go ('K') | « service/datastore/query.go ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: service/datastore/query_test.go
diff --git a/service/datastore/query_test.go b/service/datastore/query_test.go
index 2a1ab97335b5638e4858e646cad5840c697aaaa2..606b4edde274e3b7a3df513b3420386266cd0919 100644
--- a/service/datastore/query_test.go
+++ b/service/datastore/query_test.go
@@ -8,6 +8,7 @@ import (
"math"
"testing"
+ "github.com/luci/luci-go/common/parallel"
. "github.com/luci/luci-go/common/testing/assertions"
. "github.com/smartystreets/goconvey/convey"
)
@@ -340,3 +341,39 @@ func TestQueries(t *testing.T) {
}
})
}
+
+func TestQueryConcurrencySafety(t *testing.T) {
+ t.Parallel()
+
+ Convey("query and derivative query finalization is goroutine-safe", t, func() {
+ const rounds = 10
+
+ q := NewQuery("Foo")
+
+ err := parallel.FanOutIn(func(outerC chan<- func() error) {
+
+ for i := 0; i < rounds; i++ {
+ outerQ := q.Gt("Field", i)
+
+ // Finalize the original query.
+ outerC <- func() error {
+ _, err := q.Finalize()
+ return err
+ }
+
+ // Finalize the derivative query a lot.
+ outerC <- func() error {
+ return parallel.FanOutIn(func(innerC chan<- func() error) {
+ for i := 0; i < rounds; i++ {
+ innerC <- func() error {
+ _, err := outerQ.Finalize()
+ return err
+ }
+ }
+ })
+ }
+ }
+ })
+ So(err, ShouldBeNil)
+ })
+}
« service/datastore/query.go ('K') | « service/datastore/query.go ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698