Author: wyoung
Date: Fri Feb 29 07:25:03 2008
New Revision: 2225

URL: http://svn.gna.org/viewcvs/mysqlpp?rev=2225&view=rev
Log:
Reworked the part of the ConnectionPool unit test that ensures that
connections expire when they get too old: the test assumed that the
implementation of ::operator new() doesn't reuse pointers when you
allocate an object, deallocate it, and then allocate an object of the
exact same type.  On RHEL3, at least, this does happen, and rightfully
so; why not re-use the space made in the heap by the previous
allocation?  We now test for object uniqueness in a more robust way.

Modified:
    trunk/test/cpool.cpp

Modified: trunk/test/cpool.cpp
URL: 
http://svn.gna.org/viewcvs/mysqlpp/trunk/test/cpool.cpp?rev=2225&r1=2224&r2=2225&view=diff
==============================================================================
--- trunk/test/cpool.cpp (original)
+++ trunk/test/cpool.cpp Fri Feb 29 07:25:03 2008
@@ -24,28 +24,40 @@
  USA
 ***********************************************************************/
 
-#include <mysql++.h>
+#include <cpool.h>
+#include <connection.h>
 
 #include <iostream>
 
 #if defined(MYSQLPP_PLATFORM_WINDOWS)
 #      define SLEEP(n) Sleep((n) * 1000)
 #else
+#      include <unistd.h>
 #      define SLEEP(n) sleep(n)
 #endif
 
 using namespace std;
 
-
-class TCPConnectionPool : public mysqlpp::ConnectionPool
+class TestConnection : public mysqlpp::Connection
 {
 public:
-    ~TCPConnectionPool() { clear(); }
+       TestConnection() : itime_(time(0)) { }
+       time_t instantiation_time() const { return itime_; }
+
+private:
+       time_t itime_;
+};
+
+
+class TestConnectionPool : public mysqlpp::ConnectionPool
+{
+public:
+    ~TestConnectionPool() { clear(); }
 
     unsigned int max_idle_time() { return 1; }
 
 private:
-    mysqlpp::TCPConnection* create() { return new mysqlpp::TCPConnection(); }
+    TestConnection* create() { return new TestConnection; }
     void destroy(mysqlpp::Connection* cp) { delete cp; }
 };
 
@@ -53,7 +65,7 @@
 int
 main()
 {
-       TCPConnectionPool pool;
+       TestConnectionPool pool;
 
        mysqlpp::Connection* conn1 = pool.grab();
        mysqlpp::Connection* conn2 = pool.grab();
@@ -69,10 +81,14 @@
                return 1;
        }
 
+       time_t itime_c1 = dynamic_cast<TestConnection*>(conn1)->
+                       instantiation_time();
        pool.release(conn1);
        SLEEP(pool.max_idle_time() + 1);
        mysqlpp::Connection* conn4 = pool.grab();
-       if (conn1 == conn4) {
+       time_t itime_c4 = dynamic_cast<TestConnection*>(conn4)->
+                       instantiation_time();
+       if (itime_c1 == itime_c4) {
                cerr << "conn1 should have been destroyed but wasn't!" << endl;
                return 1;
        }


_______________________________________________
Mysqlpp-commits mailing list
[email protected]
https://mail.gna.org/listinfo/mysqlpp-commits

Reply via email to