test for save/restoring locks and also unlocking
authorJosef Reidinger <jreidinger@suse.cz>
Fri, 11 Apr 2008 15:16:01 +0000 (15:16 +0000)
committerJosef Reidinger <jreidinger@suse.cz>
Fri, 11 Apr 2008 15:16:01 +0000 (15:16 +0000)
tests/zypp/Locks_test.cc
tests/zypp/data/Locks/locks
zypp/Locks.cc

index b27a443..6f10a51 100644 (file)
@@ -79,3 +79,43 @@ BOOST_AUTO_TEST_CASE(locks_2)
     BOOST_CHECK(isLocked(*it));
   }
 }
+
+BOOST_AUTO_TEST_CASE(locks_save_load)
+{
+  cout << "****save/load****"  << endl;
+  Pathname src(TESTS_SRC_DIR);
+    src += "zypp/data/Locks/locks";
+  Locks::instance().loadLocks(src);
+  PoolQuery q;
+  q.addString("zypper");
+  for_(it,q.begin(),q.end())
+  {
+    BOOST_CHECK(isLocked(*it));
+  }
+  Locks::instance().unlock(q);
+  for_(it,q.begin(),q.end())
+  {
+    BOOST_CHECK(!isLocked(*it));
+  }
+#if 1 
+  filesystem::TmpFile testfile;
+  //Pathname testfile(TESTS_SRC_DIR);
+    //  testfile += "/zypp/data/Locks/testlocks";
+  Locks::instance().saveLocks(testfile);
+  Locks::instance().loadLocks(testfile);
+  //still locked
+  for_(it,q.begin(),q.end())
+  {
+    BOOST_CHECK(isLocked(*it));
+  }
+  Locks::instance().unlock(q); //need twice because finded from previous test
+  Locks::instance().saveLocks(testfile);
+  Locks::instance().loadLocks(testfile);
+  //now unlocked - first unlock remove indetical lock from previous test
+  //and next unlock remove lock from lockfile
+  for_(it,q.begin(),q.end())
+  {
+    BOOST_CHECK(!isLocked(*it));
+  }
+#endif
+}
index 9e3fcf2..873fa82 100644 (file)
@@ -1,5 +1 @@
-#repo cannot be tested due to possibly missing allias
-kind: patch
-
-string: kde
-attribute: pattern
+global_string: zypper
index ecc3e77..b734851 100644 (file)
 #include "zypp/PoolQueryUtil.tcc"
 #include "zypp/ZYppCallbacks.h"
 #include "zypp/sat/SolvAttr.h"
+#include "zypp/PathInfo.h"
 
 #undef ZYPP_BASE_LOGGER_LOGGROUP
 #define ZYPP_BASE_LOGGER_LOGGROUP "locks"
 
 #include "zypp/Locks.h"
-#include "zypp/PathInfo.h"
 
 using namespace std;
 using namespace zypp;
@@ -100,10 +100,12 @@ void Locks::addLock( const PoolQuery& query )
     _pimpl->toRemove.end(), query);
   if ( i != _pimpl->toRemove.end() )
   {
+    DBG << "query removed from toRemove" << endl;
     _pimpl->toRemove.erase(i);
   }
   else
   {
+    DBG << "query added as new" << endl;
     _pimpl->toAdd.push_back( query );
   }
 }
@@ -131,10 +133,12 @@ void Locks::unlock( const PoolQuery& query )
     _pimpl->toAdd.end(), query);
   if ( i != _pimpl->toAdd.end() )
   {
+    DBG << "query removed from added" << endl;
     _pimpl->toAdd.erase(i);
   }
   else
   {
+    DBG << "needed remove some old lock" << endl;
     _pimpl->toRemove.push_back( query );
   }
 }
@@ -264,8 +268,11 @@ public:
   {
     if (aborted())
       return false;
-    if( q==query ) //identical
+    if( q==query )
+    {//identical
+      DBG << "identical queries" << endl;
       return true;
+    }
 
     SavingLocksReport::ConflictState cs;
     switch( contains(q,solvs) )
@@ -284,10 +291,13 @@ public:
     {
     case SavingLocksReport::ABORT:
       aborted_ = true;
+      DBG << "abort merging" << endl;
       return false;
     case SavingLocksReport::DELETE:
+      DBG << "force delete" << endl;
       return true;
     case SavingLocksReport::IGNORE:
+      DBG << "skip lock" << endl;
       return false;
     }
     WAR << "should not reached, some state is missing" << endl;
@@ -322,6 +332,7 @@ void Locks::saveLocks( const Pathname& file )
     report->finish(SavingLocksReport::ABORTED);
     return;
   }
+  DBG << "writed "<< _pimpl->locks.size() << "locks" << endl;
   writePoolQueriesToFile( file, _pimpl->locks.begin(), _pimpl->locks.end() );
   report->finish(SavingLocksReport::NO_ERROR);
 }