Skip to content

Commit 2f818f7

Browse files
committed
Merge pull request mongodb#100 from ajdavis/test-interrupt-in-jython
Test refactoring, skip a test that won't work in Jython
2 parents 94cd798 + 13d009e commit 2f818f7

File tree

1 file changed

+10
-13
lines changed

1 file changed

+10
-13
lines changed

test/test_connection.py

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
InvalidURI,
3737
OperationFailure)
3838
from test import version
39-
from test.utils import server_is_master_with_slave
39+
from test.utils import server_is_master_with_slave, delay
4040

4141

4242
def get_connection(*args, **kwargs):
@@ -383,14 +383,7 @@ def test_network_timeout(self):
383383
no_timeout.pymongo_test.test.insert({"x": 1}, safe=True)
384384

385385
# A $where clause that takes a second longer than the timeout
386-
where_func = """function (doc) {
387-
var d = new Date().getTime() + (%f + 1) * 1000;;
388-
var x = new Date().getTime();
389-
while (x < d) {
390-
x = new Date().getTime();
391-
}
392-
return true;
393-
}""" % timeout_sec
386+
where_func = delay(timeout_sec+1)
394387

395388
def get_x(db):
396389
return db.test.find().where(where_func).next()["x"]
@@ -489,16 +482,20 @@ def test_contextlib(self):
489482
self.assertEqual(0, len(connection._Connection__pool.sockets))
490483

491484
def test_interrupt_signal(self):
485+
if sys.platform.startswith('java'):
486+
# We can't figure out how to raise an exception on a thread that's
487+
# blocked on a socket, whether that's the main thread or a worker,
488+
# without simply killing the whole thread in Jython. This suggests
489+
# PYTHON-294 can't actually occur in Jython.
490+
raise SkipTest("Can't test interrupts in Jython")
491+
492492
# Test fix for PYTHON-294 -- make sure Connection closes its
493493
# socket if it gets an interrupt while waiting to recv() from it.
494494
c = get_connection()
495495
db = c.pymongo_test
496496

497497
# A $where clause which takes 1.5 sec to execute
498-
where = '''function() {
499-
var d = new Date((new Date()).getTime() + 1.5 * 1000);
500-
while (d > (new Date())) { }; return true;
501-
}'''
498+
where = delay(1.5)
502499

503500
# Need exactly 1 document so find() will execute its $where clause once
504501
db.drop_collection('foo')

0 commit comments

Comments
 (0)