Skip to content

Conversation

evansiroky
Copy link
Contributor

@evansiroky evansiroky commented Feb 23, 2019

Checklist

  • Appropriate branch selected (all PRs must first be merged to dev before they can be merged to master)
  • Any modified or new methods or classes have helpful JSDoc and code is thoroughly commented
  • The description lists all applicable issues this PR seeks to resolve
  • The description lists any configuration setting(s) that differ from the default settings
  • All tests and CI builds passing

Description

This PR adds some tests to make sure that infinite loops don't happen when trips have an empty array of stop times. Fixes #426.

@codecov-io
Copy link

codecov-io commented Feb 23, 2019

Codecov Report

Merging #427 into dev will increase coverage by 0.09%.
The diff coverage is 100%.

Impacted file tree graph

@@           Coverage Diff            @@
##             dev    #427      +/-   ##
========================================
+ Coverage    5.3%   5.39%   +0.09%     
========================================
  Files        322     322              
  Lines      15469   15532      +63     
  Branches    4674    4695      +21     
========================================
+ Hits         820     838      +18     
- Misses     12497   12521      +24     
- Partials    2152    2173      +21
Impacted Files Coverage Δ
lib/types/index.js 0% <ø> (ø) ⬆️
lib/mock-data.js 100% <100%> (ø) ⬆️
lib/editor/util/index.js 29.48% <100%> (+20.15%) ⬆️
lib/main.js 0% <0%> (ø) ⬆️
lib/manager/actions/user.js 0% <0%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 0f10fa2...772f37c. Read the comment docs.

@landonreed
Copy link
Contributor

landonreed commented Mar 25, 2019

@evansiroky, can you describe how this scenario (editing trips with no stop times) came about? I agree that we should not fall into an infinite loop, but I'm a bit confused about the larger context. Ideally, we would prevent users from editing trips with no stop times, but I guess if a feed were imported with no stop times, this situation could occur.

I'll also note that just because we have issue and PR templates with a bunch of sections to fill out now, we should be careful to still create well-crafted tickets. I think the templates can quickly become a nuisance that get ignored especially if they don't apply to every situation well.

@landonreed landonreed assigned evansiroky and unassigned landonreed Mar 25, 2019
@evansiroky
Copy link
Contributor Author

Agreed that I should have filled out issue #426 better. I just edited that issue to wrote about how I discovered the bug while changing the service_id and then looking at the timetable editor.

@evansiroky evansiroky assigned landonreed and unassigned evansiroky Mar 28, 2019
tripId: string,
useFrequency: boolean
tripShortName: ?string,
useFrequency?: boolean,
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this type change correct? Shouldn't useFrequency always be defined because it is defined in the GraphQL query?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I believe if the value is undefined in the database, it will not come through in the response of the GraphQL query. If you look at a response from GraphQL in chrome dev tools you should see this.

}
if (a.stopTimes.length === 0 && b.stopTimes.length === 0) return 0
if (a.stopTimes.length === 0) return -1
if (b.stopTimes.length === 0) return 1
Copy link
Contributor

Choose a reason for hiding this comment

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

This code block definitely deserves a descriptive comment describing: why it's sorting this way, why there might be a trip with no stop times, etc. It's the only change to non-test code in the whole PR, I think it's important that something like this have some comments.

@landonreed landonreed assigned evansiroky and unassigned landonreed Apr 1, 2019
@evansiroky
Copy link
Contributor Author

Just added some more comments about the additional checks in the sort function.

@evansiroky evansiroky assigned landonreed and unassigned evansiroky Apr 1, 2019
@landonreed landonreed merged commit 111f418 into dev Apr 2, 2019
@landonreed landonreed deleted the sortandfiltertrips-fix branch April 2, 2019 19:03
@landonreed
Copy link
Contributor

🎉 This PR is included in version 4.1.0 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Infinite loop in sortAndFilterTrips
3 participants