def test_random_string(): test_string = random_string() assert test_string assert len(test_string) == 6 text_length = 16 test_string2 = random_string(size=text_length) assert len(test_string2) == text_length
def test_random_string(self): test_string = random_string() self.assertIsNotNone(test_string) self.assertEqual(len(test_string), 6) text_length = 16 test_string2 = random_string(size=text_length) self.assertEqual(len(test_string2), text_length)
async def test_remote_select_packets_limit(self): """ Test dropping packets that go over the response limit for a remote select. """ mds0 = self.nodes[0].overlay.mds mds1 = self.nodes[1].overlay.mds # We do not want the query back mechanism to interfere with this test self.nodes[1].overlay.settings.max_channel_query_back = 0 with db_session: for _ in range(0, 100): mds0.ChannelMetadata.create_channel(random_string(100), "") peer = self.nodes[0].my_peer kwargs_dict = {"metadata_type": [CHANNEL_TORRENT]} self.nodes[1].overlay.send_remote_select(peer, **kwargs_dict) # There should be an outstanding request in the list self.assertTrue(self.nodes[1].overlay.request_cache._identifiers) # pylint: disable=protected-access await self.deliver_messages(timeout=1.5) with db_session: received_channels = list(mds1.ChannelMetadata.select()) # We should receive less that 6 packets, so all the channels should not fit there. received_channels_count = len(received_channels) assert 40 < received_channels_count < 60 # The list of outstanding requests should be empty self.assertFalse(self.nodes[1].overlay.request_cache._identifiers) # pylint: disable=protected-access
async def test_remote_select_torrents(self): """ Test dropping packets that go over the response limit for a remote select. """ peer = self.nodes[0].my_peer mds0 = self.nodes[0].overlay.mds mds1 = self.nodes[1].overlay.mds with db_session: chan = mds0.ChannelMetadata.create_channel(random_string(100), "") torrent_infohash = random_infohash() torrent = mds0.TorrentMetadata(origin_id=chan.id_, infohash=torrent_infohash, title='title1') torrent.sign() processing_results = [] def callback(request, results): # pylint: disable=unused-argument processing_results.extend(results) self.nodes[1].overlay.send_remote_select( peer, metadata_type=[REGULAR_TORRENT], infohash=torrent_infohash, processing_callback=callback) await self.deliver_messages() assert len(processing_results) == 1 obj = processing_results[0].md_obj assert isinstance(obj, mds1.TorrentMetadata) assert obj.title == 'title1' assert obj.health.seeders == 0 with db_session: torrent = mds0.TorrentMetadata.get(infohash=torrent_infohash) torrent.timestamp += 1 torrent.title = 'title2' torrent.sign() processing_results = [] self.nodes[1].overlay.send_remote_select( peer, metadata_type=[REGULAR_TORRENT], infohash=torrent_infohash, processing_callback=callback) await self.deliver_messages() assert len(processing_results) == 1 obj = processing_results[0].md_obj assert isinstance(obj, mds1.TorrentMetadata) assert obj.health.seeders == 0
async def test_remote_select_packets_limit(self): """ Test dropping packets that go over the response limit for a remote select. """ with db_session: for _ in range(0, 100): self.nodes[0].overlay.mds.ChannelMetadata.create_channel(random_string(100), "") peer = self.nodes[0].my_peer kwargs_dict = {"metadata_type": [CHANNEL_TORRENT]} self.nodes[1].overlay.send_remote_select(peer, **kwargs_dict) # There should be an outstanding request in the list self.assertTrue(self.nodes[1].overlay.request_cache._identifiers) await self.deliver_messages(timeout=0.5) with db_session: received_channels = self.nodes[1].overlay.mds.ChannelMetadata.select() # We should receive less that 6 packets, so all the channels should not fit there. self.assertTrue(40 < received_channels.count() < 60) # The list of outstanding requests should be empty self.assertFalse(self.nodes[1].overlay.request_cache._identifiers)