Skip to content

Commit d244115

Browse files
committed
try fix single server test
1 parent 93f7abe commit d244115

6 files changed

Lines changed: 35 additions & 8 deletions

File tree

Heart/DataBaseSpace/databasenode.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ bool DataBaseNode::run(const QString &addres,
107107
if (localNodeName.isEmpty())
108108
return false;
109109

110-
_localNodeName = localNodeName;
110+
setLocalNodeName(localNodeName);
111111

112112
if (!isSqlInited() && !initSqlDb()) {
113113
return false;
@@ -450,6 +450,10 @@ bool DataBaseNode::upgradeDataBase() {
450450
return true;
451451
}
452452

453+
const QString &DataBaseNode::localNodeName() const {
454+
return _localNodeName;
455+
}
456+
453457
void DataBaseNode::setLocalNodeName(const QString &newLocalNodeName) {
454458
_localNodeName = newLocalNodeName;
455459
}
@@ -458,7 +462,7 @@ QVariantMap DataBaseNode::defaultDbParams() const {
458462

459463
return {
460464
{"DBDriver", "QSQLITE"},
461-
{"DBFilePath", DEFAULT_DB_PATH + "/" + _localNodeName + "/" + _localNodeName + "_" + DEFAULT_DB_NAME},
465+
{"DBFilePath", DEFAULT_DB_PATH + "/" + localNodeName() + "/" + localNodeName() + "_" + DEFAULT_DB_NAME},
462466
};
463467
}
464468

Heart/DataBaseSpace/databasenode.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,8 +205,16 @@ class HEARTSHARED_EXPORT DataBaseNode : public AbstractNode
205205
const std::function<bool (const QSharedPointer<QH::PKG::DBObject>&)> &changeAction);
206206

207207

208+
208209
protected:
209210

211+
/**
212+
* @brief localNodeName This method return local node name.
213+
*
214+
* @return local node name
215+
*/
216+
const QString &localNodeName() const;
217+
210218
/**
211219
* @brief setLocalNodeName This method sets new local name of database file.
212220
* @note This method must be invoked before the DataBaseNode::initsqlDb and the DataBaseNode::run methods.

Heart/DataBaseSpace/singleclient.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,13 @@ ErrorCodes::Code SingleClient::getLastError() const {
393393
return _lastError;
394394
}
395395

396+
ErrorCodes::Code SingleClient::takeLastError() {
397+
auto result = _lastError;
398+
setLastError(ErrorCodes::NoError);
399+
400+
return result;
401+
}
402+
396403
QString SingleClient::getLastErrorString() const {
397404
return ErrorCodes::DBErrorCodesHelper::toString(_lastError);
398405
}

Heart/DataBaseSpace/singleclient.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,12 @@ class HEARTSHARED_EXPORT SingleClient: public SingleBase
132132
*/
133133
ErrorCodes::Code getLastError() const;
134134

135+
/**
136+
* @brief takeLastError This method take last erro code. after call this object sets no error to last error.
137+
* @return LastError code.
138+
*/
139+
ErrorCodes::Code takeLastError();
140+
135141
/**
136142
* @brief getLastErrorString This method return the string implementation of a last code error.
137143
* @return string value of the last error.

HeartTests/AbstractSpace/testutils.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,13 @@ TestUtils::~TestUtils() {
4646

4747
bool TestUtils::wait(const std::function<bool()> &forWait, int msec) const {
4848
auto curmsec = QDateTime::currentMSecsSinceEpoch() + msec;
49-
while (curmsec > QDateTime::currentMSecsSinceEpoch() && !forWait()) {
49+
bool waitFor = false;
50+
while (curmsec > QDateTime::currentMSecsSinceEpoch() && !waitFor) {
51+
waitFor = forWait();
5052
QCoreApplication::processEvents();
5153
}
5254
QCoreApplication::processEvents();
53-
return forWait();
55+
return waitFor;
5456
}
5557

5658
bool TestUtils::connectFunc(

HeartTests/DataBaseSpace/singleservertest.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,19 +85,19 @@ void SingleServerTest::loginTest() {
8585
};
8686

8787
auto checkLoginNonExitsUser = [client](){
88-
return client->getLastError() == static_cast<int>(QH::ErrorCodes::UserNotExits);
88+
return client->takeLastError() == static_cast<int>(QH::ErrorCodes::UserNotExits);
8989
};
9090

9191
auto checksigupExitsUser = [client](){
92-
return client->getLastError() == static_cast<int>(QH::ErrorCodes::UserExits);
92+
return client->takeLastError() == static_cast<int>(QH::ErrorCodes::UserExits);
9393
};
9494

9595
auto checkLoginInvalidPassword = [client](){
96-
return client->getLastError() == static_cast<int>(QH::ErrorCodes::UserInvalidPasswoed);
96+
return client->takeLastError() == static_cast<int>(QH::ErrorCodes::UserInvalidPasswoed);
9797
};
9898

9999
auto checkRemoveNotLoginningClient = [client](){
100-
return client->getLastError() == static_cast<int>(QH::ErrorCodes::UserNotLogged);
100+
return client->takeLastError() == static_cast<int>(QH::ErrorCodes::UserNotLogged);
101101
};
102102

103103
QVERIFY(client && server);

0 commit comments

Comments
 (0)