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 2082 +2
Lines 77182 77201 +19
Branches 7831 7832 +1
=============================================
- Hits 54183 54182 -1
- Misses 20230 20250 +20
Partials 2769 2769 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
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.
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?
| result.failureValue().errorType(), | ||
| invalidStopIndex | ||
| ); | ||
| return result.toFailureResult(); |
There was a problem hiding this comment.
create a new result with trip id and datasource
| } | ||
|
|
||
| @Test | ||
| void testUpdateCascading() { |
There was a problem hiding this comment.
These tests just test something that we have now removed, right?
There was a problem hiding this comment.
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.
| break; | ||
| } | ||
| if (!matchFound) { | ||
| return Result.failure(new UpdateError(null, STOP_MISMATCH, i)); |
There was a problem hiding this comment.
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.
I have added validation rules for too few and too many calls.
| StopLocation stop = builder.stops.original(i); | ||
|
|
||
| boolean matchFound = false; | ||
| for (CallWrapper call : calls) { |
There was a problem hiding this comment.
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.
I have added validation rules for too few and too many calls.
| assertTrue(addedTrip.isFailure(), "Trip creation should fail"); | ||
| assertEquals( | ||
| UpdateError.UpdateErrorType.NO_VALID_STOPS, | ||
| UpdateError.UpdateErrorType.UNKNOWN_STOP, |
There was a problem hiding this comment.
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.
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.
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.
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.
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