| 1176 | assert t < 14, "Not all timeouts were < 14 seconds %r" % timeouts |
| 1177 | |
| 1178 | def _test_overflow(self, thread_count, max_overflow): |
| 1179 | reaper = testing.engines.ConnectionKiller() |
| 1180 | |
| 1181 | dbapi = MockDBAPI() |
| 1182 | mutex = threading.Lock() |
| 1183 | |
| 1184 | def creator(): |
| 1185 | time.sleep(0.05) |
| 1186 | with mutex: |
| 1187 | return dbapi.connect() |
| 1188 | |
| 1189 | p = pool.QueuePool( |
| 1190 | creator=creator, pool_size=3, timeout=2, max_overflow=max_overflow |
| 1191 | ) |
| 1192 | reaper.add_pool(p) |
| 1193 | peaks = [] |
| 1194 | |
| 1195 | def whammy(): |
| 1196 | for i in range(10): |
| 1197 | try: |
| 1198 | con = p.connect() |
| 1199 | time.sleep(0.005) |
| 1200 | peaks.append(p.overflow()) |
| 1201 | con.close() |
| 1202 | del con |
| 1203 | except tsa.exc.TimeoutError: |
| 1204 | pass |
| 1205 | |
| 1206 | threads = [] |
| 1207 | for i in range(thread_count): |
| 1208 | th = threading.Thread(target=whammy) |
| 1209 | th.start() |
| 1210 | threads.append(th) |
| 1211 | for th in threads: |
| 1212 | th.join(join_timeout) |
| 1213 | |
| 1214 | self.assert_(max(peaks) <= max_overflow) |
| 1215 | |
| 1216 | reaper.assert_all_closed() |
| 1217 | |
| 1218 | def test_overflow_reset_on_failed_connect(self): |
| 1219 | dbapi = Mock() |