In the logistics service there is an HTTP handler POST /shipments/status-batch that accepts JSON of the form { "request_id": "...", "ids": ["S-1", "S-2"] } and synchronously updates the status of the specified shipments in memory to dispatched.
A review of changes in the PR is needed. Assume the handler contract is as follows:
Content-Type: application/json.request_id and a non-cancelled context: 200 OK and JSON { "updated": <number>, "status": "accepted" }.request_id has already been processed before, the side effect must not be repeated, and the response must still be the same 200 OK with the previous number of updated records.408 Request Timeout.Assumptions and environment:
net/http, with one Store instance per process.go test -race or parallel HTTP requests to one process.What to check in the PR:
request_id is respected;Reproduction steps:
Store via NewStore() and mount HandleBatchStatus on POST /shipments/status-batch.request_id and verify that both shipments receive dispatched status.request_id and check that the number of updates in the response matches the first call, and that the state is not changed again.-race.Context and verify that storage state does not change and the response status is 408.Go 1.24.0, standard library only. Execution in one process, Store is shared between concurrent HTTP requests. To check races, run go test -race or a custom parallel request driver. It is assumed that context cancellation can happen before entering the critical section, and the handler must account for this before the first change to shared state.
Use line comments to explain the problem, its impact, the fix and how to test it.