Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Activity now sets _running flag to false when it finishes or throws. #4748

Merged
merged 1 commit into from
Oct 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Foundation/include/Poco/Activity.h
Original file line number Diff line number Diff line change
Expand Up @@ -180,9 +180,11 @@ class Activity: public Runnable
}
catch (...)
{
_running = false;
_done.set();
throw;
}
_running = false;
_done.set();
}

Expand Down
50 changes: 50 additions & 0 deletions Foundation/testsuite/src/ActivityTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,44 @@ namespace
Activity<ActiveObject> _activity;
Poco::UInt64 _count;
};

class BriefActiveObject
{
public:
BriefActiveObject():
_activity(this, &BriefActiveObject::run),
_count(0)
{
}

~BriefActiveObject()
{
}

Activity<BriefActiveObject>& activity()
{
return _activity;
}

Poco::UInt64 count() const
{
return _count;
}
protected:
void run()
{
while (!_activity.isStopped())
{
++_count;
if(_count > 2)
break;

}
}
private:
Activity<BriefActiveObject> _activity;
Poco::UInt64 _count;
};
}


Expand All @@ -81,6 +119,17 @@ void ActivityTest::testActivity()
assertTrue (activeObj.count() > 0);
}

void ActivityTest::testActivityFinishes()
{
BriefActiveObject briefActiveObj;
assertTrue (briefActiveObj.activity().isStopped());
briefActiveObj.activity().start();
assertTrue (!briefActiveObj.activity().isStopped());
Thread::sleep(100);
assertTrue (!briefActiveObj.activity().isRunning());
assertTrue (briefActiveObj.count() == 3);
}


void ActivityTest::setUp()
{
Expand All @@ -97,6 +146,7 @@ CppUnit::Test* ActivityTest::suite()
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("ActivityTest");

CppUnit_addTest(pSuite, ActivityTest, testActivity);
CppUnit_addTest(pSuite, ActivityTest, testActivityFinishes);

return pSuite;
}
1 change: 1 addition & 0 deletions Foundation/testsuite/src/ActivityTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class ActivityTest: public CppUnit::TestCase
~ActivityTest();

void testActivity();
void testActivityFinishes();

void setUp();
void tearDown();
Expand Down
Loading