Переглянути джерело

Adding Resizing Tests

Adding some testing around the automatic resizing of the dictionary
mmap file when increasing or decreasing the size of the data being
stored in the dictionary.
master
Nate Bohman 5 роки тому
джерело
коміт
cdf3639a5f
Підписано: Nate Bohman <natrinicle@gmail.com> Ідентифікатор GPG ключа: C10546A54ABA1CE5
3 змінених файлів з 56 додано та 2 видалено
  1. +1
    -1
      docs/source/coverage/shm_dict_shm_dict_py.source.html
  2. +1
    -1
      shm_dict/_version.py
  3. +54
    -0
      tests/test_shm_dict.py

+ 1
- 1
docs/source/coverage/shm_dict_shm_dict_py.source.html Переглянути файл

@@ -30,7 +30,7 @@
<p class="stm run hide_run" id="t30"><span class="nam">__credits__</span> <span class="op">=</span> <span class="op">[</span><span class="str">"Nate Bohman"</span><span class="op">]</span><span class="strut"> </span></p>
<p class="stm run hide_run" id="t31"><span class="nam">__license__</span> <span class="op">=</span> <span class="str">"LGPL-3"</span><span class="strut"> </span></p>
<p class="stm run hide_run" id="t32"><span class="nam">__maintainer__</span> <span class="op">=</span> <span class="str">"Nate Bohman"</span><span class="strut"> </span></p>
<p class="stm run hide_run" id="t33"><span class="nam">__email__</span> <span class="op">=</span> <span class="str">"natrinicle@natrinicle.com"</span><span class="strut"> </span></p>
<p class="stm run hide_run" id="t33"><span class="nam">__email__</span> <span class="op">=</span> <span class="str">"natrinicle-shm_dict@natrinicle.com"</span><span class="strut"> </span></p>
<p class="stm run hide_run" id="t34"><span class="nam">__status__</span> <span class="op">=</span> <span class="str">"Production"</span><span class="strut"> </span></p>
<p class="pln" id="t35"><span class="strut"> </span></p>
<p class="stm run hide_run" id="t36"><span class="nam">logger</span> <span class="op">=</span> <span class="nam">logging</span><span class="op">.</span><span class="nam">getLogger</span><span class="op">(</span><span class="nam">__name__</span><span class="op">)</span> <span class="com"># pylint: disable=invalid-name</span><span class="strut"> </span></p>

+ 1
- 1
shm_dict/_version.py Переглянути файл

@@ -1,7 +1,7 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

__version__ = "2019.08.21.23.49"
__version__ = "2019.08.28.20.31"
__version_info__ = tuple([int(num) for num in __version__.split(".")])



+ 54
- 0
tests/test_shm_dict.py Переглянути файл

@@ -6,9 +6,11 @@ try:
except ImportError:
from collections import MutableMapping

from math import ceil
import mmap
import mock
import os
import pickle
from random import SystemRandom
import re
from string import ascii_letters as str_ascii_letters, digits as str_digits
@@ -275,6 +277,58 @@ class TestSHMDict(object):
self.vol_shm_dict[dict_key] = rand_string(10)
assert len(self.vol_shm_dict) == 1

def test_large_dict(self, dict_key):
test_rand_string_short = rand_string(10)
test_rand_string_medium = rand_string(mmap.PAGESIZE * 2)
test_rand_string_long = rand_string(mmap.PAGESIZE * 4)
self.create_vol_shm_dict()

# Test short, medium, and long size storage
self.vol_shm_dict[dict_key] = test_rand_string_short
assert self.vol_shm_dict[dict_key] == test_rand_string_short
assert self.vol_shm_dict.map_file.size() == int(
ceil(float(len(pickle.dumps(self.vol_shm_dict.copy(), 2))) / mmap.PAGESIZE)
* mmap.PAGESIZE
)

self.vol_shm_dict[dict_key] = test_rand_string_medium
assert self.vol_shm_dict[dict_key] == test_rand_string_medium
assert self.vol_shm_dict.map_file.size() == int(
ceil(float(len(pickle.dumps(self.vol_shm_dict.copy(), 2))) / mmap.PAGESIZE)
* mmap.PAGESIZE
)

self.vol_shm_dict[dict_key] = test_rand_string_long
assert self.vol_shm_dict[dict_key] == test_rand_string_long
assert self.vol_shm_dict.map_file.size() == int(
ceil(float(len(pickle.dumps(self.vol_shm_dict.copy(), 2))) / mmap.PAGESIZE)
* mmap.PAGESIZE
)

# Test short + medium and short + medium + long storage
# Ensures that dict resizes map_file down first and then back up
self.vol_shm_dict[dict_key] = "".join(
[test_rand_string_short, test_rand_string_medium]
)
assert self.vol_shm_dict[dict_key] == "".join(
[test_rand_string_short, test_rand_string_medium]
)
assert self.vol_shm_dict.map_file.size() == int(
ceil(float(len(pickle.dumps(self.vol_shm_dict.copy(), 2))) / mmap.PAGESIZE)
* mmap.PAGESIZE
)

self.vol_shm_dict[dict_key] = "".join(
[test_rand_string_short, test_rand_string_medium, test_rand_string_long]
)
assert self.vol_shm_dict[dict_key] == "".join(
[test_rand_string_short, test_rand_string_medium, test_rand_string_long]
)
assert self.vol_shm_dict.map_file.size() == int(
ceil(float(len(pickle.dumps(self.vol_shm_dict.copy(), 2))) / mmap.PAGESIZE)
* mmap.PAGESIZE
)

def test_clear(self, dict_key):
test_rand_string = rand_string(10)
self.create_vol_shm_dict()

Завантаження…
Відмінити
Зберегти