Updated to version 0.5.1.

epel9
Vitaly Zaitsev 3 years ago
parent 93a3cbfda9
commit efed11c0d7
No known key found for this signature in database
GPG Key ID: BF99FC6DD45AB90A

1
.gitignore vendored

@ -1,3 +1,4 @@
/qcoro-0.2.0.tar.gz
/qcoro-0.3.0.tar.gz
/qcoro-0.4.0.tar.gz
/qcoro-0.5.1.tar.gz

@ -0,0 +1,358 @@
From afa8824d941731d85116e0d08d619581939af734 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Daniel=20Vr=C3=A1til?= <dvratil@kde.org>
Date: Sat, 30 Apr 2022 14:31:53 +0200
Subject: [PATCH] Make sure the test server waits for incoming connection
The socket state is local, so it's possible to report 'connected',
resume to coroutine finish it and destroy the socket before the
server has time to actually get the incoming connection. This
results in the test server being stopped by the test before it
actually starts waiting for incoming connection, causing the
server to incorrectly report the test as time out.
The fix is for the test to wait at the end for the server to
confirm it has gotten the incoming connection.
---
tests/qcoroabstractsocket.cpp | 23 +++++++++++++++++++++++
tests/qcorolocalsocket.cpp | 18 ++++++++++++++++++
tests/testhttpserver.h | 12 ++++++++++++
3 files changed, 53 insertions(+)
diff --git a/tests/qcoroabstractsocket.cpp b/tests/qcoroabstractsocket.cpp
index df4754b..6207fb4 100644
--- a/tests/qcoroabstractsocket.cpp
+++ b/tests/qcoroabstractsocket.cpp
@@ -24,6 +24,9 @@ class QCoroAbstractSocketTest : public QCoro::TestObject<QCoroAbstractSocketTest
co_await qCoro(socket).waitForConnected();
QCORO_COMPARE(socket.state(), QAbstractSocket::ConnectedState);
+
+ // Make sure the server gets the connection as well
+ QCORO_VERIFY(mServer.waitForConnection());
}
void testThenWaitForConnectedTriggers_coro(TestLoop &el) {
@@ -37,6 +40,7 @@ class QCoroAbstractSocketTest : public QCoro::TestObject<QCoroAbstractSocketTest
});
el.exec();
QVERIFY(called);
+ QVERIFY(mServer.waitForConnection());
}
QCoro::Task<> testWaitForDisconnectedTriggers_coro(QCoro::TestContext) {
@@ -49,6 +53,8 @@ class QCoroAbstractSocketTest : public QCoro::TestObject<QCoroAbstractSocketTest
co_await qCoro(socket).waitForDisconnected();
QCORO_COMPARE(socket.state(), QAbstractSocket::UnconnectedState);
+
+ QCORO_VERIFY(mServer.waitForConnection());
}
void testThenWaitForDisconnectedTriggers_coro(TestLoop &el) {
@@ -72,6 +78,8 @@ class QCoroAbstractSocketTest : public QCoro::TestObject<QCoroAbstractSocketTest
el.exec();
QVERIFY(called);
+
+ QVERIFY(mServer.waitForConnection());
}
QCoro::Task<> testDoesntCoAwaitConnectedSocket_coro(QCoro::TestContext context) {
@@ -82,6 +90,8 @@ class QCoroAbstractSocketTest : public QCoro::TestObject<QCoroAbstractSocketTest
context.setShouldNotSuspend();
co_await qCoro(socket).waitForConnected();
+
+ QCORO_VERIFY(mServer.waitForConnection());
}
void testThenDoesntCoAwaitConnectedSocket_coro(TestLoop &el) {
@@ -103,6 +113,8 @@ class QCoroAbstractSocketTest : public QCoro::TestObject<QCoroAbstractSocketTest
el.exec();
QVERIFY(called);
+
+ QVERIFY(mServer.waitForConnection());
}
QCoro::Task<> testDoesntCoAwaitDisconnectedSocket_coro(QCoro::TestContext context) {
@@ -138,6 +150,7 @@ class QCoroAbstractSocketTest : public QCoro::TestObject<QCoroAbstractSocketTest
co_await qCoro(socket).connectToHost(QHostAddress::LocalHost, mServer.port());
QCORO_COMPARE(socket.state(), QAbstractSocket::ConnectedState);
+ QCORO_VERIFY(mServer.waitForConnection());
}
void testThenConnectToServerWithArgs_coro(TestLoop &el) {
@@ -151,6 +164,7 @@ class QCoroAbstractSocketTest : public QCoro::TestObject<QCoroAbstractSocketTest
});
el.exec();
QVERIFY(called);
+ QVERIFY(mServer.waitForConnection());
}
QCoro::Task<> testWaitForConnectedTimeout_coro(QCoro::TestContext) {
@@ -186,6 +200,8 @@ class QCoroAbstractSocketTest : public QCoro::TestObject<QCoroAbstractSocketTest
QCORO_COMPARE(socket.state(), QAbstractSocket::ConnectedState);
QCORO_TEST_TIMEOUT(co_await qCoro(socket).waitForDisconnected(10ms));
+
+ QCORO_VERIFY(mServer.waitForConnection());
}
void testThenWaitForDisconnectedTimeout_coro(TestLoop &el) {
@@ -208,6 +224,7 @@ class QCoroAbstractSocketTest : public QCoro::TestObject<QCoroAbstractSocketTest
});
});
el.exec();
+ QVERIFY(mServer.waitForConnection());
}
QCoro::Task<> testReadAllTriggers_coro(QCoro::TestContext) {
@@ -218,6 +235,7 @@ class QCoroAbstractSocketTest : public QCoro::TestObject<QCoroAbstractSocketTest
socket.write("GET /stream HTTP/1.1\r\n");
QCORO_TEST_IODEVICE_READALL(socket);
+ QCORO_VERIFY(mServer.waitForConnection());
}
void testThenReadAllTriggers_coro(TestLoop &el) {
@@ -242,6 +260,7 @@ class QCoroAbstractSocketTest : public QCoro::TestObject<QCoroAbstractSocketTest
el.exec();
QVERIFY(called);
+ QVERIFY(mServer.waitForConnection());
}
QCoro::Task<> testReadTriggers_coro(QCoro::TestContext) {
@@ -252,6 +271,7 @@ class QCoroAbstractSocketTest : public QCoro::TestObject<QCoroAbstractSocketTest
socket.write("GET /stream HTTP/1.1\r\n");
QCORO_TEST_IODEVICE_READ(socket);
+ QCORO_VERIFY(mServer.waitForConnection());
}
void testThenReadTriggers_coro(TestLoop &el) {
@@ -276,6 +296,7 @@ class QCoroAbstractSocketTest : public QCoro::TestObject<QCoroAbstractSocketTest
el.exec();
QVERIFY(called);
+ QVERIFY(mServer.waitForConnection());
}
QCoro::Task<> testReadLineTriggers_coro(QCoro::TestContext) {
@@ -287,6 +308,7 @@ class QCoroAbstractSocketTest : public QCoro::TestObject<QCoroAbstractSocketTest
QCORO_TEST_IODEVICE_READLINE(socket);
QCORO_COMPARE(lines.size(), 14);
+ QCORO_VERIFY(mServer.waitForConnection());
}
void testThenReadLineTriggers_coro(TestLoop &el) {
@@ -311,6 +333,7 @@ class QCoroAbstractSocketTest : public QCoro::TestObject<QCoroAbstractSocketTest
el.exec();
QVERIFY(called);
+ QVERIFY(mServer.waitForConnection());
}
private Q_SLOTS:
diff --git a/tests/qcorolocalsocket.cpp b/tests/qcorolocalsocket.cpp
index 19f2703..f7b2b10 100644
--- a/tests/qcorolocalsocket.cpp
+++ b/tests/qcorolocalsocket.cpp
@@ -25,6 +25,7 @@ class QCoroLocalSocketTest : public QCoro::TestObject<QCoroLocalSocketTest> {
co_await qCoro(socket).waitForConnected();
QCORO_COMPARE(socket.state(), QLocalSocket::ConnectedState);
+ QCORO_VERIFY(mServer.waitForConnection());
}
void testThenWaitForConnectedTriggers_coro(TestLoop &el) {
@@ -38,6 +39,7 @@ class QCoroLocalSocketTest : public QCoro::TestObject<QCoroLocalSocketTest> {
});
el.exec();
QVERIFY(called);
+ QVERIFY(mServer.waitForConnection());
}
QCoro::Task<> testWaitForDisconnectedTriggers_coro(QCoro::TestContext) {
@@ -50,6 +52,7 @@ class QCoroLocalSocketTest : public QCoro::TestObject<QCoroLocalSocketTest> {
co_await qCoro(socket).waitForDisconnected();
QCORO_COMPARE(socket.state(), QLocalSocket::UnconnectedState);
+ QCORO_VERIFY(mServer.waitForConnection());
}
void testThenWaitForDisconnectedTriggers_coro(TestLoop &el) {
@@ -66,6 +69,7 @@ class QCoroLocalSocketTest : public QCoro::TestObject<QCoroLocalSocketTest> {
});
el.exec();
QVERIFY(called);
+ QVERIFY(mServer.waitForConnection());
}
// On Linux at least, QLocalSocket connects immediately and synchronously
@@ -78,6 +82,7 @@ class QCoroLocalSocketTest : public QCoro::TestObject<QCoroLocalSocketTest> {
QCORO_COMPARE(socket.state(), QLocalSocket::ConnectedState);
co_await qCoro(socket).waitForConnected();
+ QCORO_VERIFY(mServer.waitForConnection());
}
void testThenDoesntCoAwaitConnectedSocket_coro(TestLoop &el) {
@@ -93,6 +98,7 @@ class QCoroLocalSocketTest : public QCoro::TestObject<QCoroLocalSocketTest> {
});
el.exec();
QVERIFY(called);
+ QVERIFY(mServer.waitForConnection());
}
QCoro::Task<> testDoesntCoAwaitDisconnectedSocket_coro(QCoro::TestContext context) {
@@ -128,6 +134,7 @@ class QCoroLocalSocketTest : public QCoro::TestObject<QCoroLocalSocketTest> {
co_await qCoro(socket).connectToServer(QCoroLocalSocketTest::getSocketName());
QCORO_COMPARE(socket.state(), QLocalSocket::ConnectedState);
+ QCORO_VERIFY(mServer.waitForConnection());
}
void testThenConnectToServerWithArgs_coro(TestLoop &el) {
@@ -140,6 +147,7 @@ class QCoroLocalSocketTest : public QCoro::TestObject<QCoroLocalSocketTest> {
});
el.exec();
QVERIFY(called);
+ QVERIFY(mServer.waitForConnection());
}
QCoro::Task<> testConnectToServer_coro(QCoro::TestContext context) {
@@ -151,6 +159,7 @@ class QCoroLocalSocketTest : public QCoro::TestObject<QCoroLocalSocketTest> {
co_await qCoro(socket).connectToServer();
QCORO_COMPARE(socket.state(), QLocalSocket::ConnectedState);
+ QCORO_VERIFY(mServer.waitForConnection());
}
void testThenConnectToServer_coro(TestLoop &el) {
@@ -164,6 +173,7 @@ class QCoroLocalSocketTest : public QCoro::TestObject<QCoroLocalSocketTest> {
});
el.exec();
QVERIFY(called);
+ QVERIFY(mServer.waitForConnection());
}
QCoro::Task<> testWaitForConnectedTimeout_coro(QCoro::TestContext) {
@@ -198,6 +208,7 @@ class QCoroLocalSocketTest : public QCoro::TestObject<QCoroLocalSocketTest> {
QCORO_COMPARE(socket.state(), QLocalSocket::ConnectedState);
QCORO_TEST_TIMEOUT(co_await qCoro(socket).waitForDisconnected(10ms));
+ QCORO_VERIFY(mServer.waitForConnection());
}
void testThenWaitForDisconnectedTimeout_coro(TestLoop &el) {
@@ -215,6 +226,7 @@ class QCoroLocalSocketTest : public QCoro::TestObject<QCoroLocalSocketTest> {
const auto end = std::chrono::steady_clock::now();
QVERIFY(end - start < 500ms);
QVERIFY(called);
+ QVERIFY(mServer.waitForConnection());
}
QCoro::Task<> testReadAllTriggers_coro(QCoro::TestContext) {
@@ -225,6 +237,7 @@ class QCoroLocalSocketTest : public QCoro::TestObject<QCoroLocalSocketTest> {
socket.write("GET /stream HTTP/1.1\r\n");
QCORO_TEST_IODEVICE_READALL(socket);
+ QCORO_VERIFY(mServer.waitForConnection());
}
void testThenReadAllTriggers_coro(TestLoop &el) {
@@ -241,6 +254,7 @@ class QCoroLocalSocketTest : public QCoro::TestObject<QCoroLocalSocketTest> {
el.exec();
QVERIFY(called);
+ QVERIFY(mServer.waitForConnection());
}
QCoro::Task<> testReadTriggers_coro(QCoro::TestContext) {
@@ -251,6 +265,7 @@ class QCoroLocalSocketTest : public QCoro::TestObject<QCoroLocalSocketTest> {
socket.write("GET /stream HTTP/1.1\r\n");
QCORO_TEST_IODEVICE_READ(socket);
+ QCORO_VERIFY(mServer.waitForConnection());
}
void testThenReadTriggers_coro(TestLoop &el) {
@@ -266,6 +281,7 @@ class QCoroLocalSocketTest : public QCoro::TestObject<QCoroLocalSocketTest> {
socket.write("GET /block HTTP/1.1\r\n");
el.exec();
QVERIFY(called);
+ QVERIFY(mServer.waitForConnection());
}
QCoro::Task<> testReadLineTriggers_coro(QCoro::TestContext) {
@@ -277,6 +293,7 @@ class QCoroLocalSocketTest : public QCoro::TestObject<QCoroLocalSocketTest> {
QCORO_TEST_IODEVICE_READLINE(socket);
QCORO_COMPARE(lines.size(), 14);
+ QCORO_VERIFY(mServer.waitForConnection());
}
void testThenReadLineTriggers_coro(TestLoop &el) {
@@ -293,6 +310,7 @@ class QCoroLocalSocketTest : public QCoro::TestObject<QCoroLocalSocketTest> {
el.exec();
QVERIFY(called);
+ QVERIFY(mServer.waitForConnection());
}
private Q_SLOTS:
diff --git a/tests/testhttpserver.h b/tests/testhttpserver.h
index 005a5ba..b65a4bf 100644
--- a/tests/testhttpserver.h
+++ b/tests/testhttpserver.h
@@ -52,6 +52,8 @@ class TestHttpServer {
public:
template<typename T>
void start(const T &name) {
+ mPort = 0;
+ mHasConnection = false;
mStop = false;
mExpectTimeout = false;
// Can't use QThread::create, it's only available when Qt is built with C++17,
@@ -69,6 +71,7 @@ class TestHttpServer {
}
mThread.reset();
mPort = 0;
+ mHasConnection = false;
}
uint16_t port() const {
@@ -79,6 +82,11 @@ class TestHttpServer {
mExpectTimeout = expectTimeout;
}
+ bool waitForConnection() {
+ std::unique_lock lock(mReadyMutex);
+ return mServerReady.wait_for(lock, std::chrono::seconds(5), [this]() { return mHasConnection; });
+ }
+
private:
template<typename T>
void run(const T &name) {
@@ -117,6 +125,9 @@ class TestHttpServer {
return;
}
+ mHasConnection = true;
+ mServerReady.notify_all();
+
if (conn->waitForReadyRead(1000)) {
const auto request = conn->readLine();
qDebug() << request;
@@ -171,6 +182,7 @@ class TestHttpServer {
std::mutex mReadyMutex;
std::condition_variable mServerReady;
uint16_t mPort = 0;
+ bool mHasConnection = false;
std::atomic_bool mStop = false;
std::atomic_bool mExpectTimeout = false;
};

@ -1,4 +1,3 @@
%undefine __cmake_in_source_build
%global use_qt5 1
%global use_qt6 1
@ -15,14 +14,17 @@ coroutine is co_awaiting, the Qt event loop runs as usual, meaning that your
application remains responsive.}
Name: qcoro
Version: 0.4.0
Release: 4%{?dist}
Version: 0.5.1
Release: 1%{?dist}
License: MIT
Summary: C++ Coroutines for Qt
URL: https://github.com/danvratil/%{name}
Source0: %{url}/archive/v%{version}/%{name}-%{version}.tar.gz
# https://github.com/danvratil/qcoro/commit/afa8824d941731d85116e0d08d619581939af734
Patch100: %{name}-tests-fixes.patch
%if 0%{?use_qt5}
BuildRequires: cmake(Qt5Concurrent)
BuildRequires: cmake(Qt5Core)
@ -125,13 +127,13 @@ popd
%check
%if 0%{?use_qt5}
pushd %{qt5_build_dir}
%ctest --timeout 3600 --exclude-regex '(qcoroprocess|qcoroabstractsocket|qcorolocalsocket)'
%ctest --timeout 3600
popd
%endif
%if 0%{?use_qt6}
pushd %{qt6_build_dir}
%ctest --timeout 3600 --exclude-regex '(qcoroprocess|qcoroabstractsocket|qcorolocalsocket)'
%ctest --timeout 3600
popd
%endif
@ -145,6 +147,7 @@ popd
%{_includedir}/%{name}5/
%{_libdir}/cmake/%{appname}5*/
%{_libdir}/lib%{appname}5*.so
%{_libdir}/qt5/mkspecs/modules/qt_%{appname}*.pri
%endif
%if 0%{?use_qt6}
@ -157,9 +160,13 @@ popd
%{_includedir}/%{name}6/
%{_libdir}/cmake/%{appname}6*/
%{_libdir}/lib%{appname}6*.so
%{_libdir}/qt6/mkspecs/modules/qt_%{appname}*.pri
%endif
%changelog
* Sat May 07 2022 Vitaly Zaitsev <vitaly@easycoding.org> - 0.5.1-1
- Updated to version 0.5.1.
* Wed Mar 16 2022 Vitaly Zaitsev <vitaly@easycoding.org> - 0.4.0-4
- Enabled s390x build.

@ -1 +1 @@
SHA512 (qcoro-0.4.0.tar.gz) = bca0b0a02dabeabbf55fc1edc48d7d725ce8070a9f26317034f439958595d9a15c683d0bccaa4d1483d64d0a7737e84a0f7597bc3ad189b5a51f6b02d320cccf
SHA512 (qcoro-0.5.1.tar.gz) = d4329f8f73203db0bfedd1a4a915cb20d01b4c00a3b1570640ff3aa9a77863bb4fe2f9d19f814d7d7676cd2508448ef28ddd1ece00037466e5dbedc63c3a638b

Loading…
Cancel
Save