Robust Software

21
Robust Software – Robust Software – Dotting the I’s Dotting the I’s and Crossing the and Crossing the T’s T’s Chris Oldwood Chris Oldwood ACCU Conference 2013 ACCU Conference 2013 @chrisoldwood / @chrisoldwood / [email protected] [email protected]

description

It’s been said that the first 90% of a project consumes 90% of the time, whereas the second 10 % accounts for the other 90% of the time. One reason might be because elevating software from “mostly works” to robust and supportable requires an attention to detail in the parts of a system that are usually mocked out during unit testing. It’s all too easy to focus on testing the happy paths and gloss over the more tricky design problems such as how to handle a full disk or Cheshire cat style network. This session delves into those less glamorous non-functional requirements that crop up the moment you start talking to hard disks, networks, databases, etc. Unsurprisingly it will have a fair bit to say about detecting and recovering from errors; starting with ensuring that you generate them correctly in the first place. This will undoubtedly lead on to the aforementioned subject of testing systemic effects. Finally there will also be diversions into the realms of monitoring and configuration as we look into the operational side of the code once it’s running. At the end you will hopefully have smiled at the misfortune of others (mostly me) and added a few more items to the ever growing list of “stuff I might have to think about when developing software”.

Transcript of Robust Software

Page 1: Robust Software

Robust Software – Robust Software – Dotting the I’s and Dotting the I’s and

Crossing the T’sCrossing the T’sChris OldwoodChris Oldwood

ACCU Conference 2013ACCU Conference 2013

@chrisoldwood / @chrisoldwood / [email protected]@cix.co.uk

Page 2: Robust Software

The I’s & T’sThe I’s & T’s

RobustnessRobustness Handling ErrorsHandling Errors Safely Ignoring ErrorsSafely Ignoring Errors TimeoutsTimeouts Unit Testing FailuresUnit Testing Failures Flexible ConfigurationFlexible Configuration Monitoring ClarityMonitoring Clarity

Page 3: Robust Software

RobustnessRobustness

Page 4: Robust Software

Stable in the face of Stable in the face of unexpected unexpected behaviourbehaviour

Page 5: Robust Software

Pop Quiz – Exit Code?Pop Quiz – Exit Code?

int main(int argc, char* argv[]){ throw UnhandledException();}

Page 6: Robust Software

Exit Code ConventionExit Code Convention

program.exe

if %errorlevel% neq 0 ( echo ERROR: Program failed exit /b 1)

Page 7: Robust Software

Big Outer Try BlockBig Outer Try Blockint main(int argc, char* argv[]){ try { return DoUsefulWork(argc, argv); } catch (const std::exception& e) { /* Report failure */ } catch (…) { /* Report failure */ }

return EXIT_FAILURE;}

Page 8: Robust Software

Module BoundariesModule BoundariesHRESULT DoSomething(...){ try { return Impl::DoSomething(...); } catch (const std::bad_alloc& e) { return E_OUTOFMEMORY; } catch (const std::exception& e) { return E_FAIL; } catch (...) { return E_UNEXPECTED; }}

Page 9: Robust Software

Exception Safety Exception Safety GuaranteesGuarantees

NoneNone BasicBasic StrongStrong No ThrowNo Throw

Page 10: Robust Software

Exception Unsafe CodeException Unsafe CodeIServicePtr AcquireService(){ if (!m_service) { m_service = new Service(); m_service.CreateInstance(); }

return m_service;}

IServicePtr m_service;

Page 11: Robust Software

Exception Safe CodeException Safe CodeIServicePtr AcquireService(){ if (!m_service) { ServicePtr service = new Service(); service.CreateInstance();

m_service.swap(service); }

return m_service;}

IServicePtr m_service;

Page 12: Robust Software

Forever is a Really Long Forever is a Really Long TimeTime

Handle completed = BeginAsyncOperation();. . .Wait(completed, INFINITE);

Page 13: Robust Software

Cancellable OperationsCancellable Operations

Handle completed = BeginAsyncOperation();Handle aborted = GetAbortHandle();Handle waitables[] = { aborted, completed };. . .Handle signalled = Wait(waitables, timeout);

if (signalled == aborted){

Page 14: Robust Software

Retries: immediate then Retries: immediate then queuedqueued

Page 15: Robust Software

Unit Testing FailuresUnit Testing Failures

Page 16: Robust Software

Testing Write+Rename Testing Write+Rename IdiomIdiom

[Test]public Void OriginalFilePreservedOnException(){ var fakeIo = new FakeIo();

fakeIo.Write = (file, buffer) => { throw new IoException(); }

var writer = new WriterService(fakeIo); var filename = “original.txt”;

Assert.Throws(() => writer.WriteFile(filename)); Assert.True(fakeIo.FileExists(filename)); Assert.That(. . .);}

Page 17: Robust Software

Flexible ConfigurationFlexible Configuration

Page 18: Robust Software

Monitoring ClarityMonitoring Clarity

Page 19: Robust Software

Release It!Release It!

Page 20: Robust Software

Questions?Questions?

Page 21: Robust Software

Blog:Blog:http://chrisoldwood.blogspot.comhttp://chrisoldwood.blogspot.com

@chrisoldwood / @chrisoldwood / [email protected]@cix.co.uk