Skip to content

Commit

Permalink
core: stdcm: fix corner cases in blockRoutes map
Browse files Browse the repository at this point in the history
We used to not add entries in some cases,
and the map was shared across different instances
  • Loading branch information
eckter committed May 2, 2024
1 parent b86407f commit 02d2995
Show file tree
Hide file tree
Showing 2 changed files with 147 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ private class InfraExplorerImpl(
this.blockInfra,
this.blocks.shallowCopy(),
this.routes.shallowCopy(),
this.blockRoutes,
this.blockRoutes.toMutableMap(),
this.incrementalPath.clone(),
this.pathPropertiesCache,
this.currentIndex,
Expand All @@ -271,8 +271,10 @@ private class InfraExplorerImpl(
var nBlocksToSkip = 0
val pathFragments = arrayListOf<PathFragment>()
var pathStarted = incrementalPath.pathStarted
val addedBlocks = mutableListOf<BlockId>()

for (block in routeBlocks) {
addedBlocks.add(block)
if (block == firstLocation?.edge) {
seenFirstBlock = true
}
Expand All @@ -298,14 +300,14 @@ private class InfraExplorerImpl(
travelledPathEnd = Distance.ZERO
)
)
blockRoutes.getOrPut(block) { mutableSetOf() }.add(route)
pathStarted = true
if (endPath) break // Can't extend any further
}
}
assert(seenFirstBlock)
blocks.addAll(routeBlocks)
blocks.addAll(addedBlocks)
routes.add(route)
for (block in addedBlocks) blockRoutes.getOrPut(block) { mutableSetOf() }.add(route)
for (i in 0 ..< nBlocksToSkip) moveForward()
for (pathFragment in pathFragments) incrementalPath.extend(pathFragment)

Expand Down
142 changes: 142 additions & 0 deletions tests/tests/regression_tests_data/infra_explorer_crash.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
{
"error_type": "STDCM",
"code": 500,
"error": "{\"status\":500,\"type\":\"core:unknown_error\",\"context\":{\"stack_trace\":[\"InfraExplorer.kt:176\",\"InfraExplorerWithEnvelopeImpl.kt:-1\",\"STDCMSimulations.kt:114\",\"STDCMSimulations.kt:55\",\"STDCMEdgeBuilder.kt:162\",\"STDCMEdgeBuilder.kt:124\",\"STDCMGraph.kt:104\",\"STDCMPathfinding.kt:152\",\"STDCMPathfinding.kt:116\",\"STDCMPathfinding.kt:59\",\"STDCMEndpoint.kt:66\",\"FkRegex.java:153\",\"FkRegex.java:217\",\"FkChain.java:72\",\"TkFork.java:98\",\"TkFallback.java:84\",\"TkFallback.java:66\",\"TkWrap.java:58\",\"TkSlf4j.java:110\",\"BkBasic.java:123\",\"BkBasic.java:99\",\"BkSafe.java:46\",\"BkWrap.java:51\",\"BkParallel.java:81\",\"ThreadPoolExecutor.java:1136\",\"ThreadPoolExecutor.java:635\",\"Thread.java:840\"],\"exception_type\":\"class java.lang.NullPointerException\",\"url\":\"http://localhost:8080/stdcm\"},\"message\":\"An unknown exception was thrown\"}",
"infra_name": "small_infra",
"path_payload": {},
"stdcm_payload": {
"infra_id": 1,
"rolling_stock_id": 515,
"timetable_id": 134,
"start_time": 41836,
"maximum_departure_delay": 13945,
"maximum_run_time": 31875,
"margin_before": 442,
"margin_after": 205,
"steps": [
{
"duration": 0,
"waypoints": [
{
"track_section": "TG0",
"offset": 951.1704278320904
}
]
},
{
"duration": 197.37616881543562,
"waypoints": [
{
"track_section": "TG0",
"offset": 544.0143798050083
}
]
},
{
"duration": 866.9112878148477,
"waypoints": [
{
"track_section": "TC0",
"offset": 227.31827592351112
}
]
},
{
"duration": 1,
"waypoints": [
{
"track_section": "TA6",
"offset": 5841.495397000809
}
]
}
],
"comfort": "STANDARD",
"standard_allowance": {
"value_type": "percentage",
"percentage": 0
}
},
"prelude": [
{
"path_payload": {
"infra": 1,
"name": "foo",
"steps": [
{
"duration": 161.09860354664073,
"waypoints": [
{
"track_section": "TA5",
"offset": 23.95502360287256
}
]
},
{
"duration": 401.34324494528494,
"waypoints": [
{
"track_section": "TA5",
"offset": 39.63166791001232
}
]
},
{
"duration": 0,
"waypoints": [
{
"track_section": "TD1",
"offset": 18783.00499771772
}
]
},
{
"duration": 0,
"waypoints": [
{
"track_section": "TH0",
"offset": 328.92934635392834
}
]
},
{
"duration": 1,
"waypoints": [
{
"track_section": "TH1",
"offset": 3705.1089040007237
}
]
}
]
},
"schedule_payload": {
"timetable": 134,
"path": 7567,
"schedules": [
{
"train_name": "foo",
"labels": [],
"departure_time": 61596,
"allowances": [
{
"allowance_type": "engineering",
"begin_position": 9131.094438287506,
"end_position": 34160.65466558349,
"value": {
"value_type": "percentage",
"percentage": 6.560122985216419
},
"capacity_speed_limit": 17.768277770359386,
"distribution": "LINEAR"
}
],
"initial_speed": 0,
"rolling_stock_id": 515,
"speed_limit_category": "foo"
}
]
}
}
]
}

0 comments on commit 02d2995

Please sign in to comment.