|
| 1 | +# Copyright 2014 MongoDB, Inc. |
| 2 | +# |
| 3 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +# you may not use this file except in compliance with the License. |
| 5 | +# You may obtain a copy of the License at |
| 6 | +# |
| 7 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +# |
| 9 | +# Unless required by applicable law or agreed to in writing, software |
| 10 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +# See the License for the specific language governing permissions and |
| 13 | +# limitations under the License. |
| 14 | + |
| 15 | +"""Test the monitor module.""" |
| 16 | + |
| 17 | +import gc |
| 18 | +import sys |
| 19 | + |
| 20 | +sys.path[0:0] = [""] |
| 21 | + |
| 22 | +from pymongo.monitor import MONITORS |
| 23 | +from test import unittest, port, host, IntegrationTest |
| 24 | +from test.utils import get_client, wait_until |
| 25 | + |
| 26 | + |
| 27 | +class TestMonitor(IntegrationTest): |
| 28 | + def test_atexit_hook(self): |
| 29 | + n_monitors = len(MONITORS) |
| 30 | + client = get_client(host, port) |
| 31 | + wait_until(lambda: len(MONITORS) == n_monitors + 1, |
| 32 | + 'register new monitor') |
| 33 | + |
| 34 | + del client |
| 35 | + gc.collect() |
| 36 | + |
| 37 | + wait_until(lambda: len(MONITORS) == n_monitors, |
| 38 | + 'unregister monitor') |
| 39 | + |
| 40 | + |
| 41 | +if __name__ == "__main__": |
| 42 | + unittest.main() |
0 commit comments