Fix 'out of process' autotests
We are, arguably, not testing QProcess and its ability to start or finish, we test QUdpSocket. If, for some reason (as we discovered on some specific machines recently) the process does not start or does not produce any output (canReadLine), we QSKIP instead of failing. Also, all those QCOMPARE will bypass the part there we stop processes - so must be RAII-protected. Fixes: QTBUG-82717 Change-Id: Idfb0d4a483d753f336b3827875eeaf51c79270e2 Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
This commit is contained in:
parent
1309205b8b
commit
c668fd940d
@ -1090,12 +1090,21 @@ void tst_QUdpSocket::outOfProcessConnectedClientServerTest()
|
|||||||
QProcess serverProcess;
|
QProcess serverProcess;
|
||||||
serverProcess.start(QLatin1String("clientserver/clientserver server 1 1"),
|
serverProcess.start(QLatin1String("clientserver/clientserver server 1 1"),
|
||||||
QIODevice::ReadWrite | QIODevice::Text);
|
QIODevice::ReadWrite | QIODevice::Text);
|
||||||
QVERIFY2(serverProcess.waitForStarted(3000),
|
|
||||||
qPrintable("Failed to start subprocess: " + serverProcess.errorString()));
|
const auto serverProcessCleaner = qScopeGuard([&serverProcess] {
|
||||||
|
serverProcess.kill();
|
||||||
|
serverProcess.waitForFinished();
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!serverProcess.waitForStarted(3000))
|
||||||
|
QSKIP("Failed to start server as a subprocess");
|
||||||
|
|
||||||
// Wait until the server has started and reports success.
|
// Wait until the server has started and reports success.
|
||||||
while (!serverProcess.canReadLine())
|
while (!serverProcess.canReadLine()) {
|
||||||
QVERIFY(serverProcess.waitForReadyRead(3000));
|
if (!serverProcess.waitForReadyRead(3000))
|
||||||
|
QSKIP("No output from the server process, bailing out");
|
||||||
|
}
|
||||||
|
|
||||||
QByteArray serverGreeting = serverProcess.readLine();
|
QByteArray serverGreeting = serverProcess.readLine();
|
||||||
QVERIFY(serverGreeting != QByteArray("XXX\n"));
|
QVERIFY(serverGreeting != QByteArray("XXX\n"));
|
||||||
int serverPort = serverGreeting.trimmed().toInt();
|
int serverPort = serverGreeting.trimmed().toInt();
|
||||||
@ -1105,12 +1114,21 @@ void tst_QUdpSocket::outOfProcessConnectedClientServerTest()
|
|||||||
clientProcess.start(QString::fromLatin1("clientserver/clientserver connectedclient %1 %2")
|
clientProcess.start(QString::fromLatin1("clientserver/clientserver connectedclient %1 %2")
|
||||||
.arg(QLatin1String("127.0.0.1")).arg(serverPort),
|
.arg(QLatin1String("127.0.0.1")).arg(serverPort),
|
||||||
QIODevice::ReadWrite | QIODevice::Text);
|
QIODevice::ReadWrite | QIODevice::Text);
|
||||||
QVERIFY2(clientProcess.waitForStarted(3000),
|
|
||||||
qPrintable("Failed to start subprocess: " + clientProcess.errorString()));
|
|
||||||
|
|
||||||
// Wait until the server has started and reports success.
|
const auto clientProcessCleaner = qScopeGuard([&clientProcess] {
|
||||||
while (!clientProcess.canReadLine())
|
clientProcess.kill();
|
||||||
QVERIFY(clientProcess.waitForReadyRead(3000));
|
clientProcess.waitForFinished();
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!clientProcess.waitForStarted(3000))
|
||||||
|
QSKIP("Client process did not start");
|
||||||
|
|
||||||
|
// Wait until the client has started and reports success.
|
||||||
|
while (!clientProcess.canReadLine()) {
|
||||||
|
if (!clientProcess.waitForReadyRead(3000))
|
||||||
|
QSKIP("No output from the client process, bailing out");
|
||||||
|
}
|
||||||
|
|
||||||
QByteArray clientGreeting = clientProcess.readLine();
|
QByteArray clientGreeting = clientProcess.readLine();
|
||||||
QCOMPARE(clientGreeting, QByteArray("ok\n"));
|
QCOMPARE(clientGreeting, QByteArray("ok\n"));
|
||||||
|
|
||||||
@ -1135,11 +1153,6 @@ void tst_QUdpSocket::outOfProcessConnectedClientServerTest()
|
|||||||
QCOMPARE(serverData.at(i * 3 + 2).trimmed().mid(8).toInt(),
|
QCOMPARE(serverData.at(i * 3 + 2).trimmed().mid(8).toInt(),
|
||||||
sdata.mid(4).trimmed().toInt() * 2);
|
sdata.mid(4).trimmed().toInt() * 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
clientProcess.kill();
|
|
||||||
QVERIFY(clientProcess.waitForFinished());
|
|
||||||
serverProcess.kill();
|
|
||||||
QVERIFY(serverProcess.waitForFinished());
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1151,12 +1164,21 @@ void tst_QUdpSocket::outOfProcessUnconnectedClientServerTest()
|
|||||||
QProcess serverProcess;
|
QProcess serverProcess;
|
||||||
serverProcess.start(QLatin1String("clientserver/clientserver server 1 1"),
|
serverProcess.start(QLatin1String("clientserver/clientserver server 1 1"),
|
||||||
QIODevice::ReadWrite | QIODevice::Text);
|
QIODevice::ReadWrite | QIODevice::Text);
|
||||||
QVERIFY2(serverProcess.waitForStarted(3000),
|
|
||||||
qPrintable("Failed to start subprocess: " + serverProcess.errorString()));
|
const auto serverProcessCleaner = qScopeGuard([&serverProcess] {
|
||||||
|
serverProcess.kill();
|
||||||
|
serverProcess.waitForFinished();
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!serverProcess.waitForStarted(3000))
|
||||||
|
QSKIP("Failed to start the server subprocess");
|
||||||
|
|
||||||
// Wait until the server has started and reports success.
|
// Wait until the server has started and reports success.
|
||||||
while (!serverProcess.canReadLine())
|
while (!serverProcess.canReadLine()) {
|
||||||
QVERIFY(serverProcess.waitForReadyRead(3000));
|
if (!serverProcess.waitForReadyRead(3000))
|
||||||
|
QSKIP("No output from the server, probably, it is not running");
|
||||||
|
}
|
||||||
|
|
||||||
QByteArray serverGreeting = serverProcess.readLine();
|
QByteArray serverGreeting = serverProcess.readLine();
|
||||||
QVERIFY(serverGreeting != QByteArray("XXX\n"));
|
QVERIFY(serverGreeting != QByteArray("XXX\n"));
|
||||||
int serverPort = serverGreeting.trimmed().toInt();
|
int serverPort = serverGreeting.trimmed().toInt();
|
||||||
@ -1166,12 +1188,21 @@ void tst_QUdpSocket::outOfProcessUnconnectedClientServerTest()
|
|||||||
clientProcess.start(QString::fromLatin1("clientserver/clientserver unconnectedclient %1 %2")
|
clientProcess.start(QString::fromLatin1("clientserver/clientserver unconnectedclient %1 %2")
|
||||||
.arg(QLatin1String("127.0.0.1")).arg(serverPort),
|
.arg(QLatin1String("127.0.0.1")).arg(serverPort),
|
||||||
QIODevice::ReadWrite | QIODevice::Text);
|
QIODevice::ReadWrite | QIODevice::Text);
|
||||||
QVERIFY2(clientProcess.waitForStarted(3000),
|
|
||||||
qPrintable("Failed to start subprocess: " + clientProcess.errorString()));
|
|
||||||
|
|
||||||
// Wait until the server has started and reports success.
|
const auto clientProcessCleaner = qScopeGuard([&clientProcess] {
|
||||||
while (!clientProcess.canReadLine())
|
clientProcess.kill();
|
||||||
QVERIFY(clientProcess.waitForReadyRead(3000));
|
clientProcess.waitForFinished();
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!clientProcess.waitForStarted(3000))
|
||||||
|
QSKIP("Failed to start the client's subprocess");
|
||||||
|
|
||||||
|
// Wait until the client has started and reports success.
|
||||||
|
while (!clientProcess.canReadLine()) {
|
||||||
|
if (!clientProcess.waitForReadyRead(3000))
|
||||||
|
QSKIP("The client subprocess produced not output, exiting.");
|
||||||
|
}
|
||||||
|
|
||||||
QByteArray clientGreeting = clientProcess.readLine();
|
QByteArray clientGreeting = clientProcess.readLine();
|
||||||
QCOMPARE(clientGreeting, QByteArray("ok\n"));
|
QCOMPARE(clientGreeting, QByteArray("ok\n"));
|
||||||
|
|
||||||
@ -1197,11 +1228,6 @@ void tst_QUdpSocket::outOfProcessUnconnectedClientServerTest()
|
|||||||
QCOMPARE(serverData.at(i * 3 + 2).trimmed().mid(8).toInt(),
|
QCOMPARE(serverData.at(i * 3 + 2).trimmed().mid(8).toInt(),
|
||||||
sdata.mid(4).trimmed().toInt() * 2);
|
sdata.mid(4).trimmed().toInt() * 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
clientProcess.kill();
|
|
||||||
QVERIFY(clientProcess.waitForFinished());
|
|
||||||
serverProcess.kill();
|
|
||||||
QVERIFY(serverProcess.waitForFinished());
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user