fix(test): fix flaky test

This commit is contained in:
Günter Obiltschnig
2025-02-08 15:20:14 +01:00
parent 24ff931071
commit db88e0ec00
2 changed files with 30 additions and 6 deletions

View File

@@ -86,7 +86,10 @@ namespace
void run()
{
_data.clear();
{
Poco::FastMutex::ScopedLock lock(_mutex);
_data.clear();
}
StreamSocket& ss = socket();
try
{
@@ -94,7 +97,10 @@ namespace
int n = ss.receiveBytes(buffer, sizeof(buffer));
while (n > 0)
{
_data.append(buffer, n);
{
Poco::FastMutex::ScopedLock lock(_mutex);
_data.append(buffer, n);
}
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;
}
private:
static Poco::FastMutex _mutex;
static std::string _data;
};
Poco::FastMutex CopyToStringConnection::_mutex;
std::string CopyToStringConnection::_data;
}
@@ -269,6 +278,7 @@ void SecureStreamSocketTest::testSendFile()
{
Poco::Thread::sleep(100);
}
srv.stop();
assertTrue (CopyToStringConnection::data() == sentData);
}
@@ -306,6 +316,7 @@ void SecureStreamSocketTest::testSendFileLarge()
{
Poco::Thread::sleep(100);
}
srv.stop();
assertTrue (CopyToStringConnection::data() == sentData);
}
@@ -346,6 +357,7 @@ void SecureStreamSocketTest::testSendFileRange()
{
Poco::Thread::sleep(100);
}
srv.stop();
assertTrue (CopyToStringConnection::data() == fileData.substr(offset, count));
}