Skip to content

Commit ddbc846

Browse files
author
A. Jesse Jiryu Davis
committed
Don't use multiprocessing in tests on Windows
1 parent d355cee commit ddbc846

File tree

2 files changed

+27
-48
lines changed

2 files changed

+27
-48
lines changed

test/test_gevent.py

Lines changed: 24 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
"""Tests for connection-pooling with greenlets and Gevent"""
1616

1717
import os
18+
import socket
1819
import time
1920
import threading
2021
import unittest
@@ -25,9 +26,11 @@
2526
from test.test_connection import get_connection
2627
from test.utils import delay, force_reclaim_sockets
2728

29+
2830
host = os.environ.get("DB_IP", "localhost")
2931
port = int(os.environ.get("DB_PORT", 27017))
3032

33+
3134
def looplet(greenlets):
3235
"""World's smallest event loop; run until all greenlets are done
3336
"""
@@ -55,39 +58,23 @@ def _test_pool(self, use_greenlets, use_request):
5558
gr1: get results
5659
gr0: get results
5760
"""
58-
NOT_STARTED = 0
59-
SUCCESS = 1
60-
SKIP = 2
61+
if use_greenlets:
62+
try:
63+
from gevent import monkey, Greenlet
64+
except ImportError:
65+
raise SkipTest('gevent not installed')
66+
67+
# Note we don't do patch_thread() or patch_all() - we're
68+
# testing here that patch_thread() is unnecessary for
69+
# the connection pool to work properly.
70+
monkey.patch_socket()
6171

6272
try:
63-
from multiprocessing import Value, Process
64-
except ImportError:
65-
# Python < 2.6
66-
raise SkipTest('No multiprocessing module')
67-
68-
outcome = Value('i', NOT_STARTED)
69-
70-
results = {
71-
'find_fast_result': None,
72-
'find_slow_result': None,
73-
}
74-
75-
# Do test in separate process so patch_socket() doesn't affect all
76-
# subsequent unittests
77-
def do_test():
78-
if use_greenlets:
79-
try:
80-
from gevent import Greenlet
81-
from gevent import monkey
82-
83-
# Note we don't do patch_thread() or patch_all() - we're
84-
# testing here that patch_thread() is unnecessary for
85-
# the connection pool to work properly.
86-
monkey.patch_socket()
87-
except ImportError:
88-
outcome.value = SKIP
89-
return
90-
73+
results = {
74+
'find_fast_result': None,
75+
'find_slow_result': None,
76+
}
77+
9178
cx = get_connection(
9279
use_greenlets=use_greenlets,
9380
auto_start_request=False
@@ -120,8 +107,8 @@ def find_slow():
120107

121108
history.append('find_slow start')
122109

123-
# Javascript function that pauses for half a second
124-
where = delay(0.5)
110+
# Javascript function that pauses
111+
where = delay(2)
125112
results['find_slow_result'] = list(db.test.find(
126113
{'$where': where}
127114
))
@@ -139,7 +126,7 @@ def find_slow():
139126
gr0 = threading.Thread(target=find_slow)
140127
gr1 = threading.Thread(target=find_fast)
141128
gr0.start()
142-
time.sleep(0.1)
129+
time.sleep(.1)
143130
gr1.start()
144131

145132
gr0.join()
@@ -157,20 +144,9 @@ def find_slow():
157144
'find_slow done',
158145
], history)
159146

160-
outcome.value = SUCCESS
161-
162-
proc = Process(target=do_test)
163-
proc.start()
164-
proc.join()
165-
166-
if outcome.value == SKIP:
167-
raise SkipTest('gevent not installed')
168-
169-
self.assertEqual(
170-
SUCCESS,
171-
outcome.value,
172-
'test failed'
173-
)
147+
finally:
148+
# Undo Gevent patching
149+
reload(socket)
174150

175151
def test_threads_pool(self):
176152
# Test the same sequence of calls as the gevent tests to ensure my test

test/test_pooling.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -388,6 +388,9 @@ def loop(pipe):
388388
a._Connection__pool.get_socket((a.host, a.port)))
389389

390390
def test_request_with_fork(self):
391+
if sys.platform == "win32":
392+
raise SkipTest("Can't test forking on Windows")
393+
391394
try:
392395
from multiprocessing import Process, Pipe
393396
except ImportError:

0 commit comments

Comments
 (0)