Fixed possible race condition in parallel testing#11972
Conversation
pllim
left a comment
There was a problem hiding this comment.
This solves the race condition but does not respect the original goal of not re-creating the data in every test method run. I think the intention of setup_class was that data creation would only happen once per parameterization.
This comment has been minimized.
This comment has been minimized.
There isn't really any way to parametrize I don't think it really effects the run-time performance of the unit tests meaningfully if that helps. |
Removed `masked` reference from TestArithmetic Removed `masked` from test_methods Cleaned up code Minor cleanup-refactor
|
I wonder if the global variable definition can be moved to MY_DATA = {}
def setup_module(module):
global MY_DATA
MYDATA = {'masked': Time(...), 'not_masked': Time(...)}Then, the parameterized test method accesses |
3a39ab9 to
acb9858
Compare
At this point one could just define def setup_class(cls):
mjd = np.arange(50000, 50010)
frac = np.arange(0., 0.999, 0.2)
frac_masked = np.ma.array(frac)
frac_masked[1] = np.ma.masked
cls.t0 = {
'not_masked': Time(mjd[:, np.newaxis] + frac, format='mjd', scale='utc'),
'masked': Time(mjd[:, np.newaxis] + frac_masked, format='mjd', scale='utc')
}
... |
pllim
left a comment
There was a problem hiding this comment.
I don't know the true intentions of these tests, so best if @taldcroft can review. If not, the pytest changes look technically sound and CI passed, so LGTM. Thanks!
|
@WilliamJamieson - I think this could be done with a far smaller change footprint. Instead of sticking with the original Then the slight annoyance is having to call |
|
@WilliamJamieson - one point of process is that only the reviewer should be checking the review check boxes in the PR description. Making a final determination on each of the review points should wait until the code is ready (or nearly ready) to be merged. |
@WilliamJamieson - can you address this in terms of a functional test that demonstrates the fix actually prevents parallel test failures consistently? Just passing CI once may not be sufficient. It looks like @pllim could consistently get a failure in a comment in #11966 so that would be a good thing to document. |
This is essentially what I did to start with in commit acb9858, @plim's initial comments lead me to believe that the regeneration of test data was undesirable. The further comment's lead me to make the changes you see now. Please let me know if you would like me to roll back the to that commit. |
Yes. When I initially discussed the race condition with @plim (off-line), with regard to the CI failures in PRs #11930 and #11931, I determined that I could replicate the failure on my local machine as described by the comment you allude to in #11966. I can demonstrate that merging the changes in this PR into the changes made by #11930 or #11931 always fixes the test failures I experience on my local machine. Note that further exploration of the race condition shows that arbitrarily manipulating the tests added in #11930 or #11931 causes different tests in |
|
@WilliamJamieson - thanks for the explanation. I would actually be OK with your first commit, but I think we can accommodate both testing efficiency and keeping the code somewhat clean with a hybrid approach of the first two commits:
I think this will be quick to implement if you go start from your first commit and then copy the |
c720fe0 to
2212098
Compare
I implemented this in my latest commit: 2212098. The changes still fix the error in #11930 and #11931. |
|
@WilliamJamieson - awesome, this is great from looking at the code, but now I see that the first CI test has failed. Once you get tests passing I will merge this. @pllim - this seems like a useful bug fix to backport to 4.3.x so I set the milestone to 4.3.2. Is that OK? The original code that brought in this issue is old, from 2017. |
Sure! It is up to the discretion of the subpackage maintainer, usually. 😉 |
|
The CI failure makes no sense to me... Maybe I'll restart to make sure it is not transient. |
@pllim - OK good. I was guessing that you originally set the milestone to 5.0 so I thought there might be a reason. |
Because this blocks a PR that is milestoned to 5.0. So, that is the minimum required milestone. |
pllim
left a comment
There was a problem hiding this comment.
Does look much cleaner and CI passed now. I am waiting for a final confirmation that this indeed still unblocks the modeling PR before merging. Thanks, everyone!
taldcroft
left a comment
There was a problem hiding this comment.
LGTM thanks @WilliamJamieson !
…972-on-v4.3.x Backport PR #11972 on branch v4.3.x (Fixed possible race condition in parallel testing)
Description
This pull request refactors
astropy/time/tests/test_methods.pyto remove a global variable used in test parameterization to avoid possible race conditions when running tests in parallel.Fixes #11966
Checklist for package maintainer(s)
This checklist is meant to remind the package maintainer(s) who will review this pull request of some common things to look for. This list is not exhaustive.
Extra CIlabel.no-changelog-entry-neededlabel.astropy-botcheck might be missing; do not let the green checkmark fool you.backport-X.Y.xlabel(s) before merge.