From 3e4d5288593cd7974a3df514e1af8eebcfe96097 Mon Sep 17 00:00:00 2001 From: James Turner Date: Mon, 9 Mar 2020 15:00:13 +0000 Subject: [PATCH] Additional install / download failure test Ensure we can install again on a previously failed URL. --- simgear/io/untar.cxx | 8 +++-- simgear/package/CatalogTest.cxx | 32 ++++++++++++++---- .../package/catalogTest1/b744/b747-400.xml | 7 ++++ simgear/package/catalogTest1/b747.tar.gz | Bin 0 -> 231 bytes simgear/package/catalogTest1/catalog.xml | 4 +-- 5 files changed, 40 insertions(+), 11 deletions(-) create mode 100644 simgear/package/catalogTest1/b744/b747-400.xml create mode 100644 simgear/package/catalogTest1/b747.tar.gz diff --git a/simgear/io/untar.cxx b/simgear/io/untar.cxx index cc70c62f..4002b61b 100644 --- a/simgear/io/untar.cxx +++ b/simgear/io/untar.cxx @@ -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 } diff --git a/simgear/package/CatalogTest.cxx b/simgear/package/CatalogTest.cxx index d901c68f..6dae43f7 100644 --- a/simgear/package/CatalogTest.cxx +++ b/simgear/package/CatalogTest.cxx @@ -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!"); diff --git a/simgear/package/catalogTest1/b744/b747-400.xml b/simgear/package/catalogTest1/b744/b747-400.xml new file mode 100644 index 00000000..a23281ff --- /dev/null +++ b/simgear/package/catalogTest1/b744/b747-400.xml @@ -0,0 +1,7 @@ + + + + + Boeing 747-400 + + diff --git a/simgear/package/catalogTest1/b747.tar.gz b/simgear/package/catalogTest1/b747.tar.gz new file mode 100644 index 0000000000000000000000000000000000000000..ed8e6f1c3a27244447517f4ab22d7e6209b0403c GIT binary patch literal 231 zcmV;8vk&`40J`*iM}MX_OFoGB1dzstN{`SH(hHbp)uCC5fseNq|H`$posI`x^N0 zVdJ=!LmM9EaoTS8AU@t>(mz7e`_F@V5r~Vg_Bg{C{2o$>`~DLzPX4Qc{Vxl`1aO94 ze(}%!*Gu*sK8^FXJH2MKz-(Eksb0J8Y+U$WSs&^YKzrNv%CmRlx6Yme7u0W^v8O$Z h|3~LPV|`UVl4 - a94ca5704f305b90767f40617d194ed6 - + 4d3f7417d74f811aa20ccc4f35673d20 + http://localhost:2000/catalogTest1/b747.tar.gz