def get_connection(self):
recycle = False
+
+ # NOTE: the various comparisons here are assuming that measurable time
+ # passes between these state changes. however, time.time() is not
+ # guaranteed to have sub-second precision. comparisons of
+ # "invalidation time" to "starttime" should perhaps use >= so that the
+ # state change can take place assuming no measurable time has passed,
+ # however this does not guarantee correct behavior here as if time
+ # continues to not pass, it will try to reconnect repeatedly until
+ # these timestamps diverge, so in that sense using > is safer. Per
+ # https://stackoverflow.com/a/1938096/34549, Windows time.time() may be
+ # within 16 milliseconds accuracy, so unit tests for connection
+ # invalidation need a sleep of at least this long between initial start
+ # time and invalidation for the logic below to work reliably.
if self.connection is None:
self.info.clear()
self.__connect()
is_(c2.connection, c_ref())
c2_rec = c2._connection_record
+
+ # ensure pool invalidate time will be later than starttime
+ # for ConnectionRecord objects above
+ time.sleep(0.1)
c2.invalidate(soft=True)
+
is_(c2_rec.connection, c2.connection)
c2.close()
- time.sleep(0.5)
+
c3 = p.connect()
is_not_(c3.connection, c_ref())
is_(c3._connection_record, c2_rec)
time.sleep(1.5)
self._assert_cleanup_on_pooled_reconnect(dbapi, p)
+ @testing.requires.timing_intensive
def test_connect_handler_not_called_for_recycled(self):
"""test [ticket:3497]"""
dbapi.shutdown(True)
+ # ensure pool invalidate time will be later than starttime
+ # for ConnectionRecord objects above
+ time.sleep(0.1)
+
bad = p.connect()
p._invalidate(bad)
bad.close()
[call.connect(ANY, ANY), call.checkout(ANY, ANY, ANY)],
)
+ @testing.requires.timing_intensive
def test_connect_checkout_handler_always_gets_info(self):
"""test [ticket:3497]"""
dbapi.shutdown(True)
+ # ensure pool invalidate time will be later than starttime
+ # for ConnectionRecord objects above
+ time.sleep(0.1)
+
bad = p.connect()
p._invalidate(bad)
bad.close()