jenkins-bot has submitted this change and it was merged. (
https://gerrit.wikimedia.org/r/509132 )
Change subject: [tests] Test whether sseclient.EventSource works as expected
......................................................................
[tests] Test whether sseclient.EventSource works as expected
As found in sseclient 0.0.24 the EventSource gives randomly a
ValueError 'Unterminated string' when json.load is processed
if the limit is high enough.
Bug: T222885
Change-Id: I082a63180eb26b02bb19b53b12490bd137e322a5
---
M tests/eventstreams_tests.py
1 file changed, 50 insertions(+), 1 deletion(-)
Approvals:
Zhuyifei1999: Looks good to me, but someone else must approve
D3r1ck01: Looks good to me, approved
jenkins-bot: Verified
diff --git a/tests/eventstreams_tests.py b/tests/eventstreams_tests.py
index 4007e97..5df0a45 100644
--- a/tests/eventstreams_tests.py
+++ b/tests/eventstreams_tests.py
@@ -7,9 +7,11 @@
#
from __future__ import absolute_import, division, unicode_literals
+import json
+
from tests import mock
-from pywikibot.comms.eventstreams import EventStreams
+from pywikibot.comms.eventstreams import EventStreams, EventSource
from pywikibot import config
from pywikibot.family import WikimediaFamily
@@ -248,6 +250,53 @@
self._test_filter(none_type, all_type, any_type, result)
+class EventStreamsTestClass(EventStreams):
+
+ """Test class of EventStreams."""
+
+ def __iter__(self):
+ """Iterator."""
+ n = 0
+ while self._total is None or n < self._total:
+ if not hasattr(self, 'source'):
+ self.source = EventSource(**self.sse_kwargs)
+ event = next(self.source)
+ if event.event == 'message':
+ if not event.data:
+ continue
+ n += 1
+ try:
+ element = json.loads(event.data)
+ except ValueError as e:
+ self.source.resp.close() # close SSLSocket
+ del self.source
+ raise ValueError(
+ '{error}\n\nEvent no {number}: '
+ 'Could not load json data from source\n${event}$'
+ .format(number=n, event=event, error=e))
+ yield element
+ del self.source
+
+
+class TestEventSource(TestCase):
+
+ """Test sseclient.EventSource."""
+
+ net = True
+
+ def test_stream(self):
+ """Verify that the EventSource delivers events without problems.
+
+ As found in sseclient 0.0.24 the EventSource gives randomly a
+ ValueError 'Unterminated string' when json.load is processed
+ if the limit is high enough.
+ """
+ limit = 50
+ self.es = EventStreamsTestClass(streams='recentchange')
+ self.es.set_maximum_items(limit)
+ self.assertLength(list(self.es), limit)
+
+
if __name__ == '__main__': # pragma: no cover
try:
unittest.main()
--
To view, visit
https://gerrit.wikimedia.org/r/509132
To unsubscribe, or for help writing mail filters, visit
https://gerrit.wikimedia.org/r/settings
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-MessageType: merged
Gerrit-Change-Id: I082a63180eb26b02bb19b53b12490bd137e322a5
Gerrit-Change-Number: 509132
Gerrit-PatchSet: 3
Gerrit-Owner: Xqt <info(a)gno.de>
Gerrit-Reviewer: D3r1ck01 <xsavitar.wiki(a)aol.com>
Gerrit-Reviewer: Dvorapa <dvorapa(a)seznam.cz>
Gerrit-Reviewer: John Vandenberg <jayvdb(a)gmail.com>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: Zhuyifei1999 <zhuyifei1999(a)gmail.com>
Gerrit-Reviewer: jenkins-bot (75)