Fix FakeGerritRefWatcher and FakeGerritPoller events
Ib9e095430fa82be2327dcf7fd01ee4275b17415f introduced loops in "_run" methods which have the side effect of events no longer being set. Some tests are running until timeout expiration. Test id Runtime -------------------------------------------------------------- -------- tests.unit.test_gerrit.TestPolling.test_config_update 123.778 tests.unit.test_gerrit.TestPolling.test_post 123.729 tests.unit.test_gerrit.TestChecksApi.test_new_patchset 123.635 tests.unit.test_gerrit.TestPolling.test_tag 123.628 By changing the subclass method used to set event to one inside the loop, notifications are restored. Test id Runtime -------------------------------------------------------------- -------- tests.unit.test_gerrit.TestPolling.test_config_update 5.246 tests.unit.test_gerrit.TestPolling.test_post 5.252 tests.unit.test_gerrit.TestChecksApi.test_new_patchset 5.276 tests.unit.test_gerrit.TestPolling.test_tag 5.247 Change-Id: I8c9ad6577d43b9b4866f83e4f8727615abf239c4
This commit is contained in:
parent
c2403f3991
commit
954986c538
|
@ -1088,8 +1088,8 @@ class FakeGerritPoller(gerritconnection.GerritPoller):
|
|||
|
||||
poll_interval = 1
|
||||
|
||||
def _run(self, *args, **kw):
|
||||
r = super(FakeGerritPoller, self)._run(*args, **kw)
|
||||
def _poll(self, *args, **kw):
|
||||
r = super(FakeGerritPoller, self)._poll(*args, **kw)
|
||||
# Set the event so tests can confirm that the poller has run
|
||||
# after they changed something.
|
||||
self.connection._poller_event.set()
|
||||
|
@ -1108,8 +1108,8 @@ class FakeGerritRefWatcher(gitwatcher.GitWatcher):
|
|||
self.baseurl = self.connection.upstream_root
|
||||
self.poll_delay = 1
|
||||
|
||||
def _run(self, *args, **kw):
|
||||
r = super(FakeGerritRefWatcher, self)._run(*args, **kw)
|
||||
def _poll(self, *args, **kw):
|
||||
r = super(FakeGerritRefWatcher, self)._poll(*args, **kw)
|
||||
# Set the event so tests can confirm that the watcher has run
|
||||
# after they changed something.
|
||||
self.connection._ref_watcher_event.set()
|
||||
|
|
|
@ -491,18 +491,22 @@ class GerritPoller(threading.Thread):
|
|||
event = self._makeChangeMergedEvent(change)
|
||||
self.connection.addEvent(event)
|
||||
|
||||
def _run(self):
|
||||
last_start = time.time()
|
||||
while not (self._stopped or self._connection_lost_event.is_set()):
|
||||
next_start = last_start + self.poll_interval
|
||||
self._stop_event.wait(max(next_start - time.time(), 0))
|
||||
if self._stopped or self._connection_lost_event.is_set():
|
||||
break
|
||||
last_start = time.time()
|
||||
def _poll(self):
|
||||
next_start = self._last_start + self.poll_interval
|
||||
self._stop_event.wait(max(next_start - time.time(), 0))
|
||||
if self._stopped or self._connection_lost_event.is_set():
|
||||
return
|
||||
self._last_start = time.time()
|
||||
self._poll_checkers()
|
||||
if not self.connection.enable_stream_events:
|
||||
self._poll_merged_changes()
|
||||
|
||||
self._poll_checkers()
|
||||
if not self.connection.enable_stream_events:
|
||||
self._poll_merged_changes()
|
||||
def _run(self):
|
||||
self._last_start = time.time()
|
||||
while not (self._stopped or self._connection_lost_event.is_set()):
|
||||
# during tests, a sub-class _poll method is used to send
|
||||
# notifications
|
||||
self._poll()
|
||||
|
||||
def run(self):
|
||||
while not self._stopped:
|
||||
|
|
|
@ -144,6 +144,8 @@ class GitWatcher(threading.Thread):
|
|||
def _run(self):
|
||||
while not (self._stopped or self._connection_lost_event.is_set()):
|
||||
if not self._pause:
|
||||
# during tests, a sub-class _poll method is used to send
|
||||
# notifications
|
||||
self._poll()
|
||||
# Polling wait delay
|
||||
else:
|
||||
|
|
Loading…
Reference in New Issue