1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
|
# -*- coding: utf-8 -*-
import gc
import sys
import psutil
import pymssql
import pytest
@pytest.mark.slow
@pytest.mark.xfail(reason="Memory test is not stable")
def test_memory_leak_on_unsuccessful_connect():
"""
This test checks python process memory usage and not just unsuccessful
connect path. Many other factors (i.e. garbage collection) affect memory
usage pattern. So this is an indirect test which is somewhat flaky and
because of that is marked 'xfail'.
"""
p = psutil.Process()
m0 = p.memory_full_info()
for i in range(10):
gc.collect()
try:
pymssql.connect(server="www.google.com", port=81, user='username',
password='password', login_timeout=1)
except:
pass
gc.collect()
m1 = p.memory_full_info()
duss = m1.uss - m0.uss
print(i, "uss=", m1.uss, "duss:", duss)
if i > 5:
assert duss <= 0
m0 = m1
if __name__ == '__main__':
test_memory_leak_on_unsuccessful_connect()
|