]> git.mxchange.org Git - simgear.git/commitdiff
Catalog refresh / package updating test.
authorJames Turner <zakalawe@mac.com>
Wed, 20 Apr 2016 09:58:35 +0000 (11:58 +0200)
committerJames Turner <zakalawe@mac.com>
Wed, 20 Apr 2016 09:58:35 +0000 (11:58 +0200)
simgear/package/CatalogTest.cxx
simgear/package/Root.cxx
simgear/package/catalogTest1/catalog-v2.xml [new file with mode: 0644]
simgear/package/catalogTest1/catalog.xml

index 7e1b275c095c7e81e0ae99fc12a2b84cae0c13bf..216e4522f644682492f8cfdde639fd095155986a 100644 (file)
@@ -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 <class T>
+bool contains(const std::vector<T>& vec, const T& item)
+{
+    typename std::vector<T>::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;
 }
index 785076530feed194e611c75e4edbe830d684decc..d6460ace9aa921d7fd6bb0485ab86c258b0a8c9c 100644 (file)
@@ -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 (file)
index 0000000..6749b00
--- /dev/null
@@ -0,0 +1,92 @@
+<?xml version="1.0"?>
+
+<PropertyList>
+    <id>org.flightgear.test.catalog1</id>
+    <description>First test catalog</description>
+    <url>http://localhost:2000/catalogTest1/catalog.xml</url>
+    <catalog-version>4</catalog-version>
+
+    <version>8.1.*</version>
+    <version>8.0.0</version>
+    <version>8.2.0</version>
+
+    <package>
+        <id>alpha</id>
+        <name>Alpha package</name>
+        <revision type="int">9</revision>
+        <file-size-bytes type="int">593</file-size-bytes>
+
+        <md5>a469c4b837f0521db48616cfe65ac1ea</md5>
+        <url>http://localhost:2000/catalogTest1/alpha.zip</url>
+
+        <dir>alpha</dir>
+    </package>
+
+    <package>
+        <id>c172p</id>
+        <name>Cessna 172-P</name>
+        <dir>c172p</dir>
+        <description>A plane made by Cessna</description>
+        <revision type="int">42</revision>
+        <file-size-bytes type="int">860</file-size-bytes>
+
+        <tag>cessna</tag>
+        <tag>ga</tag>
+        <tag>piston</tag>
+        <tag>ifr</tag>
+
+        <rating>
+          <FDM type="int">3</FDM>
+          <systems type="int">4</systems>
+          <model type="int">5</model>
+          <cockpit type="int">4</cockpit>
+        </rating>
+
+        <!-- local dependency -->
+        <depends>
+            <id>org.flightgear.test.catalog1.common-sounds</id>
+            <revision>10</revision>
+        </depends>
+
+        <variant>
+            <id>c172p-2d-panel</id>
+            <name>C172 with 2d panel only</name>
+        </variant>
+
+        <variant>
+            <id>c172p-floats</id>
+            <name>C172 with floats</name>
+        </variant>
+
+        <variant>
+            <id>c172p-skis</id>
+            <name>C172 with skis</name>
+        </variant>
+
+        <md5>ec0e2ffdf98d6a5c05c77445e5447ff5</md5>
+        <url>http://localhost:2000/catalogTest1/c172p.zip</url>
+
+    </package>
+
+    <package>
+        <id>common-sounds</id>
+        <name>Common sound files for test catalog aircraft</name>
+        <revision>11</revision>
+        <dir>sounds</dir>
+        <url>http://localhost:2000/catalogTest1/common-sounds.zip</url>
+        <file-size-bytes>360</file-size-bytes>
+        <md5>acf9eb89cf396eb42f8823d9cdf17584</md5>
+    </package>
+
+    <package>
+        <id>dc3</id>
+        <name>DC-3</name>
+        <revision type="int">9</revision>
+        <file-size-bytes type="int">593</file-size-bytes>
+
+        <md5>a469c4b837f0521db48616cfe65ac1ea</md5>
+        <url>http://localhost:2000/catalogTest1/alpha.zip</url>
+
+        <dir>dc3</dir>
+    </package>
+</PropertyList>
index 947606883660a00c386497f9cccc16891c3e8535..6f0504f6a4bf2fdfaa3f5973e1c469598891fbf3 100644 (file)
@@ -3,7 +3,7 @@
 <PropertyList>
     <id>org.flightgear.test.catalog1</id>
     <description>First test catalog</description>
-    <url>http://download.flightgear.org/catalog1/catalog.xml</url>
+    <url>http://localhost:2000/catalogTest1/catalog.xml</url>
     <catalog-version>4</catalog-version>
 
     <version>8.1.*</version>