test that the pool's connections are OK after cleanup() has been called.
(self, strong_refs)
| 2225 | # self._test_cleanup(True) |
| 2226 | |
| 2227 | def _test_cleanup(self, strong_refs): |
| 2228 | """test that the pool's connections are OK after cleanup() has |
| 2229 | been called.""" |
| 2230 | |
| 2231 | dbapi = MockDBAPI() |
| 2232 | |
| 2233 | lock = threading.Lock() |
| 2234 | |
| 2235 | def creator(): |
| 2236 | # the mock iterator isn't threadsafe... |
| 2237 | with lock: |
| 2238 | return dbapi.connect() |
| 2239 | |
| 2240 | p = pool.SingletonThreadPool(creator=creator, pool_size=3) |
| 2241 | |
| 2242 | if strong_refs: |
| 2243 | sr = set() |
| 2244 | |
| 2245 | def _conn(): |
| 2246 | c = p.connect() |
| 2247 | sr.add(c.dbapi_connection) |
| 2248 | return c |
| 2249 | |
| 2250 | else: |
| 2251 | |
| 2252 | def _conn(): |
| 2253 | return p.connect() |
| 2254 | |
| 2255 | def checkout(): |
| 2256 | for x in range(10): |
| 2257 | c = _conn() |
| 2258 | assert c |
| 2259 | c.cursor() |
| 2260 | c.close() |
| 2261 | time.sleep(0.01) |
| 2262 | |
| 2263 | threads = [] |
| 2264 | for i in range(10): |
| 2265 | th = threading.Thread(target=checkout) |
| 2266 | th.start() |
| 2267 | threads.append(th) |
| 2268 | for th in threads: |
| 2269 | th.join(join_timeout) |
| 2270 | |
| 2271 | lp = len(p._all_conns) |
| 2272 | is_true(3 <= lp <= 4) |
| 2273 | |
| 2274 | if strong_refs: |
| 2275 | still_opened = len([c for c in sr if not c.close.call_count]) |
| 2276 | eq_(still_opened, 3) |
| 2277 | |
| 2278 | def test_no_rollback_from_nested_connections(self): |
| 2279 | dbapi = MockDBAPI() |