Skip to content

Commit 31153c7

Browse files
Fix failing tests
1 parent 3529e7f commit 31153c7

File tree

2 files changed

+53
-13
lines changed

2 files changed

+53
-13
lines changed

src/Install/Installer.cpp

+10-5
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,15 @@ namespace sua {
3737
{
3838
Logger::trace("Installer::start({})", input);
3939

40-
_installerAgent->installBundle(input);
40+
if(_installerAgent->installBundle(input) == TechCode::InstallationFailed) {
41+
return TechCode::InstallationFailed;
42+
}
4143

42-
bool installing = true;
43-
uint32_t count = 0;
44+
int tries = 0;
4445
int32_t progressPercentage = 0;
4546
int32_t progressNotificationLimiter = 0;
4647

47-
while(installing) {
48+
while(_installerAgent->installing()) {
4849
progressPercentage = _installerAgent->getInstallProgress();
4950
std::this_thread::sleep_for(2000ms);
5051
tries++;
@@ -62,7 +63,11 @@ namespace sua {
6263
}
6364
}
6465

65-
return TechCode::OK;
66+
if(_installerAgent->succeeded()) {
67+
return TechCode::OK;
68+
}
69+
70+
return TechCode::InstallationFailed;
6671
}
6772

6873
} // namespace sua

utest/TestSelfUpdateScenarios.cpp

+43-8
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,17 @@ namespace {
3333
.Times(1)
3434
.RetiresOnSaturation();
3535

36-
EXPECT_CALL(*messagingProtocol, createMessage(_, name))
36+
EXPECT_CALL(*messagingProtocol, createMessage(_, name, _))
37+
.Times(1)
38+
.RetiresOnSaturation();
39+
}
40+
41+
void willSend(const std::string & topic, const std::string & name, const std::string & message) {
42+
EXPECT_CALL(*mqttProcessor, send(topic, _, false))
43+
.Times(1)
44+
.RetiresOnSaturation();
45+
46+
EXPECT_CALL(*messagingProtocol, createMessage(_, name, message))
3747
.Times(1)
3848
.RetiresOnSaturation();
3949
}
@@ -70,27 +80,48 @@ namespace {
7080
.RetiresOnSaturation();
7181
}
7282

73-
void installWillFail()
83+
void installSetupWillFail()
7484
{
7585
EXPECT_CALL(*installerAgent, installBundle(_))
7686
.WillOnce(Return(sua::TechCode::InstallationFailed))
7787
.RetiresOnSaturation();
7888
}
7989

80-
void installWillSucceed()
90+
void installSetupWillSucceed()
8191
{
8292
EXPECT_CALL(*installerAgent, installBundle(_))
8393
.WillOnce(Return(sua::TechCode::OK))
8494
.RetiresOnSaturation();
8595
}
8696

97+
void installStatusWillBeSuccess()
98+
{
99+
EXPECT_CALL(*installerAgent, succeeded())
100+
.WillOnce(Return(true))
101+
.RetiresOnSaturation();
102+
}
103+
87104
void installProgressWillBe(const int value)
88105
{
89106
EXPECT_CALL(*installerAgent, getInstallProgress())
90107
.WillOnce(Return(value))
91108
.RetiresOnSaturation();
92109
}
93110

111+
void installStatusWillBe(const bool value)
112+
{
113+
EXPECT_CALL(*installerAgent, installing())
114+
.WillOnce(Return(value))
115+
.RetiresOnSaturation();
116+
}
117+
118+
void lastErrorWillBe(const std::string & text)
119+
{
120+
EXPECT_CALL(*installerAgent, getLastError())
121+
.WillOnce(Return(text))
122+
.RetiresOnSaturation();
123+
}
124+
94125
sua::Context & ctx() {
95126
return sua.context();
96127
}
@@ -232,7 +263,7 @@ namespace {
232263
ctx().stateMachine->handleEvent(sua::FotaEvent::Start);
233264
}
234265

235-
TEST_F(TestSelfUpdateScenarios, receivesUpdateRequestAndInstallFails_sendsInstallFailed)
266+
TEST_F(TestSelfUpdateScenarios, receivesUpdateRequestAndInstallSetupFails_sendsInstallFailed)
236267
{
237268
willTransitTo("Uninitialized");
238269
currentVersionIs("1.0");
@@ -249,7 +280,8 @@ namespace {
249280
willSend("selfupdate/desiredstatefeedback", "downloaded");
250281

251282
willTransitTo("Installing");
252-
installWillFail();
283+
installSetupWillFail();
284+
lastErrorWillBe("test");
253285
willSend("selfupdate/desiredstatefeedback", "installFailed");
254286

255287
willTransitTo("Failed");
@@ -278,11 +310,14 @@ namespace {
278310
willSend("selfupdate/desiredstatefeedback", "downloaded");
279311

280312
willTransitTo("Installing");
281-
installWillSucceed();
313+
installSetupWillSucceed();
282314
// gmock is checking expecations in reverse order
283-
installProgressWillBe(100);
315+
installStatusWillBe(false); // completed (!installing)
316+
installStatusWillBe(true); // installing
317+
installStatusWillBe(true); // installing
318+
installProgressWillBe(99);
284319
installProgressWillBe(50);
285-
installProgressWillBe(0);
320+
installStatusWillBeSuccess();
286321
willSend("selfupdate/desiredstatefeedback", "installing");
287322
willSend("selfupdate/desiredstatefeedback", "installing");
288323
willSend("selfupdate/desiredstatefeedback", "installed");

0 commit comments

Comments
 (0)