Break Our Application Like a User (Part II)
Internet connections are unreliable. Connections can randomly fail when we’re on a laptop or desktop, and it’s more common than it should be to have a low-quality data connection on cell phones. We need to ensure that our application can properly reconnect a user’s connection, even if the page has been open for a long time.
Define the test
A shopper should initially connect to the Channel when they load the application. The shopper should quickly reconnect to the Channel if they become disconnected. Once reconnected, the store should work as if the shopper was never disconnected. The shopper will miss any messages for the time that they are disconnected.
Write steps for the test
- Start the server in a freshly seeded state.
- Load the webpage.
- Kill the server to simulate a disconnection.
- Bring the server back online after one second.
- Release sneaker with
ID 1while viewing the page.
- Repeat all instructions with a wait time of five seconds and 30 seconds.
Write expectations for the test
- The shopper sees the “coming soon” shoes after step 2.
- The shopper’s WebSocket connection is disconnected after step 3.
- The shopper’s WebSocket connection is connected after step 4.
- The shopper sees the released shoe’s size selector after step 5.
We have a local server, so disconnecting our internet connection won’t impact our WebSocket connection. If this application were deployed, we would run these tests by disconnecting the internet rather than shutting down the server. Let’s run through these tests now. Follow these instructions and observe what happens.