Skip to content

Commit

Permalink
make refcount tests more consistent
Browse files Browse the repository at this point in the history
  • Loading branch information
slingamn committed Oct 2, 2015
1 parent 905d714 commit 08a38dd
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 10 deletions.
14 changes: 13 additions & 1 deletion tests/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
"""Tests. They want YOU!!"""

from __future__ import print_function

import gc
import sys
import unittest
import pylibmc
from pylibmc.test import make_test_client
Expand Down Expand Up @@ -29,3 +31,13 @@ def dump_infos():
print("Reported libmemcached version:", _pylibmc.libmemcached_version)
print("Reported pylibmc version:", _pylibmc.__version__)
print("Support compression:", _pylibmc.support_compression)

def get_refcounts(refcountables):
"""Measure reference counts during testing.
Measuring reference counts typically changes them (since at least
one new reference is created as the argument to sys.getrefcount).
Therefore, try to do it in a consistent and deterministic fashion.
"""
gc.collect()
return [sys.getrefcount(val) for val in refcountables]
5 changes: 1 addition & 4 deletions tests/test_refcounts.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,7 @@
import _pylibmc
from pylibmc.test import make_test_client
from tests import PylibmcTestCase


def get_refcounts(refcountables):
return [sys.getrefcount(val) for val in refcountables]
from tests import get_refcounts


class RefcountTests(PylibmcTestCase):
Expand Down
7 changes: 2 additions & 5 deletions tests/test_serialization.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,7 @@
import _pylibmc
from pylibmc.test import make_test_client
from tests import PylibmcTestCase


def get_refcounts(refcountables):
return [sys.getrefcount(val) for val in refcountables]
from tests import get_refcounts

def long_(val):
try:
Expand Down Expand Up @@ -47,7 +44,7 @@ def __setstate__(self, d):
c = make_test_client(MyClient, behaviors={'cas': True})
eq_(c.get('notathing'), None)

refcountables = ['foo', 'myobj', 'noneobj', 'myobj2', 'cachemiss', None]
refcountables = ['foo', 'myobj', 'noneobj', 'myobj2', 'cachemiss']
initial_refcounts = get_refcounts(refcountables)

c['foo'] = 'foo'
Expand Down

0 comments on commit 08a38dd

Please sign in to comment.