Example #1
0
    def testA(self):
        """
        Check worker methods get called. We sleep occasionally to ensure these
        asynchronous calls have enough time to be called
        """
        # Create a worker manager
        compDummy = Dummy()
        print('create manager')
        manager = WorkerThreadManager(compDummy)

        # Pause it
        print('pause workers')
        manager.pauseWorkers()

        # Add a worker, and check init method gets called
        print('add worker')
        manager.addWorker(DummyWorker1(), 1)
        time.sleep(3)
        self.assertEqual(WorkerThreadsTest._setupCalled, True)
        # Ensure the algo wasn't called whilst paused
        self.assertEqual(WorkerThreadsTest._algoCalled, False)

        print('resume workers')
        # Run the workers, pause, and check algo method gets called
        manager.resumeWorkers()
        time.sleep(3)
        manager.pauseWorkers()
        self.assertEqual(WorkerThreadsTest._algoCalled, True)

        print('terminate workers')
        # Terminate the workers, and check terminate method gets called
        manager.terminateWorkers()
        time.sleep(3)
        self.assertEqual(WorkerThreadsTest._terminateCalled, True)
Example #2
0
    def testA(self):
        """
        Check worker methods get called. We sleep occasionally to ensure these
        asynchronous calls have enough time to be called
        """
        # Create a worker manager
        compDummy = Dummy()
        print('create manager')
        manager = WorkerThreadManager(compDummy)

        # Pause it
        print('pause workers')
        manager.pauseWorkers()

        # Add a worker, and check init method gets called
        print('add worker')
        manager.addWorker(DummyWorker1(), 1)
        time.sleep(3)
        self.assertEqual( WorkerThreadsTest._setupCalled ,  True )
        # Ensure the algo wasn't called whilst paused
        self.assertEqual( WorkerThreadsTest._algoCalled ,  False )

        print('resume workers')
        # Run the workers, pause, and check algo method gets called
        manager.resumeWorkers()
        time.sleep(3)
        manager.pauseWorkers()
        self.assertEqual( WorkerThreadsTest._algoCalled ,  True )

        print('terminate workers')
        # Terminate the workers, and check terminate method gets called
        manager.terminateWorkers()
        time.sleep(3)
        self.assertEqual( WorkerThreadsTest._terminateCalled ,  True )
Example #3
0
    def testWorkerError(self):
        """If a worker raises an exception terminate the entire component"""
        compDummy = Dummy()

        print('create manager')
        manager = WorkerThreadManager(compDummy)
        # needed for handling errors - harness would generally set this
        myThread = threading.currentThread()
        myThread.workerThreadManager = manager

        print('add workers')
        manager.addWorker(DummyWorker1(), 0.1)
        manager.addWorker(ErrorWorker(), 0.1)

        print('run workers, one will throw an error')
        manager.resumeWorkers()

        # should do something smarter here
        # too short a time and threads havent exited yet
        time.sleep(6)

        # all threads should have ended after worker raised exception
        self.assertEqual(manager.activeThreadCount, 0)
Example #4
0
    def testWorkerError(self):
        """If a worker raises an exception terminate the entire component"""
        compDummy = Dummy()

        print('create manager')
        manager = WorkerThreadManager(compDummy)
        # needed for handling errors - harness would generally set this
        myThread = threading.currentThread()
        myThread.workerThreadManager = manager

        print('add workers')
        manager.addWorker(DummyWorker1(), 0.1)
        manager.addWorker(ErrorWorker(), 0.1)

        print('run workers, one will throw an error')
        manager.resumeWorkers()

        # should do something smarter here
        # too short a time and threads havent exited yet
        time.sleep(6)

        # all threads should have ended after worker raised exception
        self.assertEqual(manager.activeThreadCount, 0)