addressalign-toparrow-leftarrow-leftarrow-right-10x10arrow-rightbackbellblockcalendarcameraccwcheckchevron-downchevron-leftchevron-rightchevron-small-downchevron-small-leftchevron-small-rightchevron-small-upchevron-upcircle-with-checkcircle-with-crosscircle-with-pluscontroller-playcredit-cardcrossdots-three-verticaleditemptyheartexporteye-with-lineeyefacebookfolderfullheartglobe--smallglobegmailgooglegroupshelp-with-circleimageimagesinstagramFill 1languagelaunch-new-window--smalllight-bulblightning-boltlinklocation-pinlockm-swarmSearchmailmediummessagesminusmobilemoremuplabelShape 3 + Rectangle 1ShapeoutlookpersonJoin Group on CardStartprice-ribbonprintShapeShapeShapeShapeImported LayersImported LayersImported Layersshieldstar-shapestartickettrashtriangle-downtriangle-uptwitteruserwarningyahooyoutube

Good practices for unit testing timeout logic and avoiding "sleeping snail" test cases?

From: Stephen H.
Sent on: Monday, July 16, 2012, 10:35 AM
Hi,

Does anyone know any good resources or tips for unit testing code involving timeout logic?

In our case we're implementing a web-service with a "graceful degredation" approach for serving personalised content within a strict time limit. If we can't serve optimal "recommended for you" content for a user within Xms then we just return a cached default, e.g. because of heavy load on the recommendation engine.

The code for this involves fairly complex multi-threading (one request initiates multiple threads to pull different bits of data together) and uses a mix of CountdownLatchs and Futures to handle the timeout logic at various points.

Our initial approach for unit testing it all was to shove in lots of Thread.sleep() calls but that's a pretty bad anti-pattern, "The Sleeping Snail", and we've hit nearly all the problems associated with it (tests taking too long, tests failing on one pc but not another, etc.). Unfortunately the examples I've found for how to tackle it seem pretty contrived and I'm just wondering if anyone's come across a more in-depth guide for this sort of thing?


Thanks,
Stephen

People in this
group are also in: