def testNonBlocking(self): """Tests async function doesn't block the main thread.""" r = [] async_fn = utils.make_async()(lambda: r.append((time.sleep(5), "a"))) r.append((None, "b")) async_fn().result() self.assertListEqual(r, [(None, "b"), (None, "a")])
def testBaseCase(self): """Tests correct execution for single call.""" r = [] async_fn = utils.make_async()(lambda: r.append("a")) async_fn() time.sleep(1) self.assertListEqual(r, ["a"])
def testSerialExecution(self): """Tests multiple calls to async function execute serially.""" r = [] a = lambda: r.append((time.sleep(5), "a")) b = lambda: r.append((None, "b")) async_fn = utils.make_async()(lambda f: f()) async_fn(a) async_fn(b).result() self.assertListEqual(r, [(None, "a"), (None, "b")])