From 800ba87cc881856adae19ec40485578356398639 Mon Sep 17 00:00:00 2001 From: Sean Quah <8349537+squahtx@users.noreply.github.com> Date: Tue, 5 Apr 2022 15:43:52 +0100 Subject: Refactor and convert `Linearizer` to async (#12357) Refactor and convert `Linearizer` to async. This makes a `Linearizer` cancellation bug easier to fix. Also refactor to use an async context manager, which eliminates an unlikely footgun where code that doesn't immediately use the context manager could forget to release the lock. Signed-off-by: Sean Quah --- tests/util/test_linearizer.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'tests') diff --git a/tests/util/test_linearizer.py b/tests/util/test_linearizer.py index fa132391a1..c2a209e637 100644 --- a/tests/util/test_linearizer.py +++ b/tests/util/test_linearizer.py @@ -46,7 +46,7 @@ class LinearizerTestCase(unittest.TestCase): unblock_d: "Deferred[None]" = Deferred() async def task() -> None: - with await linearizer.queue(key): + async with linearizer.queue(key): acquired_d.callback(None) await unblock_d @@ -125,7 +125,7 @@ class LinearizerTestCase(unittest.TestCase): async def func(i: int) -> None: with LoggingContext("func(%s)" % i) as lc: - with (await linearizer.queue(key)): + async with linearizer.queue(key): self.assertEqual(current_context(), lc) self.assertEqual(current_context(), lc) -- cgit 1.5.1