changeset 138:5c5cd59c991f

fix unit tests if MySQL >= 5.7
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 09 May 2019 11:36:56 +0200
parents 52b3859ee0b7
children e4f1fb4412ea
files MySQL/UnitTests/UnitTestsMain.cpp
diffstat 1 files changed, 15 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/MySQL/UnitTests/UnitTestsMain.cpp	Thu May 09 11:29:17 2019 +0200
+++ b/MySQL/UnitTests/UnitTestsMain.cpp	Thu May 09 11:36:56 2019 +0200
@@ -74,31 +74,36 @@
   ASSERT_TRUE(db1.AcquireAdvisoryLock("mylock"));  // lock counter = 1
 
   // OK, as this is the same connection
-  ASSERT_TRUE(db1.AcquireAdvisoryLock("mylock"));  // lock counter = 1
-  ASSERT_TRUE(db1.ReleaseAdvisoryLock("mylock"));  // lock counter = 0
+  ASSERT_TRUE(db1.AcquireAdvisoryLock("mylock"));
+  // lock counter = 2 if MySQL >= 5.7, or 1 if MySQL < 5.7 (because
+  // acquiring a lock releases all the previously-acquired locks)
+  
+  ASSERT_TRUE(db1.ReleaseAdvisoryLock("mylock"));
+  // lock counter = 1 if MySQL >= 5.7, or 0 if MySQL < 5.7
 
   // Try and release twice the lock
-  ASSERT_FALSE(db1.ReleaseAdvisoryLock("mylock"));  // lock counter = 0
-  ASSERT_TRUE(db1.AcquireAdvisoryLock("mylock"));  // lock counter = 1
+  db1.ReleaseAdvisoryLock("mylock"); // Succeeds iff MySQL >= 5.7
+
+  ASSERT_TRUE(db1.AcquireAdvisoryLock("mylock2"));  // lock counter = 1
 
   {
     OrthancDatabases::MySQLDatabase db2(globalParameters_);
     db2.Open();
 
     // The "db1" is still actively locking
-    ASSERT_FALSE(db2.AcquireAdvisoryLock("mylock"));
+    ASSERT_FALSE(db2.AcquireAdvisoryLock("mylock2"));
 
     // Release the "db1" lock
-    ASSERT_TRUE(db1.ReleaseAdvisoryLock("mylock"));
-    ASSERT_FALSE(db1.ReleaseAdvisoryLock("mylock"));
+    ASSERT_TRUE(db1.ReleaseAdvisoryLock("mylock2"));
+    ASSERT_FALSE(db1.ReleaseAdvisoryLock("mylock2"));
 
     // "db2" can now acquire the lock, but not "db1"
-    ASSERT_TRUE(db2.AcquireAdvisoryLock("mylock"));
-    ASSERT_FALSE(db1.AcquireAdvisoryLock("mylock"));
+    ASSERT_TRUE(db2.AcquireAdvisoryLock("mylock2"));
+    ASSERT_FALSE(db1.AcquireAdvisoryLock("mylock2"));
   }
 
   // "db2" is closed, "db1" can now acquire the lock
-  ASSERT_TRUE(db1.AcquireAdvisoryLock("mylock"));
+  ASSERT_TRUE(db1.AcquireAdvisoryLock("mylock2"));
 }