Skip to content

Commit e1bde1b

Browse files
author
A. Jesse Jiryu Davis
committed
More rational and reliable test_max_pool_size, especially with Gevent
1 parent 97385ca commit e1bde1b

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

test/test_pooling_base.py

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
import thread
2323
import threading
2424
import time
25-
import bson
2625

2726
sys.path[0:0] = [""]
2827

@@ -47,7 +46,7 @@
4746

4847
try:
4948
import gevent
50-
from gevent import Greenlet, monkey
49+
from gevent import Greenlet, monkey, hub
5150
has_gevent = True
5251
except ImportError:
5352
has_gevent = False
@@ -680,15 +679,19 @@ def _test_max_pool_size(self, start_request, end_request):
680679
for t in threads:
681680
self.assertTrue(t.passed)
682681

683-
cx_pool = c._Connection__pool
684-
nsock = len(cx_pool.sockets)
682+
# Socket-reclamation doesn't work in Jython
683+
if not sys.platform.startswith('java'):
684+
cx_pool = c._Connection__pool
685+
nsock = len(cx_pool.sockets)
685686

686-
# Socket-reclamation depends on timely garbage-collection
687-
if 'PyPy' in sys.version:
688-
import gc
689-
gc.collect()
687+
# Socket-reclamation depends on timely garbage-collection
688+
if 'PyPy' in sys.version:
689+
gc.collect()
690+
691+
if self.use_greenlets:
692+
# Wait for Greenlet.link() callbacks to execute
693+
hub.get_hub().shutdown()
690694

691-
if not sys.platform.startswith('java'):
692695
self.assertEqual(4, len(cx_pool.sockets))
693696

694697
def test_max_pool_size(self):

0 commit comments

Comments
 (0)