Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix race in execution of tests #6177

Merged

Conversation

jtorin
Copy link
Contributor

@jtorin jtorin commented Oct 18, 2024

Summary

Make the test itinerary instance non-static as it's modified in some tests.
Specifically, an itinerary can be flagged for deletion in one test, which affects the assertions in the next test.

Without this, tests may fail if they are executed in a certain order. This may be because LC_COLLATE is not set in the environment.

Similar code

Searching for this idiom in the tree:

private static final Itinerary INSTANCE = newItinerary( ... );

...reveals other usages, although that presently they do not cause build problems. But in the worst case, it could be that a test passes because a previously executed test provides the wanted state.

Bonus observation

Itinerary.isFlaggedForDeletion() calls getSystemNotices() which in turn makes a copy of the systemNotices collection. This seems wasteful and just generates GC churn.

@jtorin jtorin requested a review from a team as a code owner October 18, 2024 13:24
@jtorin jtorin added the Skanetrafiken On skanetrafikens roadmap label Oct 18, 2024
Copy link

codecov bot commented Oct 18, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 69.90%. Comparing base (15ba54a) to head (48399cc).
Report is 53 commits behind head on dev-2.x.

Additional details and impacted files
@@              Coverage Diff              @@
##             dev-2.x    #6177      +/-   ##
=============================================
- Coverage      69.93%   69.90%   -0.03%     
+ Complexity     17727    17722       -5     
=============================================
  Files           1996     1998       +2     
  Lines          75402    75443      +41     
  Branches        7717     7718       +1     
=============================================
+ Hits           52730    52740      +10     
- Misses         19995    20024      +29     
- Partials        2677     2679       +2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@jtorin jtorin changed the title Make the test itinerary instance non-static as it's modified in some tests. Fix race in execution of tests Oct 22, 2024
@optionsome optionsome requested review from t2gran, optionsome and habrahamsson-skanetrafiken and removed request for optionsome October 22, 2024 09:20
…tests.

Specifically, an itinerary can be flagged for deletion in one test, which
affects the assertions in the next test.

Without this, tests may fail if they are executed in a certain order.
This may be because LC_COLLATE is not set in the environment.
@jtorin jtorin force-pushed the avoid-modified-testobject-reuse branch from eac5d35 to d34f27f Compare October 22, 2024 09:45
@jtorin
Copy link
Contributor Author

jtorin commented Oct 22, 2024

Updated PR with variable names reflecting that they are no longer static.

@t2gran t2gran added this to the 2.7 (next release) milestone Oct 22, 2024
@t2gran
Copy link
Member

t2gran commented Oct 22, 2024

Itinerary.isFlaggedForDeletion() calls getSystemNotices() which in turn makes a copy of the systemNotices collection. This seems wasteful and just generates GC churn.

Would you mind changing the isFlaggedForDeletion() it can safely be done in this PR:

  public boolean isFlaggedForDeletion() {
    return !systemNotices.isEmpty();
  }

t2gran
t2gran previously approved these changes Oct 22, 2024
Copy link
Member

@t2gran t2gran left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks ok, I would appreciate if you fixed the Itinerary.isFlaggedForDeletion() in this PR or in a sep PR. But, it is not required to merge the PR .

@jtorin
Copy link
Contributor Author

jtorin commented Oct 24, 2024

This looks ok, I would appreciate if you fixed the Itinerary.isFlaggedForDeletion() in this PR or in a sep PR. But, it is not required to merge the PR .

I've added a one-liner commit that simplifies the Itinerary.isFlaggedForDeletion() implementation.

@optionsome optionsome requested a review from t2gran October 24, 2024 14:23
@jtorin jtorin merged commit 25e8c0a into opentripplanner:dev-2.x Oct 25, 2024
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Skanetrafiken On skanetrafikens roadmap Skip Changelog
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants