fix: address code review findings

This commit is contained in:
2026-08-19 13:26:05 +03:00
parent 4a7be531ed
commit c2bdffb0ab
2 changed files with 25 additions and 8 deletions

View File

@@ -413,6 +413,9 @@ func TestRouteReSearchOnChange(t *testing.T) {
}
}
// Reset LastChecked to force re-check (bypass the 1-hour cache)
itinerary.LastChecked = time.Now().Unix() - 7200
// Re-check for changes after simulating cancellation
checked2 := graph.CheckAndRescheduleRoute(itinerary, "s1", "s3", SearchOptions{MaxTransfers: 5}, nil, nil)
t.Logf("After cancellation - NeedsReSearch: %v, ReSearchReason: %s", checked2.NeedsReSearch, checked2.ReSearchReason)
@@ -440,12 +443,20 @@ func TestRouteReSearchOnChange(t *testing.T) {
ReSearchReason: "",
}
// For major delay, the check uses: edge.Duration > leg.Cost*2 && leg.Cost > 0
// With Cost=500, threshold would be 1000. Setting duration to 2000 should trigger.
// Reset the s1->s2 edge duration to normal value before testing major delay
for _, edge := range graph.edges {
if edge.From.ID == "s1" && edge.To.ID == "s2" {
edge.Duration = 3600 // Reset to normal duration
break
}
}
// For major delay, the check uses: edge.Duration > leg.Duration*2 && leg.Duration > 0
// With leg.Duration=3600, threshold would be 7200. Setting duration to 8000 should trigger.
for _, edge := range graph.edges {
if edge.From.ID == "s2" && edge.To.ID == "s3" {
edge.Duration = 2000 // > 500*2 = 1000, should trigger major delay
t.Logf("Set s2->s3 edge duration to %d (simulating major delay, threshold=1000)", edge.Duration)
edge.Duration = 8000 // > 3600*2 = 7200, should trigger major delay
t.Logf("Set s2->s3 edge duration to %d (simulating major delay, threshold=7200)", edge.Duration)
break
}
}