191 handle last product
Closes #191 (closed)
This PR handles the previousProductId
field sent in broadcast messages from the websocket. Please take an in depth look at the tests in AwsProductReceiverTest
, I tried to make the tests easy to understand and show what they were doing (I removed the custom inherited TestAwsProductReceiver
class in favor of using a mocking library) and I think those adequately cover the scenarios below:
The scenarios that this covers are the following:
- Server fails to send a message and it gets re-queued -> client doesn't even know this happens and proceeds as normal
Nothing to be done client side
- Server sends a message but it gets re-queued (due to another client throwing an irrecoverable exception or something) -> client will receive a duplicate message but ignore it and client updates its previousProductId to the message
Client side: we process the message but nothing actually happens because it is a duplicate. The client's internal previousProductId
state gets updated to
- Server sends a message but client never receives it -> causes client to go into catchup mode and within this there are 2 paths:
- Broadcast is received during catchup mode -> Client ignores message and catchup mode returns the newest message
Client updates its previousProductId
to the broadcasted message but it ignores processing. Once the productsCreatedAfterClient
makes all its requests, the internal state of previousProductId
will match what the most recent product is and it will turn off catchup and start processing again
- Broadcast is received after catchup mode -> Client is already up to date after catchup mode and receives message as normal
Nothing to be done client side