2019-12-31 14:52:57 -05:00
|
|
|
from lbry.wallet.stream import StreamController
|
|
|
|
from lbry.wallet.tasks import TaskGroup
|
2019-12-31 15:30:13 -05:00
|
|
|
from lbry.testcase import AsyncioTestCase
|
2019-08-07 02:48:40 -03:00
|
|
|
|
2019-08-07 11:27:25 -03:00
|
|
|
|
|
|
|
class StreamControllerTestCase(AsyncioTestCase):
|
2019-08-07 02:48:40 -03:00
|
|
|
def test_non_unique_events(self):
|
|
|
|
events = []
|
|
|
|
controller = StreamController()
|
|
|
|
controller.stream.listen(on_data=events.append)
|
|
|
|
controller.add("yo")
|
|
|
|
controller.add("yo")
|
2019-10-06 00:12:01 +03:00
|
|
|
self.assertListEqual(events, ["yo", "yo"])
|
2019-08-07 02:48:40 -03:00
|
|
|
|
|
|
|
def test_unique_events(self):
|
|
|
|
events = []
|
|
|
|
controller = StreamController(merge_repeated_events=True)
|
|
|
|
controller.stream.listen(on_data=events.append)
|
|
|
|
controller.add("yo")
|
|
|
|
controller.add("yo")
|
2019-10-06 00:12:01 +03:00
|
|
|
self.assertListEqual(events, ["yo"])
|
2019-12-11 19:31:45 -03:00
|
|
|
|
|
|
|
|
2019-12-11 22:10:39 -05:00
|
|
|
class TaskGroupTestCase(AsyncioTestCase):
|
|
|
|
|
|
|
|
async def test_cancel_sets_it_done(self):
|
2019-12-11 19:31:45 -03:00
|
|
|
group = TaskGroup()
|
|
|
|
group.cancel()
|
2019-12-11 23:33:34 -03:00
|
|
|
self.assertTrue(group.done.is_set())
|