Browse Source

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 years ago
parent
commit
cdf3639a5f
Signed by: Nate Bohman <natrinicle@gmail.com> GPG Key ID: C10546A54ABA1CE5
3 changed files with 56 additions and 2 deletions
  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 View File

<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="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="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="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="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="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> <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 View File

#!/usr/bin/env python #!/usr/bin/env python
# -*- coding: utf-8 -*- # -*- 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(".")]) __version_info__ = tuple([int(num) for num in __version__.split(".")])





+ 54
- 0
tests/test_shm_dict.py View File

except ImportError: except ImportError:
from collections import MutableMapping from collections import MutableMapping


from math import ceil
import mmap import mmap
import mock import mock
import os import os
import pickle
from random import SystemRandom from random import SystemRandom
import re import re
from string import ascii_letters as str_ascii_letters, digits as str_digits from string import ascii_letters as str_ascii_letters, digits as str_digits
self.vol_shm_dict[dict_key] = rand_string(10) self.vol_shm_dict[dict_key] = rand_string(10)
assert len(self.vol_shm_dict) == 1 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): def test_clear(self, dict_key):
test_rand_string = rand_string(10) test_rand_string = rand_string(10)
self.create_vol_shm_dict() self.create_vol_shm_dict()

Loading…
Cancel
Save