Hi,
We are trying to integrate some Smartfox statistics into our website e.g. things like # of users online, busiest rooms, buddies online etc.
The webapp is running in a seperate Tomcat container (in production it will run on a different server, so dont want to use embedded server)
So my approach so far is to create a service class in my webapp, which wraps all of the Smartfox client communication and event handling. I am using the Java Client API, and have created a simple ConnectionManager class that connects to SFS and listens for events.
Thats all fine, but i'm wondering if anyone has some best practice ideas for unit testing it. At the moment, say I am testing connection, this is what I do.
- Register test case class as an event listener for onConnection
- Initiate connection
- Sleep for X millisecs
- Check that an onConnection event was received, and success = true
That also works, but I dont like the sleep. It needs to be somewhere around 300 millisecs to allow time for event to be received. As the number of tests grow and become more complex, this could be a serious hit on the unit test time.
I suppose one option would be to create a mock XML socket server - wondering what your thoughts are?
Regards,
Mo
Unit Testing
Hi,
you mentioned a 300ms delay... it's not clear... is that the amount of time necessary to connect? Is the Server running locally?
In a LAN a connection should take place in just a few milliseconds, and the same should go for all other calls which in turn would allow you to run your tests without much added time overhead.
you mentioned a 300ms delay... it's not clear... is that the amount of time necessary to connect? Is the Server running locally?
In a LAN a connection should take place in just a few milliseconds, and the same should go for all other calls which in turn would allow you to run your tests without much added time overhead.
Hi Lapo,
Thanks for your reply.
Yes, the 300 ms is a safe time taken to connect, login and get the room list. If i reduce it, the test intermittently fails.
However, I've been thinking about the best way of integrating an SFS client into a web application. Please correct me if I'm wrong, but I think the client needs to run in its own dedicated thread, initialised on application startup.
That should take care of the issues between synchronous HTTP requests and asynchronous SFS client?
Regards,
Mo
Thanks for your reply.
Yes, the 300 ms is a safe time taken to connect, login and get the room list. If i reduce it, the test intermittently fails.
However, I've been thinking about the best way of integrating an SFS client into a web application. Please correct me if I'm wrong, but I think the client needs to run in its own dedicated thread, initialised on application startup.
That should take care of the issues between synchronous HTTP requests and asynchronous SFS client?
Regards,
Mo