Skip to content

Commit

Permalink
[Tune] Deflake testVerboseReporting (#29748)
Browse files Browse the repository at this point in the history
`ProgressReportingTest::testVerboseReporting` is flakey. For more information, see #29693.

Signed-off-by: Balaji Veeramani <[email protected]>
Co-authored-by: Kai Fricke <[email protected]>
  • Loading branch information
bveeramani and krfricke authored Oct 27, 2022
1 parent 31d603f commit 006bc07
Showing 1 changed file with 17 additions and 11 deletions.
28 changes: 17 additions & 11 deletions python/ray/tune/tests/test_progress_reporter.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import collections
import os
import regex as re
import unittest
from unittest.mock import MagicMock, Mock, patch

Expand Down Expand Up @@ -242,14 +243,19 @@ def f(config):
"with parameters={'do': 'complete'}. This trial completed.\n"
)

VERBOSE_TRIAL_NORM_2 = """
Trial train_xxxxx_00001 reported _metric=6 with parameters={'do': 'once'}.
Trial train_xxxxx_00001 completed. Last result: _metric=6
"""
# NOTE: We use Regex for `VERBOSE_TRIAL_NORM_2` to make the test deterministic.
# `"Trial train_xxxxx_00001 reported..."` and `"Trial train_xxxxx_00001 completed..."`
# are printed in separate calls. Sometimes, a status update is printed between the
# calls. For more information, see #29693.
VERBOSE_TRIAL_NORM_2_PATTERN = (
r"Trial train_xxxxx_00001 reported _metric=6 with parameters=\{'do': 'once'\}\.\n"
r"(?s).*"
r"Trial train_xxxxx_00001 completed\. Last result: _metric=6\n"
)

VERBOSE_TRIAL_NORM_3 = """
Trial train_xxxxx_00002 reported acc=7 with parameters={'do': 'twice'}.
"""
VERBOSE_TRIAL_NORM_3 = (
"Trial train_xxxxx_00002 reported acc=7 with parameters={'do': 'twice'}.\n"
)

VERBOSE_TRIAL_NORM_4 = (
"Trial train_xxxxx_00002 reported acc=8 "
Expand Down Expand Up @@ -639,7 +645,7 @@ def testVerboseReporting(self):
self.assertNotIn(VERBOSE_EXP_OUT_1, output)
self.assertNotIn(VERBOSE_EXP_OUT_2, output)
self.assertNotIn(VERBOSE_TRIAL_NORM_1, output)
self.assertNotIn(VERBOSE_TRIAL_NORM_2, output)
self.assertIsNone(re.search(VERBOSE_TRIAL_NORM_2_PATTERN, output))
self.assertNotIn(VERBOSE_TRIAL_NORM_3, output)
self.assertNotIn(VERBOSE_TRIAL_NORM_4, output)
self.assertNotIn(VERBOSE_TRIAL_DETAIL, output)
Expand All @@ -655,7 +661,7 @@ def testVerboseReporting(self):
self.assertIn(VERBOSE_EXP_OUT_1, output)
self.assertIn(VERBOSE_EXP_OUT_2, output)
self.assertNotIn(VERBOSE_TRIAL_NORM_1, output)
self.assertNotIn(VERBOSE_TRIAL_NORM_2, output)
self.assertIsNone(re.search(VERBOSE_TRIAL_NORM_2_PATTERN, output))
self.assertNotIn(VERBOSE_TRIAL_NORM_3, output)
self.assertNotIn(VERBOSE_TRIAL_NORM_4, output)
self.assertNotIn(VERBOSE_TRIAL_DETAIL, output)
Expand All @@ -671,7 +677,7 @@ def testVerboseReporting(self):
self.assertIn(VERBOSE_EXP_OUT_1, output)
self.assertIn(VERBOSE_EXP_OUT_2, output)
self.assertIn(VERBOSE_TRIAL_NORM_1, output)
self.assertIn(VERBOSE_TRIAL_NORM_2, output)
self.assertIsNotNone(re.search(VERBOSE_TRIAL_NORM_2_PATTERN, output))
self.assertIn(VERBOSE_TRIAL_NORM_3, output)
self.assertIn(VERBOSE_TRIAL_NORM_4, output)
self.assertNotIn(VERBOSE_TRIAL_DETAIL, output)
Expand All @@ -687,7 +693,7 @@ def testVerboseReporting(self):
self.assertIn(VERBOSE_EXP_OUT_1, output)
self.assertIn(VERBOSE_EXP_OUT_2, output)
self.assertNotIn(VERBOSE_TRIAL_NORM_1, output)
self.assertNotIn(VERBOSE_TRIAL_NORM_2, output)
self.assertIsNone(re.search(VERBOSE_TRIAL_NORM_2_PATTERN, output))
self.assertNotIn(VERBOSE_TRIAL_NORM_3, output)
self.assertNotIn(VERBOSE_TRIAL_NORM_4, output)
self.assertIn(VERBOSE_TRIAL_DETAIL, output)
Expand Down

0 comments on commit 006bc07

Please sign in to comment.