Skip to content

Commit

Permalink
Re #6811. Refactor test to avoid asynchronous algorithm execution.
Browse files Browse the repository at this point in the history
I found a better way to mimic a long running algorithm rather than
actually having one - just have it always say it's still running
if asked. This is just as good for testing this class as the old way.
  • Loading branch information
RussellTaylor committed Apr 1, 2013
1 parent 71cfd3a commit bdcc4a1
Showing 1 changed file with 3 additions and 18 deletions.
21 changes: 3 additions & 18 deletions Code/Mantid/Framework/API/test/AlgorithmManagerTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,18 +68,14 @@ class AlgTestSecond : public Algorithm
};


/** Algorithm that runs until cancelled */
/** Algorithm that always says it's running if asked */
class AlgRunsForever : public Algorithm
{
public:
AlgRunsForever() : Algorithm() {}
virtual ~AlgRunsForever() {}
void init() { }
void exec()
{
while (!this->m_cancel)
Poco::Thread::sleep(10);
}
void exec() { }
virtual const std::string name() const {return "AlgRunsForever";}
virtual int version() const {return(1);}
virtual const std::string category() const {return("Cat1");}
Expand Down Expand Up @@ -112,7 +108,6 @@ class AlgorithmManagerTest : public CxxTest::TestSuite
TS_ASSERT_THROWS_NOTHING(AlgorithmFactory::Instance().subscribe<AlgTestFail>());
// Size should be the same
TS_ASSERT_EQUALS(AlgorithmFactory::Instance().getKeys().size(), nalgs);

}

void testVersionPass()
Expand Down Expand Up @@ -252,18 +247,13 @@ class AlgorithmManagerTest : public CxxTest::TestSuite
AlgorithmManager::Instance().clear();
TS_ASSERT_EQUALS(AlgorithmManager::Instance().size(),0);

// Start one algorithm that never stops
// Create one algorithm that appears never to stop
IAlgorithm_sptr first = AlgorithmManager::Instance().create("AlgRunsForever");
Poco::ActiveResult<bool> res1 = first->executeAsync();

IAlgorithm_sptr second = AlgorithmManager::Instance().create("AlgTest");

// Another long-running algo
IAlgorithm_sptr third = AlgorithmManager::Instance().create("AlgRunsForever");
Poco::ActiveResult<bool> res3 = third->executeAsync();

// give it some time to start
Poco::Thread::sleep(100);

for (size_t i=3; i<5; i++)
AlgorithmManager::Instance().create("AlgTest");
Expand Down Expand Up @@ -293,11 +283,6 @@ class AlgorithmManagerTest : public CxxTest::TestSuite
TSM_ASSERT("The third algorithm (is still running) so it is still there",
AlgorithmManager::Instance().getAlgorithm(third->getAlgorithmID()) == third);

// Cancel the long-running ones
first->cancel();
third->cancel();
res1.wait();
res3.wait();
}

/**
Expand Down

0 comments on commit bdcc4a1

Please sign in to comment.