Test that RayTaskError with dual exception instances can be properly serialized.
(ray_start_regular)
| 686 | |
| 687 | |
| 688 | def test_raytaskerror_serialization(ray_start_regular): |
| 689 | """Test that RayTaskError with dual exception instances can be properly serialized.""" |
| 690 | import ray.cloudpickle as pickle |
| 691 | |
| 692 | class MyException(Exception): |
| 693 | def __init__(self, one, two): |
| 694 | self.one = one |
| 695 | self.two = two |
| 696 | |
| 697 | def __reduce__(self): |
| 698 | return self.__class__, (self.one, self.two) |
| 699 | |
| 700 | original_exception = MyException("test 1", "test 2") |
| 701 | ray_task_error = ray.exceptions.RayTaskError( |
| 702 | function_name="test_function", |
| 703 | traceback_str="test traceback", |
| 704 | cause=original_exception, |
| 705 | ) |
| 706 | |
| 707 | dual_exception = ray_task_error.make_dual_exception_instance() |
| 708 | pickled = pickle.dumps(dual_exception) |
| 709 | unpickled = pickle.loads(pickled) |
| 710 | |
| 711 | assert isinstance(unpickled, ray.exceptions.RayTaskError) |
| 712 | assert isinstance(unpickled, MyException) |
| 713 | assert unpickled.one == "test 1" |
| 714 | assert unpickled.two == "test 2" |
| 715 | |
| 716 | |
| 717 | if __name__ == "__main__": |
nothing calls this directly
no test coverage detected
searching dependent graphs…