3 Replies Latest reply on Jun 27, 2012 10:36 PM by Yong Hao Gao

    The start() /stop() issue

    Yong Hao Gao Master

      In our code the start() and stop() are seen in many places, like HornetQServerImpl. There is a potential issue that may cause test failures.


      For example, in HornetQServerImpl.start(), if the server is a backup, it will launch a new Thread to run the activation with it (for what ever reason). And the activation may also spawn other threads to do some work.


      If in a test we call start() and then immediately stop(), some components may be closed before it even gets started. In my investigation, for example,


      If a backup is started, the storageManager will be started by a thread. But if the stop() is called to closely, the storageManager.close() will be called before the thread call storageManager.start().

      The result, as shown in tests, is that the storageManager is started even after its stop() has been called. Therefore in test tearDown() stage, it will found some threads still running and never stop.

      So the test result in "Thread leak".


      Simply put some sleep between start and stop in the test may help but this is not a good way. I have tried to add some flags to prevent this. It seems to work but it will add some synchronization blocks to the class. Is there a better and simpler way to prevent it?


      In my env, I always get this issue with FailoverTest.testWithoutUsingTheBackup(). If you see the code the problem is that the backup server is started and stopped to quickly:


        backupServer.stop(); // Backup stops!