Skip to content

Commit

Permalink
make test_db_dbspec's thread-leak-protection better, and stop leaking…
Browse files Browse the repository at this point in the history
… threads
  • Loading branch information
Dustin J. Mitchell committed Mar 2, 2010
1 parent 5505f59 commit 9c01344
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
2 changes: 1 addition & 1 deletion buildbot/test/unit/test_db_connector.py
Expand Up @@ -20,7 +20,7 @@ def setUp(self):
def tearDown(self):
self.dbc.stop()
# double-check we haven't left a ThreadPool open
assert len(threading.enumerate()) - self.start_thdcount < 2
assert len(threading.enumerate()) - self.start_thdcount < 1

def test_quoteq_format(self):
self.dbc.paramstyle = "format" # override default
Expand Down
10 changes: 7 additions & 3 deletions buildbot/test/unit/test_db_dbspec.py
Expand Up @@ -131,13 +131,14 @@ class DBSpec_methods(unittest.TestCase):
def setUp(self):
self.spec = dbspec.DBSpec.from_url("sqlite://")
self.pools = []
self.start_thdcount = len(threading.enumerate())

def tearDown(self):
# be careful to stop all pools
for pool in self.pools:
pool.stop()
pool.close()
# double-check we haven't left a ThreadPool open
assert len(threading.enumerate()) < 4
assert len(threading.enumerate()) - self.start_thdcount < 1

# track a pool that must be closed
def trackPool(self, pool):
Expand All @@ -155,4 +156,7 @@ def test_get_sync_connection_has_cursor(self):
self.assertTrue(hasattr(self.spec.get_sync_connection(), 'cursor'))

def test_get_async_connection_pool_has_runInteraction(self):
self.assertTrue(hasattr(self.spec.get_async_connection_pool(), 'runInteraction'))
pool = self.spec.get_async_connection_pool()
self.trackPool(pool)
pool.start()
self.assertTrue(hasattr(pool, 'runInteraction'))

0 comments on commit 9c01344

Please sign in to comment.