Skip to content

Commit 4e69087

Browse files
authored
Fixing race condition in Pub / Sub system tests. (googleapis#4632)
This was a programming error on my part (using a brand new lock every time it was held).
1 parent d8317b5 commit 4e69087

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

pubsub/tests/system.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,11 +187,12 @@ class AckCallback(object):
187187

188188
def __init__(self):
189189
self.calls = 0
190+
self.lock = threading.Lock()
190191

191192
def __call__(self, message):
192193
message.ack()
193194
# Only increment the number of calls **after** finishing.
194-
with threading.Lock():
195+
with self.lock:
195196
self.calls += 1
196197

197198

@@ -201,13 +202,14 @@ def __init__(self, sleep_time):
201202
self.sleep_time = sleep_time
202203
self.calls = 0
203204
self.call_times = []
205+
self.lock = threading.Lock()
204206

205207
def __call__(self, message):
206208
now = datetime.datetime.now()
207209
time.sleep(self.sleep_time)
208210
message.ack()
209211
# Only increment the number of calls **after** finishing.
210-
with threading.Lock():
212+
with self.lock:
211213
# list.append() is thread-safe, but we still wait until
212214
# ``calls`` is incremented to do it.
213215
self.call_times.append(now)

0 commit comments

Comments
 (0)