robust software

Post on 06-Sep-2014

85 Views

Category:

Software

3 Downloads

Preview:

Click to see full reader

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

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 / gort@cix.co.ukgort@cix.co.uk

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

RobustnessRobustness

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

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

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

Exit Code ConventionExit Code Convention

program.exe

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

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;}

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; }}

Exception Safety Exception Safety GuaranteesGuarantees

NoneNone BasicBasic StrongStrong No ThrowNo Throw

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

return m_service;}

IServicePtr m_service;

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;

Forever is a Really Long Forever is a Really Long TimeTime

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

Cancellable OperationsCancellable Operations

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

if (signalled == aborted){

Retries: immediate then Retries: immediate then queuedqueued

Unit Testing FailuresUnit Testing Failures

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(. . .);}

Flexible ConfigurationFlexible Configuration

Monitoring ClarityMonitoring Clarity

Release It!Release It!

Questions?Questions?

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

@chrisoldwood / @chrisoldwood / gort@cix.co.ukgort@cix.co.uk

top related