Make eager/monitoring_test.py less flaky.
MonitoredTimer measures wall time, so we're susceptible to the process being interrupted. To measure time intervals of different lengths, wrap them inside each other, that way guaranteeing that the inner one is shorter than the outer one. PiperOrigin-RevId: 315355335 Change-Id: I6eb136f221f4b96917ad8f6708f4a9bad18841c9
This commit is contained in:
parent
1acf61f028
commit
d7da550fc7
|
@ -104,10 +104,10 @@ class MonitoringTest(test_util.TensorFlowTestCase):
|
|||
|
||||
def test_context_manager(self):
|
||||
counter = monitoring.Counter('test/ctxmgr', 'test context manager', 'slot')
|
||||
with monitoring.MonitoredTimer(counter.get_cell('short')):
|
||||
time.sleep(0.001)
|
||||
with monitoring.MonitoredTimer(counter.get_cell('long')):
|
||||
time.sleep(0.02)
|
||||
time.sleep(0.01)
|
||||
with monitoring.MonitoredTimer(counter.get_cell('short')):
|
||||
time.sleep(0.01)
|
||||
self.assertGreater(
|
||||
counter.get_cell('long').value(),
|
||||
counter.get_cell('short').value())
|
||||
|
|
Loading…
Reference in New Issue