mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-11-10 03:53:26 -08:00
[Server] Smoke-test the dev server end to end (#7865)
* [Server] Smoke-test the dev server end to end Spawns servatrice-dev on an ephemeral port and drives a real RemoteClient through login, room list, room join and game creation, asserting each response and the Event_GameJoined payload. The test is WITH_SERVER-gated, links only the client remote library, and keeps the dev server's throwaway settings inside a temporary directory. * [Server] Publish the dev server's port through a file The smoke test parsed the listening port out of the dev server's stdout, but the server announces it from the main thread while the logger thread writes to the same stream. A log line can land inside the announcement — Arch CI caught it — leaving the digits on the next line, so the test read nothing and failed. Add --port-file, written through QSaveFile once the server listens, and read the port from there instead of from the log. The file is either absent or complete, so logging cannot corrupt the handshake. * [Tests] Tick the event loop while waiting for the port file The port-file wait loop slept with QThread::msleep and never reached the event dispatcher. QProcess fills its read buffers and flips its state only from its socket notifiers, so drainProcessOutput() was a no-op and a child that died before publishing its port went unnoticed until the full 15 s startup timeout, with empty stdout and stderr in the failure message. Pump the event loop instead, as the previous waitForReadyRead loop did.
This commit is contained in:
parent
15d69eb929
commit
ccda73fe5c
3 changed files with 347 additions and 4 deletions
|
|
@ -15,12 +15,14 @@
|
|||
#include "smtpclient.h"
|
||||
#include "version_string.h"
|
||||
|
||||
#include <QByteArray>
|
||||
#include <QCommandLineOption>
|
||||
#include <QCommandLineParser>
|
||||
#include <QCoreApplication>
|
||||
#include <QDir>
|
||||
#include <QFile>
|
||||
#include <QMetaObject>
|
||||
#include <QSaveFile>
|
||||
#include <QString>
|
||||
#include <QThread>
|
||||
#include <cstdlib>
|
||||
|
|
@ -88,6 +90,23 @@ void dumpState(Servatrice &server, const Servatrice_InMemoryDatabaseInterface &d
|
|||
std::cout << "servatrice-dev: log entries=" << database.getLogEntries().size() << std::endl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Publishes the bound port the way a script can read it.
|
||||
*
|
||||
* The stdout announcement is written from this thread while the logger thread writes to the same
|
||||
* stream, so a reader can see a log line inside it. A file written through QSaveFile is either
|
||||
* absent or complete, which makes the port deterministic to consume.
|
||||
*/
|
||||
bool writeListeningPort(const QString &path, int port)
|
||||
{
|
||||
QSaveFile file(path);
|
||||
if (!file.open(QIODevice::WriteOnly | QIODevice::Truncate)) {
|
||||
return false;
|
||||
}
|
||||
file.write(QByteArray::number(port) + '\n');
|
||||
return file.commit();
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
|
|
@ -103,9 +122,13 @@ int main(int argc, char *argv[])
|
|||
parser.addVersionOption();
|
||||
|
||||
QCommandLineOption portOption({"p", "port"}, "TCP port to listen on; 0 picks an ephemeral port.", "port", "0");
|
||||
QCommandLineOption portFileOption("port-file",
|
||||
"Write the bound listening port to this file once the server listens.",
|
||||
"path");
|
||||
QCommandLineOption seedOption("seed", "Seed for the game RNG; random when omitted.", "seed");
|
||||
QCommandLineOption dumpStateOption("dump-state", "Print the server state after startup and keep serving.");
|
||||
parser.addOption(portOption);
|
||||
parser.addOption(portFileOption);
|
||||
parser.addOption(seedOption);
|
||||
parser.addOption(dumpStateOption);
|
||||
parser.process(app);
|
||||
|
|
@ -169,11 +192,18 @@ int main(int argc, char *argv[])
|
|||
std::cerr << "servatrice-dev: the server is not listening" << std::endl;
|
||||
retval = EXIT_FAILURE;
|
||||
} else {
|
||||
std::cout << "servatrice-dev: listening on port " << listeningPort << std::endl;
|
||||
if (parser.isSet(dumpStateOption)) {
|
||||
dumpState(*server, *server->getInMemoryDatabase());
|
||||
const QString portFilePath = parser.value(portFileOption);
|
||||
if (!portFilePath.isEmpty() && !writeListeningPort(portFilePath, listeningPort)) {
|
||||
std::cerr << "servatrice-dev: cannot write the listening port to " << portFilePath.toStdString()
|
||||
<< std::endl;
|
||||
retval = EXIT_FAILURE;
|
||||
} else {
|
||||
std::cout << "servatrice-dev: listening on port " << listeningPort << std::endl;
|
||||
if (parser.isSet(dumpStateOption)) {
|
||||
dumpState(*server, *server->getInMemoryDatabase());
|
||||
}
|
||||
retval = QCoreApplication::exec();
|
||||
}
|
||||
retval = QCoreApplication::exec();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue