Merge lp:~dave-cheney/goose/tip into lp:goose

Proposed by Dave Cheney
Status: Merged
Approved by: Dave Cheney
Approved revision: 128
Merged at revision: 127
Proposed branch: lp:~dave-cheney/goose/tip
Merge into: lp:goose
Diff against target: 89 lines (+17/-0)
1 file modified
testservices/swiftservice/service.go (+17/-0)
To merge this branch: bzr merge lp:~dave-cheney/goose/tip
Reviewer Review Type Date Requested Status
Juju Engineering Pending
Review via email: mp+225257@code.launchpad.net

Commit message

testing: fix data race in swift mock

https://codereview.appspot.com/108380043/

Description of the change

testing: fix data race in swift mock

https://codereview.appspot.com/108380043/

To post a comment you must log in.
Revision history for this message
Dave Cheney (dave-cheney) wrote :

Reviewers: mp+225257_code.launchpad.net,

Message:
Please take a look.

Description:
testing: fix data race in swift mock

https://code.launchpad.net/~dave-cheney/goose/tip/+merge/225257

(do not edit description out of merge proposal)

Please review this at https://codereview.appspot.com/108380043/

Affected files (+19, -0 lines):
   A [revision details]
   M testservices/swiftservice/service.go

Index: [revision details]
=== added file '[revision details]'
--- [revision details] 2012-01-01 00:00:00 +0000
+++ [revision details] 2012-01-01 00:00:00 +0000
@@ -0,0 +1,2 @@
+Old revision: tarmac-20140613065325-tlt6r3jg7saby4ub
+New revision: <email address hidden>

Index: testservices/swiftservice/service.go
=== modified file 'testservices/swiftservice/service.go'
--- testservices/swiftservice/service.go 2013-09-04 09:50:54 +0000
+++ testservices/swiftservice/service.go 2014-07-02 05:34:48 +0000
@@ -10,6 +10,7 @@
   "net/url"
   "sort"
   "strings"
+ "sync"
   "time"
  )

@@ -20,6 +21,8 @@

  type Swift struct {
   testservices.ServiceInstance
+
+ mu sync.Mutex // protects the remaining fields
   containers map[string]object
  }

@@ -70,7 +73,9 @@

  // HasContainer verifies the given container exists or not.
  func (s *Swift) HasContainer(name string) bool {
+ s.mu.Lock()
   _, ok := s.containers[name]
+ s.mu.Unlock()
   return ok
  }

@@ -80,7 +85,9 @@
   if err := s.ProcessFunctionHook(s, container, name); err != nil {
    return nil, err
   }
+ s.mu.Lock()
   data, ok := s.containers[container][name]
+ s.mu.Unlock()
   if !ok {
    return nil, fmt.Errorf("no such object %q in container %q", name,
container)
   }
@@ -96,7 +103,9 @@
   if s.HasContainer(name) {
    return fmt.Errorf("container already exists %q", name)
   }
+ s.mu.Lock()
   s.containers[name] = make(object)
+ s.mu.Unlock()
   return nil
  }

@@ -110,7 +119,9 @@
   if ok := s.HasContainer(name); !ok {
    return nil, fmt.Errorf("no such container %q", name)
   }
+ s.mu.Lock()
   items := s.containers[name]
+ s.mu.Unlock()
   sorted := make([]string, 0, len(items))
   prefix := params["prefix"]
   for filename := range items {
@@ -154,7 +165,9 @@
     return err
    }
   }
+ s.mu.Lock()
   s.containers[container][name] = data
+ s.mu.Unlock()
   return nil
  }

@@ -166,7 +179,9 @@
   if ok := s.HasContainer(name); !ok {
    return fmt.Errorf("no such container %q", name)
   }
+ s.mu.Lock()
   delete(s.containers, name)
+ s.mu.Unlock()
   return nil
  }

@@ -178,7 +193,9 @@
   if _, err := s.GetObject(container, name); err != nil {
    return err
   }
+ s.mu.Lock()
   delete(s.containers[container], name)
+ s.mu.Unlock()
   return nil
  }

Revision history for this message
Andrew Wilkins (axwalk) wrote :

