Break Our Application Like a User (Part II)

Test the application by looking at problems from a user's perspective.

Internet-related actions

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.

The official Channels JavaScript client handles reconnection attempts for us. It uses a back-off algorithm that starts with frequent retries and waits a few seconds between attempts. If needed, we can change the reconnection algorithm to be more or less aggressive, but the default one will work well for most applications. We’ll execute a test case to ensure that users can reconnect to the store when they become disconnected.

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

  1. Start the server in a freshly seeded state.
  2. Load the webpage.
  3. Kill the server to simulate a disconnection.
  4. Bring the server back online after one second.
  5. Release sneaker with ID 1 while viewing the page.
  6. 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.

Get hands-on with 1200+ tech skills courses.