test_result.py 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. import pytest
  2. import sys
  3. import os
  4. from unittest import mock
  5. from ray_release.result import handle_exception, ExitCode, ResultStatus
  6. from ray_release.exception import ReleaseTestError, ReleaseTestSetupError
  7. def test_handle_exception():
  8. """
  9. Unit test for ray_release.result.handle_exception
  10. """
  11. assert handle_exception(ReleaseTestError(), 10) == (
  12. ExitCode.UNSPECIFIED,
  13. ResultStatus.RUNTIME_ERROR,
  14. None,
  15. )
  16. # retriable
  17. with mock.patch.dict(os.environ, {"BUILDKITE_TIME_LIMIT_FOR_RETRY": "100"}):
  18. assert handle_exception(ReleaseTestSetupError(), 10) == (
  19. ExitCode.SETUP_ERROR,
  20. ResultStatus.TRANSIENT_INFRA_ERROR,
  21. None,
  22. )
  23. # retry limit reached, not retriable
  24. with mock.patch.dict(os.environ, {"BUILDKITE_RETRY_COUNT": "1"}):
  25. assert handle_exception(ReleaseTestSetupError(), 10) == (
  26. ExitCode.SETUP_ERROR,
  27. ResultStatus.INFRA_ERROR,
  28. None,
  29. )
  30. # too long to run, not retriable
  31. with mock.patch.dict(os.environ, {"BUILDKITE_TIME_LIMIT_FOR_RETRY": "1"}):
  32. assert handle_exception(ReleaseTestSetupError(), 3600) == (
  33. ExitCode.SETUP_ERROR,
  34. ResultStatus.INFRA_ERROR,
  35. None,
  36. )
  37. if __name__ == "__main__":
  38. sys.exit(pytest.main(["-v", __file__]))