@@ -50,7 +50,7 @@ void BasicServiceTest::testStart()
50
50
51
51
socket = new QLocalSocket (this );
52
52
socket->connectToServer (QStringLiteral (" __qtservice_testservice" ));
53
- QVERIFY (socket->waitForConnected (30000 ));
53
+ QVERIFY2 (socket->waitForConnected (30000 ), qUtf8Printable (socket-> errorString () ));
54
54
stream.setDevice (socket);
55
55
56
56
QByteArray msg;
@@ -106,35 +106,43 @@ void BasicServiceTest::testRestart()
106
106
{
107
107
TEST_STATUS (ServiceControl::Status::Running);
108
108
resetSettings ();
109
- if (control->blocking () != ServiceControl::BlockMode::Blocking)
110
- return ;
111
- testFeature (static_cast <ServiceControl::SupportFlag>(static_cast <int >(ServiceControl::SupportFlag::Start |
112
- ServiceControl::SupportFlag::Stop)));
109
+
110
+ // run test for blocking backends or backends that report status - but those must support start/stop
111
+ if (control->blocking () != ServiceControl::BlockMode::Blocking &&
112
+ !control->supportFlags ().testFlag (ServiceControl::SupportFlag::Status)) {
113
+ QEXPECT_FAIL (" " , " feature restart not supported by backend" , Abort);
114
+ } else {
115
+ QVERIFY (control->supportFlags ().testFlag (ServiceControl::SupportFlag::Start));
116
+ QVERIFY (control->supportFlags ().testFlag (ServiceControl::SupportFlag::Stop));
117
+ }
113
118
114
119
QVERIFY2 (control->restart (), qUtf8Printable (control->error ()));
115
- QThread::sleep (10 );
116
- // blocking should only return after the server started, but for non blocking this may not be the case...
117
- if (control->blocking () != ServiceControl::BlockMode::Blocking)
118
- QThread::sleep (3 );
119
120
120
121
QByteArray msg;
121
122
#ifndef Q_OS_WIN
122
123
READ_LOOP (msg);
123
124
QCOMPARE (msg, QByteArray (" stopping" ));
124
125
msg = {};
125
126
#endif
126
- QVERIFY (socket->waitForDisconnected (5000 ));
127
+ QVERIFY2 (socket->waitForDisconnected (5000 ), qUtf8Printable (socket-> errorString () ));
127
128
socket->deleteLater ();
128
129
130
+ // blocking should only return after the server started, but for non blocking this may not be the case...
131
+ if (control->blocking () != ServiceControl::BlockMode::Blocking) {
132
+ for (auto i = 0 ; i < 10 ; ++i) {
133
+ QThread::msleep (500 );
134
+ QCoreApplication::processEvents ();
135
+ }
136
+ }
137
+ TEST_STATUS (ServiceControl::Status::Running);
138
+
129
139
socket = new QLocalSocket (this );
130
140
socket->connectToServer (QStringLiteral (" __qtservice_testservice" ));
131
- QVERIFY (socket->waitForConnected (30000 ));
141
+ QVERIFY2 (socket->waitForConnected (30000 ), qUtf8Printable (socket-> errorString () ));
132
142
stream.setDevice (socket);
133
143
134
144
READ_LOOP (msg);
135
145
QCOMPARE (msg, QByteArray (" started" ));
136
-
137
- TEST_STATUS (ServiceControl::Status::Running);
138
146
}
139
147
140
148
void BasicServiceTest::testCustom ()
@@ -156,7 +164,7 @@ void BasicServiceTest::testStop()
156
164
READ_LOOP (msg);
157
165
QCOMPARE (msg, QByteArray (" stopping" ));
158
166
#endif
159
- QVERIFY (socket->waitForDisconnected (5000 ));
167
+ QVERIFY2 (socket->waitForDisconnected (5000 ), qUtf8Printable (socket-> errorString () ));
160
168
161
169
TEST_STATUS (ServiceControl::Status::Stopped);
162
170
}
@@ -273,10 +281,7 @@ void BasicServiceTest::performSocketTest()
273
281
274
282
auto tcpSocket = new QTcpSocket (this );
275
283
tcpSocket->connectToHost (QStringLiteral (" 127.0.0.1" ), 15843 );
276
- while (control->status () == ServiceControl::Status::Starting)
277
- QThread::msleep (500 );
278
- QVERIFY (tcpSocket->waitForConnected (5000 ));
279
-
284
+ QVERIFY2 (tcpSocket->waitForConnected (5000 ), qUtf8Printable (socket->errorString ()));
280
285
TEST_STATUS (ServiceControl::Status::Running);
281
286
282
287
QByteArray msg = " hello world" ;
0 commit comments