From ab5d71ff6155171d886da2187b280f2f13514686 Mon Sep 17 00:00:00 2001 From: Jack Robison Date: Wed, 13 Mar 2019 16:23:34 -0400 Subject: [PATCH] fix the time to the head blob including the time to the sd blob in analytics --- lbrynet/stream/stream_manager.py | 2 +- tests/unit/stream/test_stream_manager.py | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/lbrynet/stream/stream_manager.py b/lbrynet/stream/stream_manager.py index 137fbad11..181a69228 100644 --- a/lbrynet/stream/stream_manager.py +++ b/lbrynet/stream/stream_manager.py @@ -455,7 +455,7 @@ class StreamManager: ), timeout ) time_to_descriptor = await descriptor_time_fut - time_to_first_bytes = self.loop.time() - start_download_time + time_to_first_bytes = self.loop.time() - start_download_time - time_to_descriptor self.wait_for_stream_finished(stream) if fee_address and fee_amount and not to_replace: stream.tx = await self.wallet.send_amount_to_address( diff --git a/tests/unit/stream/test_stream_manager.py b/tests/unit/stream/test_stream_manager.py index 8a1ff02aa..cf0214248 100644 --- a/tests/unit/stream/test_stream_manager.py +++ b/tests/unit/stream/test_stream_manager.py @@ -113,6 +113,25 @@ class TestStreamManager(BlobExchangeTestBase): binascii.hexlify(generate_id()).decode())) self.exchange_rate_manager = get_dummy_exchange_rate_manager(time) + async def test_time_to_first_bytes(self): + await self.setup_stream_manager() + checked_post = False + + async def check_post(event): + self.assertEqual(event['event'], 'Time To First Bytes') + total_duration = event['properties']['total_duration'] + resolve_duration = event['properties']['resolve_duration'] + head_blob_duration = event['properties']['head_blob_duration'] + sd_blob_duration = event['properties']['sd_blob_duration'] + self.assertTrue(total_duration >= resolve_duration + head_blob_duration + sd_blob_duration) + nonlocal checked_post + checked_post = True + + self.stream_manager.analytics_manager._post = check_post + await self.stream_manager.download_stream_from_uri(self.uri, self.exchange_rate_manager) + await asyncio.sleep(0, loop=self.loop) + self.assertTrue(checked_post) + async def test_download_stop_resume_delete(self): await self.setup_stream_manager() received = []