updates on the order bulk fix
This commit is contained in:
@@ -30,7 +30,7 @@ func eligibilityDB(t *testing.T) *gorm.DB {
|
||||
}
|
||||
gdb := testpg.Open(t, dsn, "assignment_eligibility_test")
|
||||
all := []any{&models.PickupBooking{}, &models.BookingAssignment{}, &models.MilerProfile{},
|
||||
&models.BookingStageEvent{}, &models.BookingDestination{}}
|
||||
&models.BookingStageEvent{}, &models.BookingDestination{}, &models.MilerDutyLog{}}
|
||||
if err := gdb.Migrator().DropTable(all...); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -39,7 +39,14 @@ func eligibilityDB(t *testing.T) *gorm.DB {
|
||||
}
|
||||
prev := db.DB
|
||||
db.DB = gdb
|
||||
t.Cleanup(func() { db.DB = prev })
|
||||
// commitAssignment fires customer notifications in a goroutine that can
|
||||
// outlive the test. Putting back a nil db.DB would make it panic; leaving
|
||||
// the closed test handle makes it fail quietly instead.
|
||||
t.Cleanup(func() {
|
||||
if prev != nil {
|
||||
db.DB = prev
|
||||
}
|
||||
})
|
||||
t.Setenv("MILER_MAX_ACTIVE_BOOKINGS", "")
|
||||
t.Setenv("ASSIGNMENT_MAX_GPS_AGE_MINUTES", "")
|
||||
return gdb
|
||||
@@ -163,7 +170,7 @@ func TestConcurrentAttemptsAssignOnce(t *testing.T) {
|
||||
go func(i, r int) {
|
||||
defer wg.Done()
|
||||
b := booking
|
||||
err := commitAssignment(&b, &milerCandidate{profile: models.MilerProfile{Userid: r}}, nil)
|
||||
_, err := commitAssignment(&b, &milerCandidate{profile: models.MilerProfile{Userid: r}}, nil, nil)
|
||||
mu.Lock()
|
||||
defer mu.Unlock()
|
||||
switch {
|
||||
@@ -198,7 +205,7 @@ func TestCancelledBookingIsNotAssigned(t *testing.T) {
|
||||
mustDo(t, gdb.First(&stale, id).Error)
|
||||
mustDo(t, gdb.Model(&models.PickupBooking{}).Where("bookingid = ?", id).Update("status", constants.BookingCancelled).Error)
|
||||
|
||||
err := commitAssignment(&stale, &milerCandidate{profile: models.MilerProfile{Userid: 38}}, nil)
|
||||
_, err := commitAssignment(&stale, &milerCandidate{profile: models.MilerProfile{Userid: 38}}, nil, nil)
|
||||
if !errors.Is(err, errBookingTaken) {
|
||||
t.Fatalf("want errBookingTaken, got %v", err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user