-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Reject SIRI messages with invalid stops and missing times #6499
base: dev-2.x
Are you sure you want to change the base?
Reject SIRI messages with invalid stops and missing times #6499
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## dev-2.x #6499 +/- ##
=============================================
- Coverage 70.20% 70.18% -0.02%
+ Complexity 18313 18309 -4
=============================================
Files 2080 2081 +1
Lines 77182 77197 +15
Branches 7831 7832 +1
=============================================
- Hits 54183 54181 -2
- Misses 20230 20249 +19
+ Partials 2769 2767 -2 ☔ View full report in Codecov by Sentry. |
ab30c6a
to
02cf113
Compare
import org.opentripplanner.updater.trip.TripInput; | ||
import org.opentripplanner.updater.trip.siri.SiriEtBuilder; | ||
|
||
class IncompleteMessageTest implements RealtimeTestConstants { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Back when I started adding these module tests @t2gran asked me to put these into packages to group them by feature. If you like this pattern, can you put this one into the package rejection
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
result.failureValue().errorType(), | ||
invalidStopIndex | ||
); | ||
return result.toFailureResult(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
create a new result with trip id and datasource
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
@@ -424,132 +434,6 @@ void testUpdateUpdatedStop() { | |||
assertEquals(RealTimeState.MODIFIED, updatedTimes.getRealTimeState()); | |||
} | |||
|
|||
@Test | |||
void testUpdateCascading() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These tests just test something that we have now removed, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, testUpdateCascading
assumes that we accept a message with fewer calls than in the scheduled trip. We now refuse these messages except for full cancellation, and full cancellation is tested elsewhere.
testCreateStopPatternNoCalls
and testCreateStopPatternSingleCall
call ModifiedTripBuilder.createStopPattern
with preconditions that are now impossible.
@@ -268,10 +281,13 @@ static StopPattern createStopPattern( | |||
alreadyVisited.add(call); | |||
break; | |||
} | |||
if (!matchFound) { | |||
return Result.failure(new UpdateError(null, STOP_MISMATCH, i)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We will fail with this error if there is a missing call as well. I guess that's not a big probeblem but it seems like an inaccurate error code for that case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have added validation rules for too few and too many calls.
@@ -242,16 +249,22 @@ static StopPattern createStopPattern( | |||
for (int i = 0; i < numberOfStops; i++) { | |||
StopLocation stop = builder.stops.original(i); | |||
|
|||
boolean matchFound = false; | |||
for (CallWrapper call : calls) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The logic in this method will still accept if there are too many calls in the ET update. Maybe fixing that is part of your other extra-call-PR?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have added validation rules for too few and too many calls.
.../java/org/opentripplanner/updater/trip/siri/moduletests/rejection/IncompleteMessageTest.java
Outdated
Show resolved
Hide resolved
@@ -551,7 +551,7 @@ void testAddedTripFailOnUnknownStop() { | |||
|
|||
assertTrue(addedTrip.isFailure(), "Trip creation should fail"); | |||
assertEquals( | |||
UpdateError.UpdateErrorType.NO_VALID_STOPS, | |||
UpdateError.UpdateErrorType.UNKNOWN_STOP, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is a test for UNKNOWN_STOP here but perhaps you could add one for regular, non-extra-journey updates.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have added unit tests for unknown stop and stop mismatch
# Conflicts: # application/src/test/java/org/opentripplanner/updater/trip/siri/ModifiedTripBuilderTest.java # application/src/test/java/org/opentripplanner/updater/trip/siri/moduletests/InterpolationTest.java
* Full cancellation of a trip. | ||
*/ | ||
private Result<TripUpdate, UpdateError> cancelTrip(RealTimeTripTimes newTimes) { | ||
LOG.debug("Trip is cancelled"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a pretty useless log message, isn't it? I think you should either add the trip id or remove it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pretty useless indeed. I've removed it.
@@ -242,16 +253,22 @@ static StopPattern createStopPattern( | |||
for (int i = 0; i < numberOfStops; i++) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add a line of documentation in both createStopPattern()
and applyUpdates()
that the number of calls are guaranteed to be the same as the numberOfStops. I think that will make it easier to if we decide to refactor this code in the future.
Summary
This PR applies strictly the validation rules specified in the Nordic SIRI profile.
In particular:
This PR ensures that messages that fail these validation rules are rejected.
As a consequence, the time interpolation logic is not used anymore and can be removed .
The rules are relaxed for full trip cancellation: a message is accepted even if it contains incomplete times or invalid stops.
Issue
No
Unit tests
Updated unit tests.
Documentation
No