From 4941d1d31dd35fd08f6e545cbe7d2ae036724ce0 Mon Sep 17 00:00:00 2001 From: Kay Kurokawa Date: Wed, 20 Sep 2017 22:57:47 -0400 Subject: [PATCH] test when you have a v1 blob reflect before a stream reflect over the same blobs --- tests/functional/test_reflector.py | 72 ++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) diff --git a/tests/functional/test_reflector.py b/tests/functional/test_reflector.py index a86ed2520..f0f8a76eb 100644 --- a/tests/functional/test_reflector.py +++ b/tests/functional/test_reflector.py @@ -287,6 +287,78 @@ class TestReflector(unittest.TestCase): d.addCallback(lambda _: verify_data_on_reflector()) return d + # test case when we reflect blob, and than that same blob + # is reflected as stream + def test_blob_reflect_and_stream(self): + + def verify_blob_on_reflector(): + check_blob_ds = [] + for blob_hash, blob_size in self.expected_blobs: + check_blob_ds.append(verify_have_blob(blob_hash, blob_size)) + return defer.DeferredList(check_blob_ds) + + @defer.inlineCallbacks + def verify_stream_on_reflector(): + # check stream_info_manager has all the right information + + streams = yield self.server_stream_info_manager.get_all_streams() + self.assertEqual(1, len(streams)) + self.assertEqual(self.stream_hash, streams[0]) + + blobs = yield self.server_stream_info_manager.get_blobs_for_stream(self.stream_hash) + blob_hashes = [b[0] for b in blobs if b[0] is not None] + expected_blob_hashes = [b[0] for b in self.expected_blobs[:-1] if b[0] is not None] + self.assertEqual(expected_blob_hashes, blob_hashes) + sd_hashes = yield self.server_stream_info_manager.get_sd_blob_hashes_for_stream(self.stream_hash) + self.assertEqual(1, len(sd_hashes)) + expected_sd_hash = self.expected_blobs[-1][0] + self.assertEqual(self.sd_hash, sd_hashes[0]) + + # check should_announce blobs on blob_manager + blob_hashes = yield self.server_blob_manager._get_all_should_announce_blob_hashes() + self.assertEqual(2, len(blob_hashes)) + self.assertTrue(self.sd_hash in blob_hashes) + self.assertTrue(expected_blob_hashes[0] in blob_hashes) + + def verify_have_blob(blob_hash, blob_size): + d = self.server_blob_manager.get_blob(blob_hash) + d.addCallback(lambda blob: verify_blob_completed(blob, blob_size)) + return d + + def send_to_server_as_blobs(blob_hashes_to_send): + factory = reflector.BlobClientFactory( + self.session.blob_manager, + blob_hashes_to_send + ) + factory.protocol_version = 0 + + from twisted.internet import reactor + reactor.connectTCP('localhost', self.port, factory) + return factory.finished_deferred + + def send_to_server_as_stream(result): + fake_lbry_file = mocks.FakeLBRYFile(self.session.blob_manager, + self.stream_info_manager, + self.stream_hash) + factory = reflector.ClientFactory(fake_lbry_file) + + from twisted.internet import reactor + reactor.connectTCP('localhost', self.port, factory) + return factory.finished_deferred + + + def verify_blob_completed(blob, blob_size): + self.assertTrue(blob.get_is_verified()) + self.assertEqual(blob_size, blob.length) + + # Modify this to change which blobs to send + blobs_to_send = self.expected_blobs + + d = send_to_server_as_blobs([x[0] for x in self.expected_blobs]) + d.addCallback(send_to_server_as_stream) + d.addCallback(lambda _: verify_blob_on_reflector()) + d.addCallback(lambda _: verify_stream_on_reflector()) + return d def iv_generator(): iv = 0