mirror of
https://github.com/pocoproject/poco.git
synced 2025-10-21 15:51:43 +02:00
fix(test): fix flaky test
This commit is contained in:
@@ -63,7 +63,10 @@ namespace
|
|||||||
|
|
||||||
void run()
|
void run()
|
||||||
{
|
{
|
||||||
|
{
|
||||||
|
Poco::FastMutex::ScopedLock lock(_mutex);
|
||||||
_data.clear();
|
_data.clear();
|
||||||
|
}
|
||||||
StreamSocket& ss = socket();
|
StreamSocket& ss = socket();
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@@ -71,7 +74,10 @@ namespace
|
|||||||
int n = ss.receiveBytes(buffer, sizeof(buffer));
|
int n = ss.receiveBytes(buffer, sizeof(buffer));
|
||||||
while (n > 0)
|
while (n > 0)
|
||||||
{
|
{
|
||||||
|
{
|
||||||
|
Poco::FastMutex::ScopedLock lock(_mutex);
|
||||||
_data.append(buffer, n);
|
_data.append(buffer, n);
|
||||||
|
}
|
||||||
n = ss.receiveBytes(buffer, sizeof(buffer));
|
n = ss.receiveBytes(buffer, sizeof(buffer));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -81,15 +87,18 @@ namespace
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static const std::string& data()
|
static const std::string data()
|
||||||
{
|
{
|
||||||
|
Poco::FastMutex::ScopedLock lock(_mutex);
|
||||||
return _data;
|
return _data;
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
static Poco::FastMutex _mutex;
|
||||||
static std::string _data;
|
static std::string _data;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Poco::FastMutex CopyToStringConnection::_mutex;
|
||||||
std::string CopyToStringConnection::_data;
|
std::string CopyToStringConnection::_data;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -746,6 +755,7 @@ void SocketTest::testSendFile()
|
|||||||
{
|
{
|
||||||
Poco::Thread::sleep(100);
|
Poco::Thread::sleep(100);
|
||||||
}
|
}
|
||||||
|
srv.stop();
|
||||||
|
|
||||||
assertTrue (CopyToStringConnection::data() == sentData);
|
assertTrue (CopyToStringConnection::data() == sentData);
|
||||||
}
|
}
|
||||||
@@ -783,6 +793,7 @@ void SocketTest::testSendFileLarge()
|
|||||||
{
|
{
|
||||||
Poco::Thread::sleep(100);
|
Poco::Thread::sleep(100);
|
||||||
}
|
}
|
||||||
|
srv.stop();
|
||||||
|
|
||||||
assertTrue (CopyToStringConnection::data() == sentData);
|
assertTrue (CopyToStringConnection::data() == sentData);
|
||||||
}
|
}
|
||||||
@@ -823,6 +834,7 @@ void SocketTest::testSendFileRange()
|
|||||||
{
|
{
|
||||||
Poco::Thread::sleep(100);
|
Poco::Thread::sleep(100);
|
||||||
}
|
}
|
||||||
|
srv.stop();
|
||||||
|
|
||||||
assertTrue (CopyToStringConnection::data() == sentData.substr(offset, count));
|
assertTrue (CopyToStringConnection::data() == sentData.substr(offset, count));
|
||||||
}
|
}
|
||||||
|
@@ -86,7 +86,10 @@ namespace
|
|||||||
|
|
||||||
void run()
|
void run()
|
||||||
{
|
{
|
||||||
|
{
|
||||||
|
Poco::FastMutex::ScopedLock lock(_mutex);
|
||||||
_data.clear();
|
_data.clear();
|
||||||
|
}
|
||||||
StreamSocket& ss = socket();
|
StreamSocket& ss = socket();
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@@ -94,7 +97,10 @@ namespace
|
|||||||
int n = ss.receiveBytes(buffer, sizeof(buffer));
|
int n = ss.receiveBytes(buffer, sizeof(buffer));
|
||||||
while (n > 0)
|
while (n > 0)
|
||||||
{
|
{
|
||||||
|
{
|
||||||
|
Poco::FastMutex::ScopedLock lock(_mutex);
|
||||||
_data.append(buffer, n);
|
_data.append(buffer, n);
|
||||||
|
}
|
||||||
n = ss.receiveBytes(buffer, sizeof(buffer));
|
n = ss.receiveBytes(buffer, sizeof(buffer));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -104,15 +110,18 @@ namespace
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static const std::string& data()
|
static const std::string data()
|
||||||
{
|
{
|
||||||
|
Poco::FastMutex::ScopedLock lock(_mutex);
|
||||||
return _data;
|
return _data;
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
static Poco::FastMutex _mutex;
|
||||||
static std::string _data;
|
static std::string _data;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Poco::FastMutex CopyToStringConnection::_mutex;
|
||||||
std::string CopyToStringConnection::_data;
|
std::string CopyToStringConnection::_data;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -269,6 +278,7 @@ void SecureStreamSocketTest::testSendFile()
|
|||||||
{
|
{
|
||||||
Poco::Thread::sleep(100);
|
Poco::Thread::sleep(100);
|
||||||
}
|
}
|
||||||
|
srv.stop();
|
||||||
|
|
||||||
assertTrue (CopyToStringConnection::data() == sentData);
|
assertTrue (CopyToStringConnection::data() == sentData);
|
||||||
}
|
}
|
||||||
@@ -306,6 +316,7 @@ void SecureStreamSocketTest::testSendFileLarge()
|
|||||||
{
|
{
|
||||||
Poco::Thread::sleep(100);
|
Poco::Thread::sleep(100);
|
||||||
}
|
}
|
||||||
|
srv.stop();
|
||||||
|
|
||||||
assertTrue (CopyToStringConnection::data() == sentData);
|
assertTrue (CopyToStringConnection::data() == sentData);
|
||||||
}
|
}
|
||||||
@@ -346,6 +357,7 @@ void SecureStreamSocketTest::testSendFileRange()
|
|||||||
{
|
{
|
||||||
Poco::Thread::sleep(100);
|
Poco::Thread::sleep(100);
|
||||||
}
|
}
|
||||||
|
srv.stop();
|
||||||
|
|
||||||
assertTrue (CopyToStringConnection::data() == fileData.substr(offset, count));
|
assertTrue (CopyToStringConnection::data() == fileData.substr(offset, count));
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user