Fix leaky tests

Fix some instance tracking to prevent Python-side objects from leaking
buffers.
Also, reduce min size of Cache instance (real minimum should be around ~~19MiB,
but we need to make it more deterministic and 20 MiB seems to be reasonable).

Still some stuff left to do, but it needs more investigation and, for
now, this should suffice just to enable some form of CI.

Signed-off-by: Jan Musial <jan.musial@intel.com>
This commit is contained in:
Jan Musial
2019-04-08 16:30:50 +02:00
parent f0c3e049c6
commit 003d6505aa
15 changed files with 246 additions and 172 deletions

View File

@@ -20,8 +20,8 @@ def test_ctx_fixture(pyocf_ctx):
def test_simple_wt_write(pyocf_ctx):
cache_device = Volume(S.from_MiB(100))
core_device = Volume(S.from_MiB(200))
cache_device = Volume(S.from_MiB(30))
core_device = Volume(S.from_MiB(30))
cache = Cache.start_on_device(cache_device)
core = Core.using_device(core_device)
@@ -49,17 +49,18 @@ def test_simple_wt_write(pyocf_ctx):
assert stats["usage"]["occupancy"]["value"] == 1
assert core.exp_obj_md5() == core_device.md5()
cache.stop()
def test_start_corrupted_metadata_lba(pyocf_ctx):
cache_device = ErrorDevice(S.from_MiB(100), error_sectors=set([0]))
cache_device = ErrorDevice(S.from_MiB(30), error_sectors=set([0]))
with pytest.raises(OcfError, match="OCF_ERR_WRITE_CACHE"):
cache = Cache.start_on_device(cache_device)
def test_load_cache_no_preexisting_data(pyocf_ctx):
cache_device = Volume(S.from_MiB(100))
cache_device = Volume(S.from_MiB(30))
with pytest.raises(OcfError, match="OCF_ERR_START_CACHE_FAIL"):
cache = Cache.load_from_device(cache_device)
@@ -68,7 +69,7 @@ def test_load_cache_no_preexisting_data(pyocf_ctx):
# TODO: Find out why this fails and fix
@pytest.mark.xfail
def test_load_cache(pyocf_ctx):
cache_device = Volume(S.from_MiB(100))
cache_device = Volume(S.from_MiB(30))
cache = Cache.start_on_device(cache_device)
cache.stop()

View File

@@ -5,14 +5,12 @@
import os
import sys
import pytest
sys.path.append(os.path.join(os.path.dirname(__file__), os.path.pardir))
from pyocf.types.logger import LogLevel, DefaultLogger, BufferLogger
from pyocf.types.volume import Volume, ErrorDevice
from pyocf.types.ctx import get_default_ctx
from pyocf.ocf import OcfLib
def pytest_configure(config):
@@ -24,10 +22,9 @@ def pyocf_ctx():
c = get_default_ctx(DefaultLogger(LogLevel.WARN))
c.register_volume_type(Volume)
c.register_volume_type(ErrorDevice)
yield c
for cache in c.caches:
cache.stop(flush=False)
for cache in c.caches[:]:
cache.stop()
c.exit()
@@ -39,4 +36,4 @@ def pyocf_ctx_log_buffer():
c.register_volume_type(ErrorDevice)
yield logger
for cache in c.caches:
cache.stop(flush=False)
cache.stop()

View File

