Re: The new Connection class in the TDD way

Hello everyone,

I’m glad to present you a quite interesting patch available in the latest revision (82) of my BitTorrent branch! I did some work on the Connection class, its documentation and unit tests.

First of all I revised the documentation in the header of class Connection. I’ll be grateful if someone of you peeks a look there. I kind of merged the rationales with the use cases because I figured out that it is much more logical and readable this way. I’d be interested to know whether I have succeeded to communicate the problems, which the class is trying to solve. My expectation is that if one is able to easily understand the problem, then understanding the solution would also be easier. Actually, understanding the solution is not at all important if you plan to only use the class anyway and not extend or refactor it yourself.

Last time I reached the point where I wanted to fully test the connect and disconnect functionality. My major problem was to test scenarios where timeouts should expire. The simplest solution would have been to actually wait 10 sec before the connection attempt times out. I quickly eliminated this as a feasible solution because as the number of similar tests increases the time we’ll need to wait will easily exceed reasonable limits. I wanted to do a time simulation instead. Only if I were allowed to tell the unit tests that 30 seconds have elapsed… What I actually needed was a way to substitute the default timer implementation with a special one. That’s what I did! I added a new class Utils::Timer which is a thin wrapper around QTimer. The unit test app links TimerSimulated.cpp and Calitko app links the normal Timer.cpp. The functions in TimerSimulated.cpp implement a custom (rather simple) timer management system instead of delegating to the default QTimer implementation. The function Timer::advanceTime() advances the current time and triggers all expired timers. I’d like to do some improvements, but the current implementation is enough to show the idea in a simple example. I’m open to any ideas or suggestions!

Regards,

Peter

Would you like to post a relpy?


This post is a reply to:
The new Connection class in the TDD way
Dear all, Herewith I’d like to shortly present some of my recent work in the field of unit testing and TDD. The attached patch and latest revision of my BitTorrent patch (more...)

No follow-ups yet.