On 2014/07/02 05:36:39, dfc wrote:
> Please take a look.

LGTM

https://codereview.appspot.com/108380043/

Revision history for this message
Dave Cheney (dave-cheney) :

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'testservices/swiftservice/service.go'
--- testservices/swiftservice/service.go 2013-09-04 09:50:54 +0000
+++ testservices/swiftservice/service.go 2014-07-02 05:35:39 +0000
@@ -10,6 +10,7 @@
10 "net/url"10 "net/url"
11 "sort"11 "sort"
12 "strings"12 "strings"
13 "sync"
13 "time"14 "time"
14)15)
1516
@@ -20,6 +21,8 @@
2021
21type Swift struct {22type Swift struct {
22 testservices.ServiceInstance23 testservices.ServiceInstance
24
25 mu sync.Mutex // protects the remaining fields
23 containers map[string]object26 containers map[string]object
24}27}
2528
@@ -70,7 +73,9 @@
7073
71// HasContainer verifies the given container exists or not.74// HasContainer verifies the given container exists or not.
72func (s *Swift) HasContainer(name string) bool {75func (s *Swift) HasContainer(name string) bool {
76 s.mu.Lock()
73 _, ok := s.containers[name]77 _, ok := s.containers[name]
78 s.mu.Unlock()
74 return ok79 return ok
75}80}
7681
@@ -80,7 +85,9 @@
80 if err := s.ProcessFunctionHook(s, container, name); err != nil {85 if err := s.ProcessFunctionHook(s, container, name); err != nil {
81 return nil, err86 return nil, err
82 }87 }
88 s.mu.Lock()
83 data, ok := s.containers[container][name]89 data, ok := s.containers[container][name]
90 s.mu.Unlock()
84 if !ok {91 if !ok {
85 return nil, fmt.Errorf("no such object %q in container %q", name, container)92 return nil, fmt.Errorf("no such object %q in container %q", name, container)
86 }93 }
@@ -96,7 +103,9 @@
96 if s.HasContainer(name) {103 if s.HasContainer(name) {
97 return fmt.Errorf("container already exists %q", name)104 return fmt.Errorf("container already exists %q", name)
98 }105 }
106 s.mu.Lock()
99 s.containers[name] = make(object)107 s.containers[name] = make(object)
108 s.mu.Unlock()
100 return nil109 return nil
101}110}
102111
@@ -110,7 +119,9 @@
110 if ok := s.HasContainer(name); !ok {119 if ok := s.HasContainer(name); !ok {
111 return nil, fmt.Errorf("no such container %q", name)120 return nil, fmt.Errorf("no such container %q", name)
112 }121 }
122 s.mu.Lock()
113 items := s.containers[name]123 items := s.containers[name]
124 s.mu.Unlock()
114 sorted := make([]string, 0, len(items))125 sorted := make([]string, 0, len(items))
115 prefix := params["prefix"]126 prefix := params["prefix"]
116 for filename := range items {127 for filename := range items {
@@ -154,7 +165,9 @@
154 return err165 return err
155 }166 }
156 }167 }
168 s.mu.Lock()
157 s.containers[container][name] = data169 s.containers[container][name] = data
170 s.mu.Unlock()
158 return nil171 return nil
159}172}
160173
@@ -166,7 +179,9 @@
166 if ok := s.HasContainer(name); !ok {179 if ok := s.HasContainer(name); !ok {
167 return fmt.Errorf("no such container %q", name)180 return fmt.Errorf("no such container %q", name)
168 }181 }
182 s.mu.Lock()
169 delete(s.containers, name)183 delete(s.containers, name)
184 s.mu.Unlock()
170 return nil185 return nil
171}186}
172187
@@ -178,7 +193,9 @@
178 if _, err := s.GetObject(container, name); err != nil {193 if _, err := s.GetObject(container, name); err != nil {
179 return err194 return err
180 }195 }
196 s.mu.Lock()
181 delete(s.containers[container], name)197 delete(s.containers[container], name)
198 s.mu.Unlock()
182 return nil199 return nil
183}200}
184201

Subscribers

People subscribed via source and target branches