Opening a couple of browser windows and clicking around was more than sufficient for testing the initial version of ReactVR pairs. Implementing a simple middleware to log actions took advantage of the Redux approach of reifying events to allow a glance at the console to reveal precisely which sequence of actions caused a problem.
Adding support for optimistic
made testing more challenging. In order to test conflict resolution,
conflicting actions needed to be generated on multiple clients almost
simultaneously. After a couple of sessions testing broken versions of
pairs with friends it was clear that a more efficient process was
required. Fortunately, Redux actions are independent of the UI events
which generate them. This separation of concerns made it trivial to
randomly generate and dispatch actions without driving the UI. Opening
clients dispatching several randomly generated actions per second made
it easy to generate conflicts to test optimistic consistency policies
while watching games play out made it easy to eyeball the results to
check that they were correct. This random action generation mechanism
can be enabled by adding
?random as the query string when opening
the Pairs example in a browser.
One of the problems found by this approach was that clients didn’t always end up eventually consistent. One client would end up with all squares shown and all pairs scored, while another would have some squares hidden. After some digging it turned out that in these cases the master would be reducing a hide action followed by a score action, while the other client would reduce the actions in the reverse order, causing the hide acton to be invalid. Without a way for a non-master client to let the master know about the conflict the master would not send a sync action and the clients would not end up eventually consistent.
This problem identified a limitation with the optimistic
clientPredictionConsistency policy: if any sequence of actions
causes a conflict then every ordering of those actions must also cause
a conflict in order for the clients to end up eventually
consistent. The fix for the hide-score case seemed clear: if the score
action was only valid if the pair was shown then both orderings of
those actions would generate a conflict and so the master would
generate a sync action regardless of the order in which it reduced the
actions. Some more eyeballing seemed to suggest that the problem had
been solved, but a better way to test the property that sync action
generation is independent of action order was to write a property
I could now test that the property held for thousands of action sequences in a few seconds and so I found the next bug almost immediately. While my change to make any ordering of test then hide generate a sync had fixed one problem it had introduced another. The validity of score events was now dependent on the preceding show events, so it was possible for show-show-score to be valid but for every other order of those events to cause the score event to be invalid and so not reduced.
At this point I took a step back. The only situation that should cause a conflict that needs to be resolved is when more than one player tries to score the same pair. In this situation clients don’t have enough information to resolve the conflict and a master client needs to pick an ordering and communicate the result to the other clients. In the case of hide and score actions every client can do the right thing. Hide actions can be made to not hide scored squares and score actions can be made to show pairs. With the reducers changed to work in this way hide actions can always be reduced and score actions are only invalid when they conflict with each other. With these changes in place the validation logic becomes dramatically simpler to reason about and the property based tests were unable to find any more cases which would not be eventually consistent even after thousands of runs.
Testing distributed systems is hard, but combining replicated Redux
with property based tests has proved to be a powerful way to gain a
high degree of confidence that applications will work correctly
despite limitations in the current simplistic
clientPredictionConsistency mechanism. The same property based tests
will enable new optimistic consistency mechanisms without those
limitations to be developed far more quickly in future.
If you’d like to play the ReactVR version of pairs or see the rest of the code, it’s available on github here.
All code in this post is made available under the ReactVR examples license.
ReactVR Redux Revisited
There were a couple of aspects of my previous experiments building networked ReactVR experiences with Redux that were unsatisfactory: there wasn’t a clean separation between the application logic and network code and, while the example exploited idempotency to reduce latency for some actions, actions which could generate conflicts used ...read more
Creating A Safe Environment For People In VR
At the 3rd Party Dev State of the Union at EVE Fanfest 2016 earlier this year, CCP FoxFour drew my attention to a limitation of the current approach used by crestmatic to generate CREST documentation: it only discovers resources always reachable from the API root from the perspective of the ...read more
Strange Tales From Other Worlds
Towards A Generic Media Type System
The early days of RESTful hypermedia API design tends to involve lots of homogeneous collections. In the case of CREST vnd.ccp.eve.Api-v1 pointed to the logged in vnd.ccp.eve.ccp.Capsuleer-v1 which pointed to a vnd.eve.ccp.CharacterCollection-v1 of contacts which pointed to many vnd.ccp ...read more
A year ago I gave a talk at EVE Vegas about building RESTful CREST applications. My #1 recommendation was to specify representations in requests, but that’s hard to do when there is little documentation on which representations are available and what they contain.
Fortunately CREST is self describing: send ...read more
Free Tests For Everyone!
Modern software development is sometimes colourfully described as being similar to firing tracer bullets at a target. Rather than spending time doing a lot of research, design and specification up front, the smallest, simplest version of the software is built and the feedback gathered from its use is used to ...read more
Investing In Testing
Last year I was talking to an engineer at Droidcon London who was working on an Android app with 100% test coverage. I immediately asked whether he thought 100% test coverage was worthwhile: many software engineering teams strive to achieve 100% test coverage, but few succeed because it’s an ...read more
There have been a number of blog posts recently about exciting new organisational structures. As Cory points out “Every early stage company thinks it has reinvented management”: a very dangerous belief when betting on a new organisational structure can be much riskier than betting on the wrong product.
It starts ...read more
Beyond Time Dilation?
EVE online is a remarkable game. On Monday over 2000 people spent over 20 hours destroying virtual spaceships worth 200,000 USD in real money in what was the likely the largest battle in a video game ever. That EVE is capaple of supporting such large engagements is an amazing ...read more
In mid-2004 I first started exploring Second Life. Version 1.4 had just been released and Philip Rosedale had said in the press release “My fantasy is to be Uma Thurman in Kill Bill, and now I can. I’d pay $10 for her yellow jumpsuit and sword moves and ...read more