Skip to content

Commit

Permalink
Fix intermittent failures in the futures Python fixture (#1574)
Browse files Browse the repository at this point in the history
  • Loading branch information
mhammond authored Jun 2, 2023
1 parent 154739d commit 49f6033
Showing 1 changed file with 7 additions and 29 deletions.
36 changes: 7 additions & 29 deletions fixtures/futures/tests/bindings/test_futures.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,13 @@ def now():
class TestFutures(unittest.TestCase):
def test_always_ready(self):
async def test():
t0 = now()
result = await always_ready()
t1 = now()

t_delta = (t1 - t0).total_seconds()
self.assertTrue(t_delta < 0.1)
self.assertEqual(result, True)
self.assertEqual(await always_ready(), True)

asyncio.run(test())

def test_void(self):
async def test():
t0 = now()
result = await void()
t1 = now()

t_delta = (t1 - t0).total_seconds()
self.assertTrue(t_delta < 0.1)
self.assertEqual(result, None)
self.assertEqual(await void(), None)

asyncio.run(test())

Expand All @@ -38,7 +26,7 @@ async def test():
t1 = now()

t_delta = (t1 - t0).total_seconds()
self.assertTrue(t_delta > 2 and t_delta < 2.1)
self.assertGreater(t_delta, 2)

asyncio.run(test())

Expand All @@ -50,7 +38,7 @@ async def test():
t1 = now()

t_delta = (t1 - t0).total_seconds()
self.assertTrue(t_delta > 0.3 and t_delta < 0.31)
self.assertGreater(t_delta, 0.3)
self.assertEqual(result_alice, 'Hello, Alice!')
self.assertEqual(result_bob, 'Hello, Bob!')

Expand All @@ -67,7 +55,7 @@ async def test():
t1 = now()

t_delta = (t1 - t0).total_seconds()
self.assertTrue(t_delta > 0.2 and t_delta < 0.21)
self.assertGreater(t_delta, 0.2)
self.assertEqual(result_alice, 'Hello, Alice!')
self.assertEqual(result_bob, 'Hello, Bob!')

Expand All @@ -81,7 +69,7 @@ async def test():
t1 = now()

t_delta = (t1 - t0).total_seconds()
self.assertTrue(t_delta > 0.2 and t_delta < 0.21)
self.assertGreater(t_delta, 0.2)
self.assertEqual(result_alice, 'HELLO, ALICE!')

asyncio.run(test())
Expand All @@ -93,19 +81,14 @@ async def test():
t1 = now()

t_delta = (t1 - t0).total_seconds()
self.assertTrue(t_delta > 0.2 and t_delta < 0.21)
self.assertGreater(t_delta, 0.2)
self.assertEqual(result_alice, 'Hello, Alice (with Tokio)!')

asyncio.run(test())

def test_fallible(self):
async def test():
t0 = now()
result = await fallible_me(False)
t1 = now()

t_delta = (t1 - t0).total_seconds()
self.assertTrue(t_delta > 0 and t_delta < 0.1)
self.assertEqual(result, 42)

try:
Expand All @@ -116,12 +99,7 @@ async def test():

megaphone = new_megaphone()

t0 = now()
result = await megaphone.fallible_me(False)
t1 = now()

t_delta = (t1 - t0).total_seconds()
self.assertTrue(t_delta > 0 and t_delta < 0.1)
self.assertEqual(result, 42)

try:
Expand Down

0 comments on commit 49f6033

Please sign in to comment.