From: James Turner Date: Wed, 20 Apr 2016 09:58:35 +0000 (+0200) Subject: Catalog refresh / package updating test. X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=46ed4b2f7922fe1d227ad8a0da17daa4626906a7;p=simgear.git Catalog refresh / package updating test. --- diff --git a/simgear/package/CatalogTest.cxx b/simgear/package/CatalogTest.cxx index 7e1b275c..216e4522 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; class TestPackageChannel : public TestServerChannel { @@ -68,11 +69,20 @@ public: virtual void processRequestHeaders() { state = STATE_IDLE; - SGPath localPath(global_serverFilesRoot); + + + if (path == "/catalogTest1/catalog.xml") { + if (global_catalogVersion > 0) { + std::stringstream ss; + ss << "/catalogTest1/catalog-v" << global_catalogVersion << ".xml"; + path = ss.str(); + } + } + localPath.append(path); - //SG_LOG(SG_IO, SG_INFO, "local path is:" << localPath.str()); + // SG_LOG(SG_IO, SG_INFO, "local path is:" << localPath.str()); if (localPath.exists()) { std::string content = readFileIntoString(localPath); @@ -119,7 +129,7 @@ int parseTest() VERIFY(cat.valid()); COMPARE(cat->id(), "org.flightgear.test.catalog1"); - COMPARE(cat->url(), "http://download.flightgear.org/catalog1/catalog.xml"); + COMPARE(cat->url(), "http://localhost:2000/catalogTest1/catalog.xml"); COMPARE(cat->description(), "First test catalog"); // check the packages too @@ -318,10 +328,79 @@ void testRemoveCatalog(HTTP::Client* cl) COMPARE(c, pkg::CatalogRef()); } -void testRefreshCatalog() +template +bool contains(const std::vector& vec, const T& item) +{ + typename std::vector::const_iterator it = std::find(vec.begin(), vec.end(), item); + return (it != vec.end()); +} + +void testRefreshCatalog(HTTP::Client* cl) { + SGPath rootPath(simgear::Dir::current().path()); + rootPath.append("pkg_catalog_refresh_update"); + simgear::Dir pd(rootPath); + pd.removeChildren(); + + pkg::RootRef root(new pkg::Root(rootPath, "8.1.2")); + root->setHTTPClient(cl); + + { + pkg::CatalogRef c = pkg::Catalog::createFromUrl(root.ptr(), "http://localhost:2000/catalogTest1/catalog.xml"); + waitForUpdateComplete(cl, root); + } + + { + pkg::PackageRef p1 = root->getPackageById("org.flightgear.test.catalog1.c172p"); + pkg::InstallRef ins = p1->install(); + + pkg::PackageRef p2 = root->getPackageById("org.flightgear.test.catalog1.alpha"); + pkg::InstallRef ins2 = p2->install(); - // check for pending updates + waitForUpdateComplete(cl, root); + + VERIFY(p1->isInstalled()); + VERIFY(p2->isInstalled()); + } + + VERIFY(root->packagesNeedingUpdate().empty()); + + global_catalogVersion = 2; + + VERIFY(!cl->hasActiveRequests()); + root->refresh(); + + // should be a no-op due to catalog age testing + VERIFY(!cl->hasActiveRequests()); + + // force it this time + root->refresh(true); + VERIFY(cl->hasActiveRequests()); + waitForUpdateComplete(cl, root); + + pkg::CatalogRef c = root->getCatalogById("org.flightgear.test.catalog1"); + COMPARE(c->ageInSeconds(), 0); + + VERIFY(root->getPackageById("dc3") != pkg::PackageRef()); + COMPARE(root->packagesNeedingUpdate().size(), 2); + + pkg::PackageList needingUpdate = root->packagesNeedingUpdate(); + VERIFY(contains(needingUpdate, root->getPackageById("common-sounds"))); + VERIFY(contains(needingUpdate, root->getPackageById("org.flightgear.test.catalog1.alpha"))); + + pkg::InstallRef ins = root->getPackageById("alpha")->existingInstall(); + VERIFY(ins->hasUpdate()); + + for (pkg::PackageList::const_iterator it = needingUpdate.begin(); + it != needingUpdate.end(); ++it) + { + root->scheduleToUpdate((*it)->existingInstall()); + } + + waitForUpdateComplete(cl, root); + + VERIFY(root->packagesNeedingUpdate().empty()); + COMPARE(root->getPackageById("common-sounds")->revision(), 11); } @@ -343,7 +422,9 @@ int main(int argc, char* argv[]) testUninstall(&cl); testRemoveCatalog(&cl); - + + testRefreshCatalog(&cl); + std::cout << "Successfully passed all tests!" << std::endl; return EXIT_SUCCESS; } diff --git a/simgear/package/Root.cxx b/simgear/package/Root.cxx index 78507653..d6460ace 100644 --- a/simgear/package/Root.cxx +++ b/simgear/package/Root.cxx @@ -379,12 +379,15 @@ void Root::refresh(bool aForce) { bool didStartAny = false; - // copy all candidate ctalogs to a seperate list, since refreshing + // copy all candidate catalogs to a seperate list, since refreshing // can modify both the main collection and/or the disabled list CatalogList toRefresh; CatalogDict::iterator it = d->catalogs.begin(); for (; it != d->catalogs.end(); ++it) { - toRefresh.push_back(it->second); + int age = it->second->ageInSeconds(); + if (aForce || (age > maxAgeSeconds())) { + toRefresh.push_back(it->second); + } } toRefresh.insert(toRefresh.end(), d->disabledCatalogs.begin(), diff --git a/simgear/package/catalogTest1/catalog-v2.xml b/simgear/package/catalogTest1/catalog-v2.xml new file mode 100644 index 00000000..6749b000 --- /dev/null +++ b/simgear/package/catalogTest1/catalog-v2.xml @@ -0,0 +1,92 @@ + + + + org.flightgear.test.catalog1 + First test catalog + http://localhost:2000/catalogTest1/catalog.xml + 4 + + 8.1.* + 8.0.0 + 8.2.0 + + + alpha + Alpha package + 9 + 593 + + a469c4b837f0521db48616cfe65ac1ea + http://localhost:2000/catalogTest1/alpha.zip + + alpha + + + + c172p + Cessna 172-P + c172p + A plane made by Cessna + 42 + 860 + + cessna + ga + piston + ifr + + + 3 + 4 + 5 + 4 + + + + + org.flightgear.test.catalog1.common-sounds + 10 + + + + c172p-2d-panel + C172 with 2d panel only + + + + c172p-floats + C172 with floats + + + + c172p-skis + C172 with skis + + + ec0e2ffdf98d6a5c05c77445e5447ff5 + http://localhost:2000/catalogTest1/c172p.zip + + + + + common-sounds + Common sound files for test catalog aircraft + 11 + sounds + http://localhost:2000/catalogTest1/common-sounds.zip + 360 + acf9eb89cf396eb42f8823d9cdf17584 + + + + dc3 + DC-3 + 9 + 593 + + a469c4b837f0521db48616cfe65ac1ea + http://localhost:2000/catalogTest1/alpha.zip + + dc3 + + diff --git a/simgear/package/catalogTest1/catalog.xml b/simgear/package/catalogTest1/catalog.xml index 94760688..6f0504f6 100644 --- a/simgear/package/catalogTest1/catalog.xml +++ b/simgear/package/catalogTest1/catalog.xml @@ -3,7 +3,7 @@ org.flightgear.test.catalog1 First test catalog - http://download.flightgear.org/catalog1/catalog.xml + http://localhost:2000/catalogTest1/catalog.xml 4 8.1.*