Esempio n. 1
0
    def test_set_exception(self) -> None:
        # This test is to ensure errors can propagate across futures.
        error_msg = "Intentional Value Error"
        value_error = ValueError(error_msg)

        f = Future[T]()
        # Set exception
        f.set_exception(value_error)
        # Exception should throw on wait
        with self.assertRaisesRegex(ValueError, "Intentional"):
            f.wait()

        # Exception should also throw on value
        f = Future()
        f.set_exception(value_error)
        with self.assertRaisesRegex(ValueError, "Intentional"):
            f.value()

        def cb(fut):
            fut.value()

        f = Future()
        f.set_exception(value_error)

        with self.assertRaisesRegex(RuntimeError, "Got the following error"):
            cb_fut = f.then(cb)
            cb_fut.wait()
Esempio n. 2
0
 def _fail_rank_async(self, name):
     ranks = self._get_ranks(name)
     fut = Future()
     if ranks is not None and self.rank in ranks:
         fut.set_exception(ValueError(f"async rank fail {self.rank} for {name}"))
     else:
         fut.set_result(None)
     return fut