@@ -19,8 +19,10 @@ from pyocf.types.shared import OcfError, OcfCompletion, CacheLineSize
@pytest.mark.parametrize("cls", CacheLineSize)
def test_adding_core(pyocf_ctx, cache_mode, cls):
# Start cache device
cache_device = Volume(S.from_MiB(100))
cache = Cache.start_on_device(cache_device, cache_mode=cache_mode, cache_line_size=cls)
cache_device = Volume(S.from_MiB(30))
cache = Cache.start_on_device(
cache_device, cache_mode=cache_mode, cache_line_size=cls
)
# Create core device
core_device = Volume(S.from_MiB(10))
@@ -42,8 +44,10 @@ def test_adding_core(pyocf_ctx, cache_mode, cls):
@pytest.mark.parametrize("cls", CacheLineSize)
def test_removing_core(pyocf_ctx, cache_mode, cls):
# Start cache device
cache_device = Volume(S.from_MiB(100))
cache = Cache.start_on_device(cache_device, cache_mode=cache_mode, cache_line_size=cls)
cache_device = Volume(S.from_MiB(30))
cache = Cache.start_on_device(
cache_device, cache_mode=cache_mode, cache_line_size=cls
)
# Create core device
core_device = Volume(S.from_MiB(10))
@@ -60,9 +64,9 @@ def test_removing_core(pyocf_ctx, cache_mode, cls):
assert stats["conf"]["core_count"] == 0
def test_100add_remove(pyocf_ctx):
def test_30add_remove(pyocf_ctx):
# Start cache device
cache_device = Volume(S.from_MiB(100))
cache_device = Volume(S.from_MiB(30))
cache = Cache.start_on_device(cache_device)
# Create core device
@@ -71,7 +75,7 @@ def test_100add_remove(pyocf_ctx):
# Add and remove core device in a loop 100 times
# Check statistics after every operation
for i in range(0, 100):
for i in range(0, 30):
cache.add_core(core)
stats = cache.get_stats()
assert stats["conf"]["core_count"] == 1
@@ -83,7 +87,7 @@ def test_100add_remove(pyocf_ctx):
def test_10add_remove_with_io(pyocf_ctx):
# Start cache device
cache_device = Volume(S.from_MiB(100))
cache_device = Volume(S.from_MiB(30))
cache = Cache.start_on_device(cache_device)
# Create core device
@@ -112,12 +116,12 @@ def test_10add_remove_with_io(pyocf_ctx):
assert stats["conf"]["core_count"] == 0
def test_add_remove_50core(pyocf_ctx):
def test_add_remove_30core(pyocf_ctx):
# Start cache device
cache_device = Volume(S.from_MiB(100))
cache_device = Volume(S.from_MiB(30))
cache = Cache.start_on_device(cache_device)
core_devices = []
core_amount = 50
core_amount = 30
# Add 50 cores and check stats after each addition
for i in range(0, core_amount):
@@ -143,11 +147,11 @@ def test_adding_to_random_cache(pyocf_ctx):
cache_devices = []
core_devices = {}
cache_amount = 5
core_amount = 50
core_amount = 30
# Create 5 cache devices
for i in range(0, cache_amount):
cache_device = Volume(S.from_MiB(100))
cache_device = Volume(S.from_MiB(30))
cache = Cache.start_on_device(cache_device)
cache_devices.append(cache)
@@ -173,8 +177,10 @@ def test_adding_to_random_cache(pyocf_ctx):
@pytest.mark.parametrize("cls", CacheLineSize)
def test_adding_core_twice(pyocf_ctx, cache_mode, cls):
# Start cache device
cache_device = Volume(S.from_MiB(100))
cache = Cache.start_on_device(cache_device, cache_mode=cache_mode, cache_line_size=cls)
cache_device = Volume(S.from_MiB(30))
cache = Cache.start_on_device(
cache_device, cache_mode=cache_mode, cache_line_size=cls
)
# Create core device
core_device = Volume(S.from_MiB(10))
@@ -196,12 +202,16 @@ def test_adding_core_twice(pyocf_ctx, cache_mode, cls):
@pytest.mark.parametrize("cls", CacheLineSize)
def test_adding_core_already_used(pyocf_ctx, cache_mode, cls):
# Start first cache device
cache_device1 = Volume(S.from_MiB(100))
cache1 = Cache.start_on_device(cache_device1, cache_mode=cache_mode, cache_line_size=cls)
cache_device1 = Volume(S.from_MiB(30))
cache1 = Cache.start_on_device(
cache_device1, cache_mode=cache_mode, cache_line_size=cls
)
# Start second cache device
cache_device2 = Volume(S.from_MiB(100))
cache2 = Cache.start_on_device(cache_device2, cache_mode=cache_mode, cache_line_size=cls)
cache_device2 = Volume(S.from_MiB(30))
cache2 = Cache.start_on_device(
cache_device2, cache_mode=cache_mode, cache_line_size=cls
)
# Create core device
core_device = Volume(S.from_MiB(10))
@@ -226,8 +236,10 @@ def test_adding_core_already_used(pyocf_ctx, cache_mode, cls):
@pytest.mark.parametrize("cls", CacheLineSize)
def test_add_remove_incrementally(pyocf_ctx, cache_mode, cls):
# Start cache device
cache_device = Volume(S.from_MiB(100))
cache = Cache.start_on_device(cache_device, cache_mode=cache_mode, cache_line_size=cls)
cache_device = Volume(S.from_MiB(30))
cache = Cache.start_on_device(
cache_device, cache_mode=cache_mode, cache_line_size=cls
)
core_devices = []
core_amount = 5

View File

@@ -16,8 +16,10 @@ from pyocf.types.shared import CacheLineSize
@pytest.mark.parametrize("cls", CacheLineSize)
def test_change_cache_mode(pyocf_ctx, from_cm, to_cm, cls):
# Start cache device
cache_device = Volume(S.from_MiB(100))
cache = Cache.start_on_device(cache_device, cache_mode=from_cm, cache_line_size=cls)
cache_device = Volume(S.from_MiB(30))
cache = Cache.start_on_device(
cache_device, cache_mode=from_cm, cache_line_size=cls
)
# Check if started with correct cache mode
stats = cache.get_stats()