News for hackers. Stuff that matters.
Re:Is TDD Dead? (2014) by snewman on Wednesday August 26, 2020 @09:57AM (#24282500)
I think GP is referring to nondeterministic exceptions. For instance, if the service under test depends on some other service, then you may need to test the scenario where the other service is unavailable. The exception is not triggered by a bug, it is triggered by an operational externality.
Re:Is TDD Dead? (2014) by dropofwill on Wednesday August 26, 2020 @07:08PM (#24288321)
For networking related problems you can deterministically control failures from the test using something like Toxiproxy. This can be especially useful if you’re working out a particular bug (e.g. gracefully handling a split brain situation or something).

A more general approach would be to just run your happy path tests while wrecking the environment (e.g. randomly killing instances, adding latency, dropping packets, whatever).

I’ve found that the latter often uncovers problems that you can use the former to solve.

Testing these sort of things with unit tests can work, but I’m more confident in tests that run on a ‘real’ networking stack, instead of e.g. mocking a socket timeout exception.

Re:Is TDD Dead? (2014) by gvjddbnvdrbv on Thursday August 27, 2020 @03:24AM (#24290951)
This is more integration testing than unit testing. Certainly valuable but it shouldn't replace your unit tests.
Re:Is TDD Dead? (2014) by dropofwill on Thursday August 27, 2020 @01:41PM (#24296283)
Yeah, reading it again I mixed up what you wrote with someone else.
Re:Is TDD Dead? (2014) by gvjddbnvdrbv on Wednesday August 26, 2020 @01:03PM (#24284458)
Then test the externalities. They probably have healthcheck endpoints....

Don't overthink everything. KISS

Re:Is TDD Dead? (2014) by snewman on Wednesday August 26, 2020 @01:12PM (#24284574)
Imagine I am implementing a service that queries 20 separate MySQL database servers to generate a report. (I'm not saying this is a good architecture, it's merely to illustrate the point.) I know that sometimes one of the MySQL instances might be down, e.g. due to a hardware failure. When this happens, my service is supposed to return data from the other 19 databases, along with a warning message indicating that the data is incomplete.

I would like to write a test to verify that my code properly handles the case where one of the MySQL instances has experienced a hardware failure. The point is that I can't do this as a strict black-box test where I merely issue calls to my service's public API.

[edit] And of course "testing the externalities" doesn't help here. I can test the MySQL instances and verify that they are all running, but that doesn't remove the need for my code to handle the possibility that at some point one of them goes down.

Re:Is TDD Dead? (2014) by gvjddbnvdrbv on Wednesday August 26, 2020 @01:38PM (#24284948)
First. Don't do this!

Second. You've done this/someone else has done this and now you need to maintain it (we've all been there!). In this case my original post holds. Your test suite mocks the databases for unit tests anyway right? So write some test(s) checking that when the various databases are down appropriate responses are given by your service.