When Offline Sync Works… Until the Network Drops Mid-Edit
The app worked perfectly, until the phone went offline
We had this offline editing feature that everyone thought was already tested properly..... you could edit something without a connection, the app would keep the change locally, and once the connection came back it would sync everything with the server
The E2E test was pretty simple, take the phone offline, make an edit, bring the connection back, check the server, everything passed every time. So naturally we thought we were done with it
Then we found a case we hadn't tested at all
The test always started with the phone already offline, but real users obviously don't know when their connection is going to disappear..... someone can start editing while they're connected, lose the connection halfway through, and just keep going because the app is still responding normally
That's what eventually exposed the bug
Someone starts editing, the app sends a request, the connection disappears, the request fails or gets stuck, and the user keeps making changes. Now the phone has the newer version while the server still has the older one
When the connection comes back, the app has to figure out which version should win, and in our case it didn't always get that right
The UI was still showing the user's latest changes so everything looked completely normal from their side..... no error, no warning, nothing that would make them think their change wasn't safe
They could finish editing, close the app and move on thinking everything had been saved
Then they would open it later and the old value would be back
That was the really annoying part because the user wouldn't even know when it happened. They could make a change at 6pm, close the app, come back later and just wonder why their edit had disappeared
We could reproduce it sometimes, but only when we started messing around with the timing of the network connection and the requests. It wasn't really an offline bug in the way we originally thought about offline bugs
It was a timing problem between the local change, the request that was already running, the connection disappearing and then coming back again.....
And that made me look at our offline tests a little differently
It's not enough to test what happens when the app is already offline. You also need to test what happens when the connection disappears while something is already happening
Because users don't wait for requests to finish before doing the next thing. They lose Wi-Fi in a train, switch networks, lock their phone halfway through an edit, come back after ten minutes or tap the same button again because they're not sure if the first tap worked
Our tests are usually very clean and predictable
Real users are not.....
And I think that's where a lot of these bugs come from, those tiny moments where the app is changing from one state to another and the user just keeps doing what they were doing
Nothing crashes, nothing turns red, the test suite stays green
The app just quietly forgets something the user thought they had saved