mirror of
https://github.com/XRPLF/rippled.git
synced 2025-11-27 06:25:51 +00:00
Fixes for Service API hang on exit during unit tests
This commit is contained in:
@@ -122,6 +122,7 @@ public:
|
|||||||
|
|
||||||
~ApplicationImp ()
|
~ApplicationImp ()
|
||||||
{
|
{
|
||||||
|
serviceStop();
|
||||||
//stop ();
|
//stop ();
|
||||||
|
|
||||||
// Why is this needed here?
|
// Why is this needed here?
|
||||||
@@ -649,12 +650,6 @@ public:
|
|||||||
void run ()
|
void run ()
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
// VFALCO TODO The unit tests crash if we try to
|
|
||||||
// run these threads in the IoService constructor
|
|
||||||
// so this hack makes them start later.
|
|
||||||
//
|
|
||||||
m_mainIoPool.runAsync ();
|
|
||||||
|
|
||||||
if (!getConfig ().RUN_STANDALONE)
|
if (!getConfig ().RUN_STANDALONE)
|
||||||
{
|
{
|
||||||
// VFALCO NOTE This seems unnecessary. If we properly refactor the load
|
// VFALCO NOTE This seems unnecessary. If we properly refactor the load
|
||||||
|
|||||||
@@ -15,13 +15,11 @@ public:
|
|||||||
, m_owner (owner)
|
, m_owner (owner)
|
||||||
, m_service (service)
|
, m_service (service)
|
||||||
{
|
{
|
||||||
//startThread ();
|
startThread ();
|
||||||
}
|
}
|
||||||
|
|
||||||
~ServiceThread ()
|
~ServiceThread ()
|
||||||
{
|
{
|
||||||
m_service.stop ();
|
|
||||||
|
|
||||||
// block until thread exits
|
// block until thread exits
|
||||||
stopThread ();
|
stopThread ();
|
||||||
}
|
}
|
||||||
@@ -50,7 +48,6 @@ IoServicePool::IoServicePool (Service& parent, String const& name, int numberOfT
|
|||||||
, m_name (name)
|
, m_name (name)
|
||||||
, m_service (numberOfThreads)
|
, m_service (numberOfThreads)
|
||||||
, m_work (boost::ref (m_service))
|
, m_work (boost::ref (m_service))
|
||||||
, m_running (false)
|
|
||||||
{
|
{
|
||||||
bassert (numberOfThreads > 0);
|
bassert (numberOfThreads > 0);
|
||||||
|
|
||||||
@@ -60,27 +57,15 @@ IoServicePool::IoServicePool (Service& parent, String const& name, int numberOfT
|
|||||||
{
|
{
|
||||||
++m_threadsRunning;
|
++m_threadsRunning;
|
||||||
m_threads.add (new ServiceThread (m_name, *this, m_service));
|
m_threads.add (new ServiceThread (m_name, *this, m_service));
|
||||||
|
m_threads[i]->start ();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
IoServicePool::~IoServicePool ()
|
IoServicePool::~IoServicePool ()
|
||||||
{
|
{
|
||||||
// must have called runAsync()
|
|
||||||
bassert (m_running);
|
|
||||||
|
|
||||||
// the dtor of m_threads will block until each thread exits.
|
// the dtor of m_threads will block until each thread exits.
|
||||||
}
|
}
|
||||||
|
|
||||||
void IoServicePool::runAsync ()
|
|
||||||
{
|
|
||||||
// must not call twice
|
|
||||||
bassert (!m_running);
|
|
||||||
m_running = true;
|
|
||||||
|
|
||||||
for (int i = 0; i < m_threads.size (); ++i)
|
|
||||||
m_threads [i]->start ();
|
|
||||||
}
|
|
||||||
|
|
||||||
boost::asio::io_service& IoServicePool::getService ()
|
boost::asio::io_service& IoServicePool::getService ()
|
||||||
{
|
{
|
||||||
return m_service;
|
return m_service;
|
||||||
|
|||||||
@@ -14,8 +14,6 @@ public:
|
|||||||
IoServicePool (Service& parent, String const& name, int numberOfThreads);
|
IoServicePool (Service& parent, String const& name, int numberOfThreads);
|
||||||
~IoServicePool ();
|
~IoServicePool ();
|
||||||
|
|
||||||
void runAsync ();
|
|
||||||
|
|
||||||
boost::asio::io_service& getService ();
|
boost::asio::io_service& getService ();
|
||||||
operator boost::asio::io_service& ();
|
operator boost::asio::io_service& ();
|
||||||
|
|
||||||
@@ -32,7 +30,6 @@ private:
|
|||||||
boost::optional <boost::asio::io_service::work> m_work;
|
boost::optional <boost::asio::io_service::work> m_work;
|
||||||
OwnedArray <ServiceThread> m_threads;
|
OwnedArray <ServiceThread> m_threads;
|
||||||
Atomic <int> m_threadsRunning;
|
Atomic <int> m_threadsRunning;
|
||||||
bool m_running;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -1077,7 +1077,9 @@ public:
|
|||||||
testBackend ("sophia", seedValue);
|
testBackend ("sophia", seedValue);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/*
|
||||||
testBackend ("sqlite", seedValue);
|
testBackend ("sqlite", seedValue);
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -1114,8 +1116,8 @@ public:
|
|||||||
{
|
{
|
||||||
ScopedService service ("test");
|
ScopedService service ("test");
|
||||||
ScopedPointer <NodeStore> src (NodeStore::New ("test", service, srcParams));
|
ScopedPointer <NodeStore> src (NodeStore::New ("test", service, srcParams));
|
||||||
|
|
||||||
storeBatch (*src, batch);
|
storeBatch (*src, batch);
|
||||||
|
service.serviceStop();
|
||||||
}
|
}
|
||||||
|
|
||||||
NodeStore::Batch copy;
|
NodeStore::Batch copy;
|
||||||
@@ -1141,6 +1143,8 @@ public:
|
|||||||
|
|
||||||
// Get the results of the import
|
// Get the results of the import
|
||||||
fetchCopyOfBatch (*dest, ©, batch);
|
fetchCopyOfBatch (*dest, ©, batch);
|
||||||
|
|
||||||
|
service.serviceStop();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Canonicalize the source and destination batches
|
// Canonicalize the source and destination batches
|
||||||
@@ -1204,6 +1208,8 @@ public:
|
|||||||
fetchCopyOfBatch (*db, ©, batch);
|
fetchCopyOfBatch (*db, ©, batch);
|
||||||
expect (areBatchesEqual (batch, copy), "Should be equal");
|
expect (areBatchesEqual (batch, copy), "Should be equal");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
service.serviceStop();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (testPersistence)
|
if (testPersistence)
|
||||||
@@ -1222,6 +1228,8 @@ public:
|
|||||||
std::sort (batch.begin (), batch.end (), NodeObject::LessThan ());
|
std::sort (batch.begin (), batch.end (), NodeObject::LessThan ());
|
||||||
std::sort (copy.begin (), copy.end (), NodeObject::LessThan ());
|
std::sort (copy.begin (), copy.end (), NodeObject::LessThan ());
|
||||||
expect (areBatchesEqual (batch, copy), "Should be equal");
|
expect (areBatchesEqual (batch, copy), "Should be equal");
|
||||||
|
|
||||||
|
service.serviceStop();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (useEphemeralDatabase)
|
if (useEphemeralDatabase)
|
||||||
@@ -1240,6 +1248,8 @@ public:
|
|||||||
std::sort (batch.begin (), batch.end (), NodeObject::LessThan ());
|
std::sort (batch.begin (), batch.end (), NodeObject::LessThan ());
|
||||||
std::sort (copy.begin (), copy.end (), NodeObject::LessThan ());
|
std::sort (copy.begin (), copy.end (), NodeObject::LessThan ());
|
||||||
expect (areBatchesEqual (batch, copy), "Should be equal");
|
expect (areBatchesEqual (batch, copy), "Should be equal");
|
||||||
|
|
||||||
|
service.serviceStop();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user