Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
synapse
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Monitor
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Maunium
synapse
Commits
470dedd2
Commit
470dedd2
authored
4 years ago
by
Richard van der Hoff
Browse files
Options
Downloads
Patches
Plain Diff
Combine the two sets of DeferredCache tests
parent
4182bb81
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
tests/storage/test__base.py
+0
-72
0 additions, 72 deletions
tests/storage/test__base.py
tests/util/caches/test_deferred_cache.py
+75
-2
75 additions, 2 deletions
tests/util/caches/test_deferred_cache.py
with
75 additions
and
74 deletions
tests/storage/test__base.py
+
0
−
72
View file @
470dedd2
...
...
@@ -20,83 +20,11 @@ from mock import Mock
from
twisted.internet
import
defer
from
synapse.util.async_helpers
import
ObservableDeferred
from
synapse.util.caches.deferred_cache
import
DeferredCache
from
synapse.util.caches.descriptors
import
cached
from
tests
import
unittest
class
DeferredCacheTestCase
(
unittest
.
HomeserverTestCase
):
def
prepare
(
self
,
reactor
,
clock
,
homeserver
):
self
.
cache
=
DeferredCache
(
"
test
"
)
def
test_empty
(
self
):
failed
=
False
try
:
self
.
cache
.
get
(
"
foo
"
)
except
KeyError
:
failed
=
True
self
.
assertTrue
(
failed
)
def
test_hit
(
self
):
self
.
cache
.
prefill
(
"
foo
"
,
123
)
self
.
assertEquals
(
self
.
cache
.
get
(
"
foo
"
),
123
)
def
test_invalidate
(
self
):
self
.
cache
.
prefill
((
"
foo
"
,),
123
)
self
.
cache
.
invalidate
((
"
foo
"
,))
failed
=
False
try
:
self
.
cache
.
get
((
"
foo
"
,))
except
KeyError
:
failed
=
True
self
.
assertTrue
(
failed
)
def
test_eviction
(
self
):
cache
=
DeferredCache
(
"
test
"
,
max_entries
=
2
)
cache
.
prefill
(
1
,
"
one
"
)
cache
.
prefill
(
2
,
"
two
"
)
cache
.
prefill
(
3
,
"
three
"
)
# 1 will be evicted
failed
=
False
try
:
cache
.
get
(
1
)
except
KeyError
:
failed
=
True
self
.
assertTrue
(
failed
)
cache
.
get
(
2
)
cache
.
get
(
3
)
def
test_eviction_lru
(
self
):
cache
=
DeferredCache
(
"
test
"
,
max_entries
=
2
)
cache
.
prefill
(
1
,
"
one
"
)
cache
.
prefill
(
2
,
"
two
"
)
# Now access 1 again, thus causing 2 to be least-recently used
cache
.
get
(
1
)
cache
.
prefill
(
3
,
"
three
"
)
failed
=
False
try
:
cache
.
get
(
2
)
except
KeyError
:
failed
=
True
self
.
assertTrue
(
failed
)
cache
.
get
(
1
)
cache
.
get
(
3
)
class
CacheDecoratorTestCase
(
unittest
.
HomeserverTestCase
):
@defer.inlineCallbacks
def
test_passthrough
(
self
):
...
...
This diff is collapsed.
Click to expand it.
tests/util/caches/test_deferred_cache.py
+
75
−
2
View file @
470dedd2
...
...
@@ -18,12 +18,41 @@ from functools import partial
from
twisted.internet
import
defer
import
synapse.util.caches.deferred_cache
from
synapse.util.caches.deferred_cache
import
DeferredCache
class
DeferredCacheTestCase
(
unittest
.
TestCase
):
def
test_empty
(
self
):
cache
=
DeferredCache
(
"
test
"
)
failed
=
False
try
:
cache
.
get
(
"
foo
"
)
except
KeyError
:
failed
=
True
self
.
assertTrue
(
failed
)
def
test_hit
(
self
):
cache
=
DeferredCache
(
"
test
"
)
cache
.
prefill
(
"
foo
"
,
123
)
self
.
assertEquals
(
cache
.
get
(
"
foo
"
),
123
)
def
test_invalidate
(
self
):
cache
=
DeferredCache
(
"
test
"
)
cache
.
prefill
((
"
foo
"
,),
123
)
cache
.
invalidate
((
"
foo
"
,))
failed
=
False
try
:
cache
.
get
((
"
foo
"
,))
except
KeyError
:
failed
=
True
self
.
assertTrue
(
failed
)
def
test_invalidate_all
(
self
):
cache
=
synapse
.
util
.
caches
.
deferred_cache
.
DeferredCache
(
"
testcache
"
)
cache
=
DeferredCache
(
"
testcache
"
)
callback_record
=
[
False
,
False
]
...
...
@@ -62,3 +91,47 @@ class DeferredCacheTestCase(unittest.TestCase):
# letting the other lookup complete should do nothing
d1
.
callback
(
"
result1
"
)
self
.
assertIsNone
(
cache
.
get
(
"
key1
"
,
None
))
def
test_eviction
(
self
):
cache
=
DeferredCache
(
"
test
"
,
max_entries
=
2
,
apply_cache_factor_from_config
=
False
)
cache
.
prefill
(
1
,
"
one
"
)
cache
.
prefill
(
2
,
"
two
"
)
cache
.
prefill
(
3
,
"
three
"
)
# 1 will be evicted
failed
=
False
try
:
cache
.
get
(
1
)
except
KeyError
:
failed
=
True
self
.
assertTrue
(
failed
)
cache
.
get
(
2
)
cache
.
get
(
3
)
def
test_eviction_lru
(
self
):
cache
=
DeferredCache
(
"
test
"
,
max_entries
=
2
,
apply_cache_factor_from_config
=
False
)
cache
.
prefill
(
1
,
"
one
"
)
cache
.
prefill
(
2
,
"
two
"
)
# Now access 1 again, thus causing 2 to be least-recently used
cache
.
get
(
1
)
cache
.
prefill
(
3
,
"
three
"
)
failed
=
False
try
:
cache
.
get
(
2
)
except
KeyError
:
failed
=
True
self
.
assertTrue
(
failed
)
cache
.
get
(
1
)
cache
.
get
(
3
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment