Most of us are familiar with unit testing code with more traditional concurrency models. In this case of threaded code, for many, this means throwing up your hands in disgust and walking away. Testing concurrency with threads is hard. Testing concurrency in Pony is much easier but if you haven’t encountered anything like it before it can be hard to know where to start.
The patterns in this chapter will cover various ways of testing your Pony code. We will pay particular attention to how to test actors. Please note that this chapter assumes that you are familiar with the basics of using PonyTest, the Pony unit testing framework. If you aren’t, please review the PonyTest documentation.
Problem Event driven code is very common in Pony. Many classes take a “notifier” class that has callbacks that get triggered when certain events happen. The network code such as UDPNotify and TCPNotify are examples of this. As you write your own Pony code, the notifier pattern is one you’ll end up using quite a bit. Testing that your code is correctly interacting with notifiers is straightforward; however, how you go about doing that isn’t immediately obvious.
Problem A lot of the Pony code you will need to test involves actors that take input and create output that leaves your system. A good example of this is testing writing to a file. How can you verify that the contents of the file are what you expect? You could write the file as normal and then compare its contents to what you were expecting. In the end, though, that doesn’t work for everything.