Read all Gerrit events from poll interruption

Gerrit may emits multiple events in a single packet, in particular the
change-created and ref-updated events. This results in a single poll
interruption and the GerritWatcher will only process the first event
until there is more activity on the event streams.

To correct this, the _read method needs to read all the lines already
available in the paramiko channel file before polling the file.

Story: 2000816
Task: 3401
Change-Id: I93b55a6491353aee8c954d349cef658c09d1ff2d
This commit is contained in:
Tristan Cacqueray 2016-12-02 09:32:11 +00:00
parent 86cb64dbf3
commit 537da25d89
1 changed files with 9 additions and 5 deletions

View File

@ -171,11 +171,15 @@ class GerritWatcher(threading.Thread):
self._stopped = False
def _read(self, fd):
l = fd.readline()
data = json.loads(l)
self.log.debug("Received data from Gerrit event stream: \n%s" %
pprint.pformat(data))
self.gerrit_connection.addEvent(data)
while True:
l = fd.readline()
data = json.loads(l)
self.log.debug("Received data from Gerrit event stream: \n%s" %
pprint.pformat(data))
self.gerrit_connection.addEvent(data)
# Continue until all the lines received are consumed
if fd._pos == fd._realpos:
break
def _listen(self, stdout, stderr):
poll = select.poll()