[asterisk-scf-commits] asterisk-scf/integration/ice-util-cpp.git branch "workqueue" updated.
Commits to the Asterisk SCF project code repositories
asterisk-scf-commits at lists.digium.com
Sat Mar 19 12:58:13 CDT 2011
branch "workqueue" has been updated
via 0b63a5b84f4fe69291c94f9bcaed9561059a467e (commit)
via 600cbad560964dfcfa9bf57e34a470df605c79bd (commit)
from 19715894a0c1a53b16213155dddb5ef397288b80 (commit)
Summary of changes:
WorkQueue/src/SuspendableWorkQueue.cpp | 7 ++-
WorkQueue/test/TestSuspendableWorkQueue.cpp | 72 +++++++++++++++++++++++++++
2 files changed, 78 insertions(+), 1 deletions(-)
- Log -----------------------------------------------------------------
commit 0b63a5b84f4fe69291c94f9bcaed9561059a467e
Author: Mark Michelson <mmichelson at digium.com>
Date: Sat Mar 19 12:56:41 2011 -0500
Add a test to see how the queue handles a potential race condition.
diff --git a/WorkQueue/src/SuspendableWorkQueue.cpp b/WorkQueue/src/SuspendableWorkQueue.cpp
index a319bfe..bbf3e1a 100644
--- a/WorkQueue/src/SuspendableWorkQueue.cpp
+++ b/WorkQueue/src/SuspendableWorkQueue.cpp
@@ -290,6 +290,8 @@ bool SuspendableWorkQueue::executeWork()
if (result == AsteriskSCF::System::WorkQueue::V1::Suspended)
{
+ mImpl->currentWork = work;
+
// It's possible that a piece of work called out to an
// asynchronous method and needed to be suspended. Before
// the work's execute() method could return a "Suspended"
@@ -303,9 +305,12 @@ bool SuspendableWorkQueue::executeWork()
if (mImpl->state != SuspendableWorkQueueImpl::Resumable)
{
mImpl->state = SuspendableWorkQueueImpl::Suspended;
- mImpl->currentWork = work;
return false;
}
+ else
+ {
+ return true;
+ }
}
mImpl->state = SuspendableWorkQueueImpl::Ready;
diff --git a/WorkQueue/test/TestSuspendableWorkQueue.cpp b/WorkQueue/test/TestSuspendableWorkQueue.cpp
index ebcc978..8b8c578 100644
--- a/WorkQueue/test/TestSuspendableWorkQueue.cpp
+++ b/WorkQueue/test/TestSuspendableWorkQueue.cpp
@@ -149,6 +149,7 @@ public:
case Task2Complete:
default:
BOOST_FAIL("RacyTask executed in bad state");
+ return Complete;
}
}
enum State
@@ -159,6 +160,8 @@ public:
} currentState;
};
+typedef IceUtil::Handle<RacyTask> RacyTaskPtr;
+
BOOST_AUTO_TEST_SUITE(SuspendableWorkQueueTest)
BOOST_AUTO_TEST_CASE(addWork)
@@ -500,4 +503,30 @@ BOOST_AUTO_TEST_CASE(complexWork)
BOOST_CHECK(listener->emptyNotice == true);
}
+BOOST_AUTO_TEST_CASE(racyWork)
+{
+ TestListenerPtr listener(new TestListener);
+ SuspendableQueuePtr queue(new SuspendableWorkQueue(listener));
+ RacyTaskPtr work(new RacyTask);
+
+ queue->enqueueWork(work);
+
+ bool moreWork = queue->executeWork();
+
+ BOOST_CHECK(moreWork == true);
+ BOOST_CHECK(work->currentState == RacyTask::Task1Complete);
+ BOOST_CHECK(queue->workCount() == 1);
+ BOOST_CHECK(listener->emptyNotice == false);
+
+ //Because the queue was already told work was resumable,
+ //we should be able to tell it to execute work.
+
+ moreWork = queue->executeWork();
+
+ BOOST_CHECK(moreWork == false);
+ BOOST_CHECK(work->currentState == RacyTask::Task2Complete);
+ BOOST_CHECK(queue->workCount() == 0);
+ BOOST_CHECK(listener->emptyNotice == true);
+}
+
BOOST_AUTO_TEST_SUITE_END()
commit 600cbad560964dfcfa9bf57e34a470df605c79bd
Author: Mark Michelson <mmichelson at digium.com>
Date: Sat Mar 19 12:09:21 2011 -0500
Add a test that tries a multi-step work item.
diff --git a/WorkQueue/test/TestSuspendableWorkQueue.cpp b/WorkQueue/test/TestSuspendableWorkQueue.cpp
index 4afe13f..ebcc978 100644
--- a/WorkQueue/test/TestSuspendableWorkQueue.cpp
+++ b/WorkQueue/test/TestSuspendableWorkQueue.cpp
@@ -101,6 +101,7 @@ public:
case Task2Complete:
default:
BOOST_FAIL("ComplexTask executed in bad state");
+ return Complete;
}
}
@@ -125,6 +126,8 @@ public:
SuspendableWorkListenerPtr mListener;
};
+typedef IceUtil::Handle<ComplexTask> ComplexTaskPtr;
+
class RacyTask : public SuspendableWork
{
public:
@@ -457,4 +460,44 @@ BOOST_AUTO_TEST_CASE(executionOrder2)
BOOST_CHECK(queue->workCount() == 0);
}
+BOOST_AUTO_TEST_CASE(complexWork)
+{
+ TestListenerPtr listener(new TestListener);
+ SuspendableQueuePtr queue(new SuspendableWorkQueue(listener));
+ ComplexTaskPtr work(new ComplexTask);
+
+ queue->enqueueWork(work);
+
+ bool moreWork = queue->executeWork();
+
+ BOOST_CHECK(moreWork == false);
+ BOOST_CHECK(queue->workCount() == 1);
+ BOOST_CHECK(work->currentState == ComplexTask::Task1Complete);
+
+ //Until we poke the ComplexWork's thread, the queue
+ //should be in a suspended state, thereby not actually
+ //attempting to execute anything.
+
+ moreWork = queue->executeWork();
+
+ BOOST_CHECK(moreWork == false);
+ BOOST_CHECK(queue->workCount() == 1);
+ BOOST_CHECK(work->currentState == ComplexTask::Task1Complete);
+
+ boost::unique_lock<boost::mutex> lock(globalLock);
+ globalGoOn = true;
+ globalCond.notify_one();
+ lock.unlock();
+
+ //Now attempting to execute work should result in
+ //something actually happening.
+
+ moreWork = queue->executeWork();
+
+ BOOST_CHECK(moreWork == false);
+ BOOST_CHECK(queue->workCount() == 0);
+ BOOST_CHECK(work->currentState == ComplexTask::Task2Complete);
+ BOOST_CHECK(listener->emptyNotice == true);
+}
+
BOOST_AUTO_TEST_SUITE_END()
-----------------------------------------------------------------------
--
asterisk-scf/integration/ice-util-cpp.git
More information about the asterisk-scf-commits
mailing list