|
19 | 19 |
|
20 | 20 | sys.path[0:0] = [""] |
21 | 21 |
|
22 | | -from test import unittest |
| 22 | +from test import IntegrationTest, unittest |
23 | 23 | from test.unified_format import generate_test_classes |
24 | 24 |
|
| 25 | +import pymongo |
| 26 | +from pymongo import _csot |
| 27 | + |
25 | 28 | # Location of JSON test specifications. |
26 | 29 | TEST_PATH = os.path.join(os.path.dirname(os.path.realpath(__file__)), "csot") |
27 | 30 |
|
28 | 31 | # Generate unified tests. |
29 | 32 | globals().update(generate_test_classes(TEST_PATH, module=__name__)) |
30 | 33 |
|
| 34 | + |
| 35 | +class TestCSOT(IntegrationTest): |
| 36 | + def test_timeout_nested(self): |
| 37 | + coll = self.db.coll |
| 38 | + self.assertEqual(_csot.get_timeout(), None) |
| 39 | + self.assertEqual(_csot.get_deadline(), float("inf")) |
| 40 | + self.assertEqual(_csot.get_rtt(), 0.0) |
| 41 | + with pymongo.timeout(10): |
| 42 | + coll.find_one() |
| 43 | + self.assertEqual(_csot.get_timeout(), 10) |
| 44 | + deadline_10 = _csot.get_deadline() |
| 45 | + |
| 46 | + with pymongo.timeout(15): |
| 47 | + coll.find_one() |
| 48 | + self.assertEqual(_csot.get_timeout(), 15) |
| 49 | + self.assertGreater(_csot.get_deadline(), deadline_10) |
| 50 | + |
| 51 | + # Should be reset to previous values |
| 52 | + self.assertEqual(_csot.get_timeout(), 10) |
| 53 | + self.assertEqual(_csot.get_deadline(), deadline_10) |
| 54 | + coll.find_one() |
| 55 | + |
| 56 | + with pymongo.timeout(5): |
| 57 | + coll.find_one() |
| 58 | + self.assertEqual(_csot.get_timeout(), 5) |
| 59 | + self.assertLess(_csot.get_deadline(), deadline_10) |
| 60 | + |
| 61 | + # Should be reset to previous values |
| 62 | + self.assertEqual(_csot.get_timeout(), 10) |
| 63 | + self.assertEqual(_csot.get_deadline(), deadline_10) |
| 64 | + coll.find_one() |
| 65 | + |
| 66 | + # Should be reset to previous values |
| 67 | + self.assertEqual(_csot.get_timeout(), None) |
| 68 | + self.assertEqual(_csot.get_deadline(), float("inf")) |
| 69 | + self.assertEqual(_csot.get_rtt(), 0.0) |
| 70 | + |
| 71 | + |
31 | 72 | if __name__ == "__main__": |
32 | 73 | unittest.main() |
0 commit comments