Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Matrix
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Container Registry
Model registry
Operate
Environments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
TeDomum
Matrix
Commits
36c58b18
Commit
36c58b18
authored
9 years ago
by
Mark Haines
Browse files
Options
Downloads
Patches
Plain Diff
Test for background updates
parent
a412b9a4
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_background_update.py
+76
-0
76 additions, 0 deletions
tests/storage/test_background_update.py
tests/utils.py
+3
-0
3 additions, 0 deletions
tests/utils.py
with
79 additions
and
0 deletions
tests/storage/test_background_update.py
0 → 100644
+
76
−
0
View file @
36c58b18
from
tests
import
unittest
from
twisted.internet
import
defer
from
synapse.api.constants
import
EventTypes
from
synapse.types
import
UserID
,
RoomID
,
RoomAlias
from
tests.utils
import
setup_test_homeserver
from
mock
import
Mock
class
BackgroundUpdateTestCase
(
unittest
.
TestCase
):
@defer.inlineCallbacks
def
setUp
(
self
):
hs
=
yield
setup_test_homeserver
()
self
.
store
=
hs
.
get_datastore
()
self
.
clock
=
hs
.
get_clock
()
self
.
update_handler
=
Mock
()
yield
self
.
store
.
register_background_update_handler
(
"
test_update
"
,
self
.
update_handler
)
@defer.inlineCallbacks
def
test_do_background_update
(
self
):
desired_count
=
1000
;
duration_ms
=
42
;
@defer.inlineCallbacks
def
update
(
progress
,
count
):
self
.
clock
.
advance_time_msec
(
count
*
duration_ms
)
progress
=
{
"
my_key
"
:
progress
[
"
my_key
"
]
+
1
}
yield
self
.
store
.
runInteraction
(
"
update_progress
"
,
self
.
store
.
_background_update_progress_txn
,
"
test_update
"
,
progress
,
)
defer
.
returnValue
(
count
)
self
.
update_handler
.
side_effect
=
update
yield
self
.
store
.
start_background_update
(
"
test_update
"
,
{
"
my_key
"
:
1
})
self
.
update_handler
.
reset_mock
()
result
=
yield
self
.
store
.
do_background_update
(
duration_ms
*
desired_count
)
self
.
assertIsNotNone
(
result
)
self
.
update_handler
.
assert_called_once_with
(
{
"
my_key
"
:
1
},
self
.
store
.
DEFAULT_BACKGROUND_BATCH_SIZE
)
@defer.inlineCallbacks
def
update
(
progress
,
count
):
yield
self
.
store
.
_end_background_update
(
"
test_update
"
)
defer
.
returnValue
(
count
)
self
.
update_handler
.
side_effect
=
update
self
.
update_handler
.
reset_mock
()
result
=
yield
self
.
store
.
do_background_update
(
duration_ms
*
desired_count
)
self
.
assertIsNotNone
(
result
)
self
.
update_handler
.
assert_called_once_with
(
{
"
my_key
"
:
2
},
desired_count
)
self
.
update_handler
.
reset_mock
()
result
=
yield
self
.
store
.
do_background_update
(
duration_ms
*
desired_count
)
self
.
assertIsNone
(
result
)
self
.
assertFalse
(
self
.
update_handler
.
called
)
This diff is collapsed.
Click to expand it.
tests/utils.py
+
3
−
0
View file @
36c58b18
...
...
@@ -243,6 +243,9 @@ class MockClock(object):
else
:
self
.
timers
.
append
(
t
)
def
advance_time_msec
(
self
,
ms
):
self
.
advance_time
(
ms
/
1000.
)
class
SQLiteMemoryDbPool
(
ConnectionPool
,
object
):
def
__init__
(
self
):
...
...
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