Repository navigation
test(assignment): cover nearest-driver selection, radius expansion and claim contention - #309
Merged
Conversation
…d claim contention Unit tests for AssignmentService against an in-memory MongoDB with the real geoNear pipeline and escrow guard; only the Redlock wrapper is replaced by an in-process lock fake.
|
@lankeethebeast Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Closes #226
Summary
assignmentServicehad no tests. This adds 22 unit tests intests/assignmentService.test.ts, which follows the repo's flattests/layout. The issue namesbackend/tests/unit/services/, but that directory doesn't exist.Deliveries, escrows and driver positions are stored in MongoMemoryServer. That means proximity search runs the real
$geoNearpipeline against the real 2dsphere indexes, and assignment goes through the realdeliveryService.assignDriverescrow guard. OnlywithLock(Redlock/Redis) is replaced, by an in-process lock fake that records acquire/release and can simulate contention.What is covered
on_delivery.ASSIGNMENT_RADIUS_EXPANSION_STEPS, never goes pastDRIVER_PROXIMITY_MAX_RADIUS_M, and searches the cap only once.releaseClaim: when the escrow guard rejects (PENDING, DISPUTED, or no escrow), the driver goes back toisAvailable: true / onlinewith nocurrentDeliveryId, and the lock is released. If the rollback write itself fails, the original error still surfaces.autoAssignPendingDeliveries: only FUNDED, driverless deliveries are picked, oldest first, within the batch limit. Locked and failing deliveries are skipped without stopping the sweep, and the{ attempted, assigned }counts are checked.Verification
eslint and prettier are clean on the new file.
Notes
radiusMetersas the next, unsearched radius. For example, with 3 steps it searches 5/10/20/40 km but reports 50 km. The tests don't lock that value in. Happy to fix it in a follow-up if you'd like.releaseClaimresets availability only and never setscurrentDeliveryId. The tests assert that it staysnull.