-
Notifications
You must be signed in to change notification settings - Fork 320
NAVAND-1108: test that reproduces the issue #6869
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
Merged
VysotskiVadim
merged 5 commits into
main
from
vv-reproduce-wrong-location-till-incident
Jan 26, 2023
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
130 changes: 130 additions & 0 deletions
130
...oidTest/java/com/mapbox/navigation/instrumentation_tests/core/UpcomingRouteObjectsTest.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,130 @@ | ||
| package com.mapbox.navigation.instrumentation_tests.core | ||
|
|
||
| import android.location.Location | ||
| import com.mapbox.navigation.base.options.NavigationOptions | ||
| import com.mapbox.navigation.base.options.RoutingTilesOptions | ||
| import com.mapbox.navigation.base.route.NavigationRoute | ||
| import com.mapbox.navigation.base.route.RouterOrigin | ||
| import com.mapbox.navigation.base.trip.model.RouteProgressState | ||
| import com.mapbox.navigation.core.MapboxNavigation | ||
| import com.mapbox.navigation.core.MapboxNavigationProvider | ||
| import com.mapbox.navigation.instrumentation_tests.R | ||
| import com.mapbox.navigation.instrumentation_tests.activity.EmptyTestActivity | ||
| import com.mapbox.navigation.instrumentation_tests.utils.MapboxNavigationRule | ||
| import com.mapbox.navigation.instrumentation_tests.utils.coroutines.routeProgressUpdates | ||
| import com.mapbox.navigation.instrumentation_tests.utils.coroutines.sdkTest | ||
| import com.mapbox.navigation.instrumentation_tests.utils.coroutines.setNavigationRoutesAndWaitForUpdate | ||
| import com.mapbox.navigation.instrumentation_tests.utils.readRawFileText | ||
| import com.mapbox.navigation.testing.ui.BaseTest | ||
| import com.mapbox.navigation.testing.ui.utils.getMapboxAccessTokenFromResources | ||
| import com.mapbox.navigation.testing.ui.utils.runOnMainSync | ||
| import kotlinx.coroutines.flow.first | ||
| import org.junit.Assert.assertEquals | ||
| import org.junit.Before | ||
| import org.junit.Ignore | ||
| import org.junit.Rule | ||
| import org.junit.Test | ||
| import java.net.URI | ||
|
|
||
| class UpcomingRouteObjectsTest : BaseTest<EmptyTestActivity>(EmptyTestActivity::class.java) { | ||
|
|
||
| @get:Rule | ||
| val mapboxNavigationRule = MapboxNavigationRule() | ||
|
|
||
| private lateinit var mapboxNavigation: MapboxNavigation | ||
|
|
||
| override fun setupMockLocation(): Location = mockLocationUpdatesRule.generateLocationUpdate { | ||
| latitude = 48.143406486859135 | ||
| longitude = 11.428011943347627 | ||
| } | ||
|
|
||
| @Before | ||
| fun setup() { | ||
| runOnMainSync { | ||
| mapboxNavigation = MapboxNavigationProvider.create( | ||
| NavigationOptions.Builder(activity) | ||
| .accessToken(getMapboxAccessTokenFromResources(activity)) | ||
| .routingTilesOptions( | ||
| RoutingTilesOptions.Builder() | ||
| .tilesBaseUri(URI(mockWebServerRule.baseUrl)) | ||
| .build() | ||
| ) | ||
| .build() | ||
| ) | ||
| } | ||
| } | ||
|
|
||
| @Test | ||
| @Ignore("waiting for the NN fix, see NN-449") | ||
| fun distanceToIncidentDoesNotChangeAfterAddingNewWaypointOnTheRouteGeometry() = sdkTest { | ||
| val (oneLegRoute, twoLegsRoute, incidentId) = | ||
| getRoutesFromTheSameOriginButDifferentWaypointsCount() | ||
|
|
||
| setRoutesOriginAsCurrentLocation(oneLegRoute, twoLegsRoute) | ||
|
|
||
| mapboxNavigation.startTripSession() | ||
| mapboxNavigation.setNavigationRoutesAndWaitForUpdate(oneLegRoute) | ||
| val upcomingIncidentForOneLeg = mapboxNavigation.routeProgressUpdates() | ||
| .first { it.currentState == RouteProgressState.TRACKING } | ||
| .upcomingRoadObjects | ||
| .first { it.roadObject.id == incidentId } | ||
|
|
||
| mapboxNavigation.setNavigationRoutesAndWaitForUpdate(twoLegsRoute) | ||
| val upcomingIncidentForTwoLegsRoute = mapboxNavigation.routeProgressUpdates() | ||
| .first { it.currentState == RouteProgressState.TRACKING } | ||
| .upcomingRoadObjects | ||
| .first { it.roadObject.id == incidentId } | ||
|
|
||
| assertEquals( | ||
| upcomingIncidentForOneLeg.distanceToStart, | ||
| upcomingIncidentForTwoLegsRoute.distanceToStart | ||
| ) | ||
| } | ||
|
|
||
| private fun setRoutesOriginAsCurrentLocation( | ||
| oneLegRoute: List<NavigationRoute>, | ||
| twoLegsRoute: List<NavigationRoute> | ||
| ) { | ||
| val origin = oneLegRoute.first().waypoints!!.first().location() | ||
| assertEquals(origin, twoLegsRoute.first().waypoints!!.first().location()) | ||
| mockLocationUpdatesRule.generateLocationUpdate { | ||
| latitude = origin.latitude() | ||
| longitude = origin.longitude() | ||
| } | ||
| } | ||
|
|
||
| private fun getRoutesFromTheSameOriginButDifferentWaypointsCount(): | ||
| Triple<List<NavigationRoute>, List<NavigationRoute>, String> { | ||
| val origin = "11.428011943347627,48.143406486859135" | ||
| val destination = "11.443258702449555,48.14554279886465" | ||
| val routeWithIncident = NavigationRoute.create( | ||
| directionsResponseJson = readRawFileText( | ||
| activity, | ||
| R.raw.route_through_incident_6058002857835914_one_leg | ||
| ), | ||
| routeRequestUrl = "https://api.mapbox.com/directions/v5/mapbox/driving-traffic/" + | ||
| "$origin;$destination" + | ||
| "?access_token=**&alternatives=true" + | ||
| "&annotations=closure,congestion_numeric,congestion,speed,duration,distance" + | ||
| "&geometries=polyline6&language=en&overview=full&steps=true", | ||
| routerOrigin = RouterOrigin.Offboard | ||
| ) | ||
| val routeWithIncidentTwoLegs = NavigationRoute.create( | ||
| directionsResponseJson = readRawFileText( | ||
| activity, | ||
| R.raw.route_through_incident_6058002857835914_two_legs | ||
| ), | ||
| routeRequestUrl = "https://api.mapbox.com/directions/v5/mapbox/driving-traffic/" + | ||
| "$origin;11.42945687746061,48.1436160028498" + | ||
| ";$destination" + | ||
| "?access_token=**&alternatives=true" + | ||
| "&annotations=closure,congestion_numeric,congestion,speed,duration,distance" + | ||
| "&geometries=polyline6&language=en&overview=full&steps=true", | ||
| routerOrigin = RouterOrigin.Offboard | ||
| ) | ||
| val incident = routeWithIncident.first() | ||
| .directionsRoute.legs()!!.first() | ||
| .incidents()!!.first() | ||
| return Triple(routeWithIncident, routeWithIncidentTwoLegs, incident.id()) | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Why do we expect them to be equal?
The routes are different, do they have the same geometry (at least until the incident)? If yes, it should be specified in the comments. If the geometry is different,
distanceToStartmay be different (it's distance along the route, not direct distance, 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.
Current location doesn't change and both routers heads to the same direction thought the same incident.
Uh oh!
There was an error while loading. Please reload this page.
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.
Thank you for the feedback. I will try to improve readability of the test
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.
@dzinad , I updated the test. Do you understand what and why it checks now?
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.
My point is that if we have the same origin and the same incident location, when we add a waypoint, distances may still differ. See the drawing.

And it's still not clear that the geometries from the origin until the incident are exactly the same.
Or am I missing something?
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 see your point, thank you. The routes I test follow the same roads. Like

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.
So the waypoint is strictly on the route's geometry? Could you mention it somewhere in the comment?