vomebook commited on
Commit ·
012bf23
1
Parent(s): b379539
Assert OCR shutdown waits for task cleanup
Browse files843 unmodified lines8448458468478488491 unmodified line8518528538548558568578581 unmodified line8608618628638648658668678682 unmodified lines871872873874875876877878879880843 unmodified linesasync def test_bucket_shutdown_cancels_and_drains_owned_ocr_tasks(self):started = [asyncio.Event(), asyncio.Event()]finished = []async def held(index):1 unmodified linetry:await asyncio.Event().wait()finally:finished.append(index)tasks = [asyncio.create_task(held(index)) for index in range(2)]state = app.app.statestate.reader_ocr_inflight = {'synthetic-1': tasks[0], 'synthetic-2': tasks[1]}1 unmodified linestate.reader_bucket_cache_bytes = 3state.reader_ocr_cache['synthetic'] = ('digest', {}, 7)state.reader_ocr_cache_bytes = 7try:await asyncio.wait_for(asyncio.gather(*(event.wait() for event in started)), 1)await asyncio.wait_for(app.shutdown_reader_bucket_state(app.app), 1)self.assertCountEqual(finished, [0, 1])self.assertTrue(all(task.cancelled() for task in tasks))self.assertEqual(state.reader_ocr_inflight, {})2 unmodified linesself.assertEqual(state.reader_bucket_cache, {})self.assertEqual(state.reader_bucket_cache_bytes, 0)finally:for task in tasks:if not task.done():task.cancel()await asyncio.gather(*tasks, return_exceptions=True)async def test_reader_content_routes_both_v2_bucket_origins_to_proxy(self):request = SimpleNamespace(method="GET", headers={"Range": "bytes=0-1"})843 unmodified lines8448458468478488498508511 unmodified line8538548558568578588598608618628638648651 unmodified line8678688698708718728738748758768778788798808818828838848858868872 unmodified lines890891892893894895896897898899900901843 unmodified linesasync def test_bucket_shutdown_cancels_and_drains_owned_ocr_tasks(self):started = [asyncio.Event(), asyncio.Event()]cleaning = [asyncio.Event(), asyncio.Event()]release = asyncio.Event()finished = []async def held(index):1 unmodified linetry:await asyncio.Event().wait()finally:cleaning[index].set()await release.wait()finished.append(index)async def await_cleanups():await asyncio.gather(*(event.wait() for event in cleaning))tasks = [asyncio.create_task(held(index)) for index in range(2)]state = app.app.statestate.reader_ocr_inflight = {'synthetic-1': tasks[0], 'synthetic-2': tasks[1]}1 unmodified linestate.reader_bucket_cache_bytes = 3state.reader_ocr_cache['synthetic'] = ('digest', {}, 7)state.reader_ocr_cache_bytes = 7shutdown = Nonecleanups = Nonetry:await asyncio.wait_for(asyncio.gather(*(event.wait() for event in started)), 1)shutdown = asyncio.create_task(app.shutdown_reader_bucket_state(app.app))cleanups = asyncio.create_task(await_cleanups())await asyncio.wait({shutdown, cleanups}, timeout=1, return_when=asyncio.FIRST_COMPLETED)self.assertTrue(all(event.is_set() for event in cleaning), 'shutdown must cancel each OCR task')self.assertFalse(shutdown.done(), 'shutdown must await OCR task cleanup')self.assertEqual(state.reader_ocr_inflight, {})release.set()try:await asyncio.wait_for(shutdown, 1)except asyncio.TimeoutError:self.fail('shutdown must finish after OCR task cleanup')self.assertCountEqual(finished, [0, 1])self.assertTrue(all(task.cancelled() for task in tasks))self.assertEqual(state.reader_ocr_inflight, {})2 unmodified linesself.assertEqual(state.reader_bucket_cache, {})self.assertEqual(state.reader_bucket_cache_bytes, 0)finally:release.set()owned = tasks + [task for task in (shutdown, cleanups) if task is not None]for task in owned:if not task.done():task.cancel()await asyncio.gather(*owned, return_exceptions=True)async def test_reader_content_routes_both_v2_bucket_origins_to_proxy(self):request = SimpleNamespace(method="GET", headers={"Range": "bytes=0-1"})
tests/test_async_proxy.py+24-3