I’ve got a library that interacts with external hardware over the ethernet port.
This presents a significant difficulty in testing it.
My library has the following sources of non-determinism / difficulty testing:
Uses of timers
Uses of sockets
I think I can create (elaborate) mocks for the sockets, but I don’t know what to do about the timers?
Are there existing resources / libraries I can leverage?
I have done something like this in the past, and it revolved around abstracting away the concept of clock (or “current time”). Once you control that (say, by having different policies, where one of them is “use the system clock”, another is “use a manual clock where I will tick whenever it is suitable”), you can make time stop, go fast, slow, even backwards.
On top of that, depending on your requirements, you could mock a timer. Maybe it is possible to abstract away the delivery mechanism, or maybe for your use case it is better to trigger a signal from your “policy-defined” clock. I would need more details to better understand.