|
36 | 36 | InvalidURI, |
37 | 37 | OperationFailure) |
38 | 38 | 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 |
40 | 40 |
|
41 | 41 |
|
42 | 42 | def get_connection(*args, **kwargs): |
@@ -383,14 +383,7 @@ def test_network_timeout(self): |
383 | 383 | no_timeout.pymongo_test.test.insert({"x": 1}, safe=True) |
384 | 384 |
|
385 | 385 | # 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) |
394 | 387 |
|
395 | 388 | def get_x(db): |
396 | 389 | return db.test.find().where(where_func).next()["x"] |
@@ -489,16 +482,20 @@ def test_contextlib(self): |
489 | 482 | self.assertEqual(0, len(connection._Connection__pool.sockets)) |
490 | 483 |
|
491 | 484 | 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 | + |
492 | 492 | # Test fix for PYTHON-294 -- make sure Connection closes its |
493 | 493 | # socket if it gets an interrupt while waiting to recv() from it. |
494 | 494 | c = get_connection() |
495 | 495 | db = c.pymongo_test |
496 | 496 |
|
497 | 497 | # 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) |
502 | 499 |
|
503 | 500 | # Need exactly 1 document so find() will execute its $where clause once |
504 | 501 | db.drop_collection('foo') |
|
0 commit comments