55 lines
2.0 KiB
Go
55 lines
2.0 KiB
Go
package assignment
|
|
|
|
import (
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
// The per-miler concurrent-stop cap.
|
|
//
|
|
// This is the knob that now decides how much one rider carries, because
|
|
// eligibility no longer stops at the first order. It is read per call so it
|
|
// can be changed without a redeploy — and a typo must never uncap the fleet.
|
|
func TestMaxActiveBookings(t *testing.T) {
|
|
cases := []struct {
|
|
env string
|
|
want int64
|
|
why string
|
|
}{
|
|
{"", defaultMaxActive, "unset falls back to the default"},
|
|
{"10", 10, "a plain number is honoured"},
|
|
{" 8 ", 8, "surrounding whitespace is tolerated"},
|
|
{"1", 1, "one stop at a time is a legitimate policy"},
|
|
{"0", defaultMaxActive, "zero would assign to nobody — treated as unset, not as a cap"},
|
|
{"-4", defaultMaxActive, "negative is meaningless here"},
|
|
{"lots", defaultMaxActive, "a typo must not uncap the fleet"},
|
|
{"3.5", defaultMaxActive, "not an integer"},
|
|
}
|
|
|
|
for _, tc := range cases {
|
|
t.Setenv("MILER_MAX_ACTIVE_BOOKINGS", tc.env)
|
|
if got := maxActiveBookings(); got != tc.want {
|
|
t.Errorf("MILER_MAX_ACTIVE_BOOKINGS=%q gave %d, want %d (%s)", tc.env, got, tc.want, tc.why)
|
|
}
|
|
}
|
|
}
|
|
|
|
// The cap counts only stops assigned since midnight India time, so an order
|
|
// left open yesterday or last month no longer blocks a working rider.
|
|
func TestStartOfISTDay(t *testing.T) {
|
|
ist := time.FixedZone("IST", 5*3600+30*60)
|
|
cases := []struct{ now, want time.Time }{
|
|
// 11:43 IST on 6 Oct -> 00:00 IST 6 Oct
|
|
{time.Date(2026, 10, 6, 11, 43, 0, 0, ist), time.Date(2026, 10, 6, 0, 0, 0, 0, ist)},
|
|
// 20:00 UTC on 5 Oct is already 01:30 on 6 Oct in India
|
|
{time.Date(2026, 10, 5, 20, 0, 0, 0, time.UTC), time.Date(2026, 10, 6, 0, 0, 0, 0, ist)},
|
|
// 18:29 UTC on 5 Oct is still 23:59 on 5 Oct in India
|
|
{time.Date(2026, 10, 5, 18, 29, 0, 0, time.UTC), time.Date(2026, 10, 5, 0, 0, 0, 0, ist)},
|
|
}
|
|
for _, c := range cases {
|
|
if got := startOfISTDay(c.now); !got.Equal(c.want) {
|
|
t.Errorf("startOfISTDay(%v) = %v, want %v", c.now, got, c.want)
|
|
}
|
|
}
|
|
}
|