Esempio n. 1
0
    def test_MPEngine_DatabaseLocked(self):
        try:
            logger.info("Starting test_MPEngine_end2end_BalanceSimulation")
            # Get temp db name for the test
            tempdb = tempfile.NamedTemporaryFile(suffix='.db',
                                                 prefix='testCase',
                                                 dir=tempfile.gettempdir())
            tempdb.close()
            dbfilenameFullPath = tempdb.name
            with appDB.DBClass(dbfilenameFullPath, settings.__version__) as DB:
                DB.appInitDB()

            num_tasks = 50
            mpe = MPEngineProdCons(4, WkrTestProdFast, WkrTestConsDB)
            # Add tasks
            task_list = [i for i in xrange(1, num_tasks + 1)]
            mpe.addTaskList(task_list)

            mpe.addConsumer([dbfilenameFullPath])
            mpe.addProducer()

            loop_test_num = num_tasks
            while mpe.working():
                (num_prod, num_cons, task1, task2, task3) = mpe.getProgress()
                print("Prod: %d / Cons: %d | %s -> %s -> %s" %
                      mpe.getProgress())
                time.sleep(1)
                if task3 >= 20 and task3 <= 30:
                    logger.info("Simulating rebalance (task3: %d task1/2: %d" %
                                (task3, task1 / 2))
                    mpe.restartConsumers()
                    mpe.restartProducers()
                loop_test_num -= 1

            results = mpe.grabResults()
            self.assertEquals(len(results), num_tasks, "test_MPEngine_end2end")
            self.assertEquals(results[-1], num_tasks, "test_MPEngine_end2end")

            del mpe
            print "Test ended"
        except Exception:
            traceback.print_exc(file=sys.stdout)
            self.fail("Exception triggered")

        # Pass
        self.assertEquals(1, 1, "test_MPEngine_end2end")
Esempio n. 2
0
    def test_MPEngine_regressionBug(self):
        try:
            print "Starting test"
            maxCores = 4

            mpe = MPEngineProdCons(maxCores, WkrTestProd, WkrTestCons)
            # Add tasks
            task_list = [i for i in xrange(1, 8)]
            mpe.addTaskList(task_list)

            mpe.startProducers(3)
            time.sleep(2)
            mpe.startConsumers(1)
            time.sleep(2)
            mpe.endProducers()
            mpe.endConsumers()
            time.sleep(2)
            mpe.addConsumer()
            mpe.addProducer()
            time.sleep(2)
            mpe.addProducer()
            time.sleep(2)
            logger.debug("restartConsumers")
            mpe.restartConsumers()
            logger.debug("restartProducers")
            mpe.restartProducers()
            time.sleep(2)

            while mpe.working():
                print("Prod: %d / Cons: %d | %s -> %s -> %s" %
                      mpe.getProgress())
                time.sleep(1)
                # mpe.rebalance()

            del mpe
            print "Test ended"
        except Exception:
            traceback.print_exc(file=sys.stdout)
            self.fail("Exception triggered")

        # Pass
        self.assertEquals(1, 1, "test_MPEngine")
Esempio n. 3
0
    def test_MPEngine_end2end_Restart_v2(self):
        try:
            print "Starting test"
            num_tasks = 10
            mpe = MPEngineProdCons(4, WkrTestProd, WkrTestCons)
            # Add tasks
            task_list = [i for i in xrange(1, num_tasks + 1)]
            mpe.addTaskList(task_list)

            mpe.addProducer()
            mpe.addConsumer()

            loop_test_num = 5
            while mpe.working():

                print("Prod: %d / Cons: %d | %s -> %s -> %s" %
                      mpe.getProgress())
                time.sleep(1)
                if loop_test_num == 0:
                    print "++++Test loop"
                    mpe.restartConsumers()
                    mpe.restartProducers()
                loop_test_num -= 1

            results = mpe.grabResults()
            self.assertEquals(len(results), num_tasks, "test_MPEngine_end2end")
            self.assertEquals(results[-1], num_tasks, "test_MPEngine_end2end")

            del mpe
            print "Test ended"
        except Exception:
            traceback.print_exc(file=sys.stdout)
            self.fail("Exception triggered")

        # Pass
        self.assertEquals(1, 1, "test_MPEngine_end2end")