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

Side by Side Diff: filter/txnBuf/race_test.go

Issue 1437553002: Add some race-detector tests (Closed) Base URL: https://github.com/luci/gae.git@master
Patch Set: upload Created 5 years, 1 month 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 | « no previous file | impl/memory/race_test.go » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 package txnBuf
6
7 import (
8 "sync"
9 "testing"
10
11 "github.com/luci/gae/impl/memory"
12 "github.com/luci/gae/service/datastore"
13 "golang.org/x/net/context"
14 )
15
16 type Counter struct {
17 ID int64 `gae:"$id"`
18
19 Value int64
20 }
21
22 func TestRace(t *testing.T) {
23 t.Parallel()
24
25 c := FilterRDS(memory.Use(context.Background()))
26 ds := datastore.Get(c)
27
28 wg := sync.WaitGroup{}
29 for i := 0; i < 100; i++ {
30 id := int64(i + 1)
31
32 wg.Add(1)
33 go func() {
34 defer wg.Done()
35 err := ds.RunInTransaction(func(c context.Context) error {
36 ds := datastore.Get(c)
37
38 for i := 0; i < 100; i++ {
39 err := ds.RunInTransaction(func(c contex t.Context) error {
40 ds := datastore.Get(c)
41
42 ctr := &Counter{ID: id}
43 if err := ds.Get(ctr); err != ni l && err != datastore.ErrNoSuchEntity {
44 t.Fatal("bad Get", err)
45 }
46 ctr.Value++
47 return ds.Put(ctr)
48 }, nil)
49 if err != nil {
50 t.Fatal("bad inner RIT", err)
51 }
52 }
53
54 return nil
55 }, nil)
56 if err != nil {
57 t.Fatal("bad outer RIT", err)
58 }
59 }()
60 }
61 wg.Wait()
62 }
OLDNEW
« no previous file with comments | « no previous file | impl/memory/race_test.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698