ray_test_db.py 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. import json
  2. import os
  3. from ray_release.configs.global_config import get_global_config
  4. from ray_release.reporter.reporter import Reporter
  5. from ray_release.result import Result, ResultStatus
  6. from ray_release.test import Test
  7. from ray_release.test_automation.release_state_machine import ReleaseTestStateMachine
  8. from ray_release.logger import logger
  9. class RayTestDBReporter(Reporter):
  10. """
  11. Reporter that updates the test and test result object in s3 with the latest test run
  12. information.
  13. - test: Test object that contains the test information (name, oncall, state, etc.)
  14. - result: Result object that contains the test result information of this particular
  15. test run (status, start time, end time, etc.)
  16. """
  17. def report_result(self, test: Test, result: Result) -> None:
  18. if os.environ.get("BUILDKITE_BRANCH") != "master":
  19. logger.info("Skip upload test results. We only upload on master branch.")
  20. return
  21. if (
  22. os.environ.get("BUILDKITE_PIPELINE_ID")
  23. not in get_global_config()["ci_pipeline_postmerge"]
  24. ):
  25. logger.info("Skip upload test results. We only upload on branch pipeline.")
  26. return
  27. if result.status == ResultStatus.TRANSIENT_INFRA_ERROR.value:
  28. logger.info(
  29. f"Skip recording result for test {test.get_name()} due to transient "
  30. "infra error result"
  31. )
  32. return
  33. logger.info(
  34. f"Updating test object {test.get_name()} with result {result.status}"
  35. )
  36. test.persist_result_to_s3(result)
  37. # Update the test object with the latest test state
  38. test.update_from_s3()
  39. logger.info(f"Test object: {json.dumps(test)}")
  40. logger.info(
  41. f"Test results: "
  42. f"{json.dumps([result.__dict__ for result in test.get_test_results()])}"
  43. )
  44. # Compute and update the next test state
  45. ReleaseTestStateMachine(test).move()
  46. # Persist the updated test object to S3
  47. test.persist_to_s3()
  48. logger.info(f"Test object {test.get_name()} updated successfully")