Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
P
persistent
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
persistent
Commits
a4f4d9f6
Commit
a4f4d9f6
authored
Apr 09, 2015
by
Jason Madden
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add test for cache gc based on byte size target.
parent
f94f7ec8
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
39 additions
and
0 deletions
+39
-0
persistent/tests/test_picklecache.py
persistent/tests/test_picklecache.py
+39
-0
No files found.
persistent/tests/test_picklecache.py
View file @
a4f4d9f6
...
...
@@ -983,6 +983,45 @@ class PickleCacheTests(unittest.TestCase):
# Nothing to test, just that it doesn't break
cache
.
_invalidate
(
p
.
_p_oid
)
def
test_cache_garbage_collection_bytes
(
self
):
from
persistent.interfaces
import
UPTODATE
from
persistent._compat
import
_b
cache
=
self
.
_makeOne
()
cache
.
target_size
=
1000
oids
=
[]
for
i
in
range
(
100
):
oid
=
_b
(
'oid_%04d'
%
i
)
oids
.
append
(
oid
)
o
=
cache
[
oid
]
=
self
.
_makePersist
(
oid
=
oid
,
state
=
UPTODATE
)
o
.
_Persistent__size
=
0
# must start 0, ZODB sets it AFTER updating the size
cache
.
update_object_size_estimation
(
oid
,
64
)
o
.
_Persistent__size
=
2
# mimic what the real persistent object does to update the cache
# size
o
.
_p_deactivate
=
lambda
:
cache
.
update_object_size_estimation
(
oid
,
-
1
)
self
.
assertEqual
(
cache
.
cache_non_ghost_count
,
100
)
# A GC at this point does nothing
cache
.
incrgc
()
self
.
assertEqual
(
cache
.
cache_non_ghost_count
,
100
)
# Now if we set a byte target:
cache
.
cache_size_bytes
=
1
# verify the change worked as expected
self
.
assertEqual
(
cache
.
cache_size_bytes
,
1
)
# verify our entrance assumption is fulfilled
self
.
assertTrue
(
cache
.
cache_size
>
100
)
self
.
assertTrue
(
cache
.
total_estimated_size
>
1
)
# A gc shrinks the bytes
cache
.
incrgc
()
self
.
assertTrue
(
cache
.
total_estimated_size
<=
1
)
# sanity check
self
.
assertTrue
(
cache
.
total_estimated_size
>=
0
)
class
DummyPersistent
(
object
):
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment