Switch integration test to mostly use unix sockets

By not using the same hardcoded number for every test, we can parallelize the test now.

There are several cases remaining where we can't easily use unix sockets (e.g. QSslSocket or imapauth module), for that ask kernel what port number is currently free to use. This is a bit racy though.
This commit is contained in:
Alexey Sokolov
2025-04-21 00:00:14 +01:00
parent 63d10ccb17
commit b642d92ce7
8 changed files with 152 additions and 85 deletions
+10 -1
View File
@@ -14,9 +14,12 @@
* limitations under the License.
*/
#include <gmock/gmock.h>
#include "base.h"
#include <gmock/gmock.h>
#include <QTcpServer>
using testing::AnyOf;
using testing::Eq;
@@ -58,4 +61,10 @@ Process::~Process() {
}
}
int PickPortNumber() {
QTcpServer tcp;
tcp.listen(QHostAddress::LocalHost);
return tcp.serverPort();
}
} // namespace znc_inttest
+9 -2
View File
@@ -21,6 +21,7 @@
#include <QCoreApplication>
#include <QDateTime>
#include <QProcess>
#include <QLocalSocket>
#include <QTcpSocket>
#include <memory>
@@ -49,6 +50,7 @@ class IO {
// Need to flush QTcpSocket, and QIODevice doesn't have flush at all...
static void FlushIfCan(QIODevice*) {}
static void FlushIfCan(QTcpSocket* sock) { sock->flush(); }
static void FlushIfCan(QLocalSocket* sock) { sock->flush(); }
Device* m_device;
bool m_verbose;
@@ -60,7 +62,7 @@ IO<Device> WrapIO(Device* d) {
return IO<Device>(d);
}
using Socket = IO<QTcpSocket>;
using Socket = IO<QLocalSocket>;
class Process : public IO<QProcess> {
public:
@@ -202,6 +204,9 @@ void IO<Device>::Write(QByteArray s, bool new_line) {
FlushIfCan(m_device);
}
inline void DisconnectFromServer(QTcpSocket* s) { s->disconnectFromHost(); }
inline void DisconnectFromServer(QLocalSocket* s) { s->disconnectFromServer(); }
template <typename Device>
void IO<Device>::Close() {
#ifdef __CYGWIN__
@@ -209,8 +214,10 @@ void IO<Device>::Close() {
// without this line
sleep(1);
#endif
m_device->disconnectFromHost();
DisconnectFromServer(m_device);
}
int PickPortNumber();
} // namespace znc_inttest
+13 -10
View File
@@ -15,6 +15,7 @@
*/
#include <QRegularExpression>
#include <QProcess>
#include "znctest.h"
#ifndef ZNC_BIN_DIR
@@ -24,13 +25,15 @@
namespace znc_inttest {
void WriteConfig(QString path) {
Process p(ZNC_BIN_DIR "/znc",
QStringList() << "--debug" << "--datadir" << path << "--makeconf",
[=](QProcess* p) {
auto env = p->processEnvironment();
env.insert("ZNC_LISTEN_UNIX_SOCKET",
path + "/inttest.znc");
p->setProcessEnvironment(env);
});
// clang-format off
Process p(ZNC_BIN_DIR "/znc", QStringList() << "--debug"
<< "--datadir" << path
<< "--makeconf");
p.ReadUntil("Listen on port"); p.Write("12345");
p.ReadUntil("Listen using SSL"); p.Write();
p.ReadUntil("IPv6"); p.Write();
p.ReadUntil("Username"); p.Write("user");
p.ReadUntil("password"); p.Write("hunter2", false);
p.ReadUntil("Confirm"); p.Write("hunter2", false);
@@ -41,7 +44,7 @@ void WriteConfig(QString path) {
p.ReadUntil("Bind host"); p.Write();
p.ReadUntil("Set up a network?"); p.Write();
p.ReadUntil("Name [libera]"); p.Write("test");
p.ReadUntil("Server host (host only)"); p.Write("127.0.0.1");
p.ReadUntil("Server host (host only)"); p.Write("unix:" + path.toUtf8() + "/inttest.ircd");
p.ReadUntil("Server uses SSL?"); p.Write();
p.ReadUntil("6667"); p.Write();
p.ReadUntil("password"); p.Write();
@@ -61,7 +64,7 @@ void WriteConfig(QString path) {
void ZNCTest::SetUp() {
WriteConfig(m_dir.path());
ASSERT_TRUE(m_server.listen(QHostAddress::LocalHost, 6667))
ASSERT_TRUE(m_server.listen(m_dir.path() + "/inttest.ircd"))
<< m_server.errorString().toStdString();
}
@@ -72,8 +75,8 @@ Socket ZNCTest::ConnectIRCd() {
Socket ZNCTest::ConnectClient() {
m_clients.emplace_back();
QTcpSocket& sock = m_clients.back();
sock.connectToHost("127.0.0.1", 12345);
QLocalSocket& sock = m_clients.back();
sock.connectToServer(m_dir.path() + "/inttest.znc");
[&] {
ASSERT_TRUE(sock.waitForConnected())
<< sock.errorString().toStdString();
+6 -5
View File
@@ -16,17 +16,18 @@
#pragma once
#include "base.h"
#include <QLocalServer>
#include <QNetworkAccessManager>
#include <QNetworkRequest>
#include <QNetworkReply>
#include <QTcpServer>
#include <QNetworkRequest>
#include <QTemporaryDir>
#include <QTextStream>
#include <QTimer>
#include <QUrl>
#include <QUrlQuery>
#include "base.h"
namespace znc_inttest {
void WriteConfig(QString path);
@@ -52,8 +53,8 @@ class ZNCTest : public testing::Test {
App m_app;
QNetworkAccessManager m_network;
QTemporaryDir m_dir;
QTcpServer m_server;
std::list<QTcpSocket> m_clients;
QLocalServer m_server;
std::list<QLocalSocket> m_clients;
};
} // namespace znc_inttest