Testing clj-browserchannel
10 Jul 2012The clj-browserchannel project now also contains a test project. The test project contains a small executable test that tests the whole browserchannel stack, by using the chat-demo application. The test project is meant to test the server-side component of the BrowserChannel protocol in clj-browserchannel. Together with the client-side implementation as part of the Google Closure library this provides real-time bi-directional communication for web apps.
The test is done by mimicking people chatting in the chat-demo application. Testing the server component in clj-browserchannel by itself is nearly impossible. This is because the server-side is fully dependent on cooperation with the client-side to comply to the BrowserChannel protocol. However both the protocol and the client-side implementation are very sparsely documented. The client-side implementation is a black box that can not easily be mocked or stubbed. Therefore the approach is to do simulation testing.
The people chatting in the chat-demo are programmed through the clj-webdriver wrapper for Selenium. A chatter can send and receive messages. Chatters can also cancel connections to create connection failures. This tests the basic promise of the BrowserChannel protocol to be resilient to connection failures. At the end of a test there is a check to see if all the messages that have been sent have been received and have been received in the proper order.
The test project currently contains one scenario, but different scenarios can be generated and tested. These scenarios could check different write/read ratios, chatter counts, failure rates and different browsers. The knobs to tune these parameters are in place.