OLD | NEW |
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 datastore | 5 package datastore |
6 | 6 |
7 import ( | 7 import ( |
8 "math" | 8 "math" |
9 "testing" | 9 "testing" |
10 | 10 |
| 11 "github.com/luci/luci-go/common/parallel" |
11 . "github.com/luci/luci-go/common/testing/assertions" | 12 . "github.com/luci/luci-go/common/testing/assertions" |
12 . "github.com/smartystreets/goconvey/convey" | 13 . "github.com/smartystreets/goconvey/convey" |
13 ) | 14 ) |
14 | 15 |
15 const ( | 16 const ( |
16 MaxUint = ^uint(0) | 17 MaxUint = ^uint(0) |
17 MaxInt = int(MaxUint >> 1) | 18 MaxInt = int(MaxUint >> 1) |
18 IntIs32Bits = int64(MaxInt) < math.MaxInt64 | 19 IntIs32Bits = int64(MaxInt) < math.MaxInt64 |
19 ) | 20 ) |
20 | 21 |
(...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
333 So(err, ShouldBeNil) | 334 So(err, ShouldBeNil) |
334 | 335 |
335 fq.original = nil | 336 fq.original = nil |
336 fq2.original = nil | 337 fq2.original = nil |
337 So(fq, ShouldResemble, fq2) | 338 So(fq, ShouldResemble, fq2) |
338 } | 339 } |
339 }) | 340 }) |
340 } | 341 } |
341 }) | 342 }) |
342 } | 343 } |
| 344 |
| 345 func TestQueryConcurrencySafety(t *testing.T) { |
| 346 t.Parallel() |
| 347 |
| 348 Convey("query and derivative query finalization is goroutine-safe", t, f
unc() { |
| 349 const rounds = 10 |
| 350 |
| 351 q := NewQuery("Foo") |
| 352 |
| 353 err := parallel.FanOutIn(func(outerC chan<- func() error) { |
| 354 |
| 355 for i := 0; i < rounds; i++ { |
| 356 outerQ := q.Gt("Field", i) |
| 357 |
| 358 // Finalize the original query. |
| 359 outerC <- func() error { |
| 360 _, err := q.Finalize() |
| 361 return err |
| 362 } |
| 363 |
| 364 // Finalize the derivative query a lot. |
| 365 outerC <- func() error { |
| 366 return parallel.FanOutIn(func(innerC cha
n<- func() error) { |
| 367 for i := 0; i < rounds; i++ { |
| 368 innerC <- func() error { |
| 369 _, err := outerQ
.Finalize() |
| 370 return err |
| 371 } |
| 372 } |
| 373 }) |
| 374 } |
| 375 } |
| 376 }) |
| 377 So(err, ShouldBeNil) |
| 378 }) |
| 379 } |
OLD | NEW |