robust software
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
![Page 1: Robust Software](https://reader033.vdocuments.us/reader033/viewer/2022061103/540b1e808d7f72dc6a8b4641/html5/thumbnails/1.jpg)
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](https://reader033.vdocuments.us/reader033/viewer/2022061103/540b1e808d7f72dc6a8b4641/html5/thumbnails/2.jpg)
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](https://reader033.vdocuments.us/reader033/viewer/2022061103/540b1e808d7f72dc6a8b4641/html5/thumbnails/3.jpg)
RobustnessRobustness
![Page 4: Robust Software](https://reader033.vdocuments.us/reader033/viewer/2022061103/540b1e808d7f72dc6a8b4641/html5/thumbnails/4.jpg)
Stable in the face of Stable in the face of unexpected unexpected behaviourbehaviour
![Page 5: Robust Software](https://reader033.vdocuments.us/reader033/viewer/2022061103/540b1e808d7f72dc6a8b4641/html5/thumbnails/5.jpg)
Pop Quiz – Exit Code?Pop Quiz – Exit Code?
int main(int argc, char* argv[]){ throw UnhandledException();}
![Page 6: Robust Software](https://reader033.vdocuments.us/reader033/viewer/2022061103/540b1e808d7f72dc6a8b4641/html5/thumbnails/6.jpg)
Exit Code ConventionExit Code Convention
program.exe
if %errorlevel% neq 0 ( echo ERROR: Program failed exit /b 1)
![Page 7: Robust Software](https://reader033.vdocuments.us/reader033/viewer/2022061103/540b1e808d7f72dc6a8b4641/html5/thumbnails/7.jpg)
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](https://reader033.vdocuments.us/reader033/viewer/2022061103/540b1e808d7f72dc6a8b4641/html5/thumbnails/8.jpg)
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](https://reader033.vdocuments.us/reader033/viewer/2022061103/540b1e808d7f72dc6a8b4641/html5/thumbnails/9.jpg)
Exception Safety Exception Safety GuaranteesGuarantees
NoneNone BasicBasic StrongStrong No ThrowNo Throw
![Page 10: Robust Software](https://reader033.vdocuments.us/reader033/viewer/2022061103/540b1e808d7f72dc6a8b4641/html5/thumbnails/10.jpg)
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](https://reader033.vdocuments.us/reader033/viewer/2022061103/540b1e808d7f72dc6a8b4641/html5/thumbnails/11.jpg)
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](https://reader033.vdocuments.us/reader033/viewer/2022061103/540b1e808d7f72dc6a8b4641/html5/thumbnails/12.jpg)
Forever is a Really Long Forever is a Really Long TimeTime
Handle completed = BeginAsyncOperation();. . .Wait(completed, INFINITE);
![Page 13: Robust Software](https://reader033.vdocuments.us/reader033/viewer/2022061103/540b1e808d7f72dc6a8b4641/html5/thumbnails/13.jpg)
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](https://reader033.vdocuments.us/reader033/viewer/2022061103/540b1e808d7f72dc6a8b4641/html5/thumbnails/14.jpg)
Retries: immediate then Retries: immediate then queuedqueued
![Page 15: Robust Software](https://reader033.vdocuments.us/reader033/viewer/2022061103/540b1e808d7f72dc6a8b4641/html5/thumbnails/15.jpg)
Unit Testing FailuresUnit Testing Failures
![Page 16: Robust Software](https://reader033.vdocuments.us/reader033/viewer/2022061103/540b1e808d7f72dc6a8b4641/html5/thumbnails/16.jpg)
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](https://reader033.vdocuments.us/reader033/viewer/2022061103/540b1e808d7f72dc6a8b4641/html5/thumbnails/17.jpg)
Flexible ConfigurationFlexible Configuration
![Page 18: Robust Software](https://reader033.vdocuments.us/reader033/viewer/2022061103/540b1e808d7f72dc6a8b4641/html5/thumbnails/18.jpg)
Monitoring ClarityMonitoring Clarity
![Page 19: Robust Software](https://reader033.vdocuments.us/reader033/viewer/2022061103/540b1e808d7f72dc6a8b4641/html5/thumbnails/19.jpg)
Release It!Release It!
![Page 20: Robust Software](https://reader033.vdocuments.us/reader033/viewer/2022061103/540b1e808d7f72dc6a8b4641/html5/thumbnails/20.jpg)
Questions?Questions?
![Page 21: Robust Software](https://reader033.vdocuments.us/reader033/viewer/2022061103/540b1e808d7f72dc6a8b4641/html5/thumbnails/21.jpg)
Blog:Blog:http://chrisoldwood.blogspot.comhttp://chrisoldwood.blogspot.com
@chrisoldwood / @chrisoldwood / [email protected]@cix.co.uk