Additional install / download failure test

Ensure we can install again on a previously failed URL.
This commit is contained in:
James Turner
2020-03-09 15:00:13 +00:00
parent b847f57382
commit 3e4d528859
5 changed files with 40 additions and 11 deletions

View File

@@ -634,7 +634,7 @@ void ArchiveExtractor::extractBytes(const uint8_t* bytes, size_t count)
d.reset(new ZipExtractorPrivate(this));
}
else {
SG_LOG(SG_IO, SG_ALERT, "Invcalid archive type");
SG_LOG(SG_IO, SG_ALERT, "Invalid archive type");
_invalidDataType = true;
return;
}
@@ -724,8 +724,10 @@ ArchiveExtractor::DetermineResult ArchiveExtractor::isTarData(const uint8_t* byt
}
int result = inflate(&z, Z_SYNC_FLUSH);
if (result != Z_OK) {
SG_LOG(SG_IO, SG_WARN, "inflate failed:" << result);
if ((result == Z_OK) || (result == Z_STREAM_END)) {
// all good
} else {
SG_LOG(SG_IO, SG_WARN, "isTarData: Zlib inflate failed:" << result);
inflateEnd(&z);
return Invalid; // not tar data
}

View File

@@ -60,6 +60,7 @@ std::string readFileIntoString(const SGPath& path)
SGPath global_serverFilesRoot;
unsigned int global_catalogVersion = 0;
bool global_failRequests = false;
bool global_fail747Request = true;
class TestPackageChannel : public TestServerChannel
{
@@ -97,8 +98,12 @@ public:
}
if (path == "/catalogTest1/b747.tar.gz") {
sendErrorResponse(403, false, "Bad URL");
return;
if (global_fail747Request) {
sendErrorResponse(403, false, "Bad URL");
return;
} else {
path = "/catalogTest1/b747.tar.gz"; // valid path
}
}
localPath.append(path);
@@ -1083,7 +1088,8 @@ void updateInvalidToInvalid(HTTP::Client* cl)
void testInstallBadPackage(HTTP::Client* cl)
{
global_catalogVersion = 0;
global_fail747Request = true;
SGPath rootPath(simgear::Dir::current().path());
rootPath.append("pkg_install_bad_pkg");
simgear::Dir pd(rootPath);
@@ -1113,15 +1119,29 @@ void testInstallBadPackage(HTTP::Client* cl)
SG_VERIFY(p1->existingInstall() == ins);
SG_CHECK_EQUAL(ins->status(), pkg::Delegate::FAIL_DOWNLOAD);
SG_CHECK_EQUAL(ins->path(), rootPath / "org.flightgear.test.catalog1" / "Aircraft" / "b744");
}
// now retry, it should work
global_fail747Request = false;
auto ins2 = p1->install();
SG_CHECK_EQUAL(ins2, p1->existingInstall());
root->scheduleToUpdate(ins2);
SG_VERIFY(ins2->isQueued());
didFail = false;
waitForUpdateComplete(cl, root);
SG_VERIFY(p1->isInstalled());
SG_VERIFY(!didFail);
SG_CHECK_EQUAL(ins->status(), pkg::Delegate::STATUS_SUCCESS);
SG_CHECK_EQUAL(ins->path(), rootPath / "org.flightgear.test.catalog1" / "Aircraft" / "b744");
}
int main(int argc, char* argv[])
{
// sglog().setLogLevels( SG_ALL, SG_DEBUG );
HTTP::Client cl;
cl.setMaxConnections(1);
cl.setMaxConnections(1);
global_serverFilesRoot = SGPath(SRC_DIR);
@@ -1156,7 +1176,7 @@ int main(int argc, char* argv[])
removeInvalidCatalog(&cl);
testVersionMigrateToId(&cl);
testInstallBadPackage(&cl);
SG_LOG(SG_GENERAL, SG_INFO, "Successfully passed all tests!");

View File

@@ -0,0 +1,7 @@
<?xml version="1.0"?>
<PropertyList>
<sim>
<description>Boeing 747-400</description>
</sim>
</PropertyList>

Binary file not shown.

View File

@@ -215,8 +215,8 @@
<cockpit type="int">4</cockpit>
</rating>
<md5>a94ca5704f305b90767f40617d194ed6</md5>
<!-- this URL will fail, on purpose -->
<md5>4d3f7417d74f811aa20ccc4f35673d20</md5>
<!-- this URL will sometimes fail, on purpose -->
<url>http://localhost:2000/catalogTest1/b747.tar.gz</url>
</package>