Skip to content

Commit

Permalink
Fixing issue with Windows timeout test (#1946)
Browse files Browse the repository at this point in the history
Summary:
Context and explanation: Timing works differently on Windows, and its imprecision has caused test failures in the past. When we started testing against Python 3.11, Windows tests involving timing started failing flakily. Adding some print statements showed that when the tests failed, time elapsed was measured as 0.0 seconds when it should have been substantially more. This is odd, since timing (including `monotonic`) was supposed to be more precise in Python 3.11. I couldn't debug this too thoroughly since I don't have access to a Windows machine outside of GitHub Actions.

The fix: Increased `sleep` from 1e-3s to 1e-2s in a test where we are making sure something times out within a limit of 1e-4s.

Pull Request resolved: #1946

Test Plan: I'm going to run units a few times to ensure that they pass consistently.

Reviewed By: saitcakmak

Differential Revision: D47810397

Pulled By: esantorella

fbshipit-source-id: 323375904553c042b84ea480f3e9eb50e6b5e21e
  • Loading branch information
esantorella authored and facebook-github-bot committed Jul 26, 2023
1 parent 4871a9a commit cca54db
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion test/optim/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def test_basic(self):
def test_timeout(self):
x = Parameter(torch.tensor(1.0))
# adding a small delay here to combat some timing issues on windows
closure = partial(norm_squared, x, delay=1e-3)
closure = partial(norm_squared, x, delay=1e-2)
result = scipy_minimize(closure, {"x": x}, timeout_sec=1e-4)
self.assertEqual(result.status, OptimizationStatus.STOPPED)
self.assertTrue("Optimization timed out after" in result.message)
Expand Down
2 changes: 1 addition & 1 deletion test/optim/utils/test_timeout.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def f_and_g(x: np.ndarray, sleep_sec: float = 0.0):
self.assertEqual(res.nit, 2) # quadratic approx. is exact

with self.subTest("test w/ binding timeout"):
res = minimize_with_timeout(**base_kwargs, args=(1e-3,), timeout_sec=1e-4)
res = minimize_with_timeout(**base_kwargs, args=(1e-2,), timeout_sec=1e-4)
self.assertFalse(res.success)
self.assertEqual(res.nit, 1) # only one call to the callback is made

Expand Down

0 comments on commit cca54db

Please sign in to comment.