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
0fbfe1b0
Commit
0fbfe1b0
authored
10 years ago
by
Kegan Dougal
Browse files
Options
Downloads
Patches
Plain Diff
Add more tests; fix bugs.
parent
192e228a
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
synapse/appservice/scheduler.py
+2
-2
2 additions, 2 deletions
synapse/appservice/scheduler.py
tests/appservice/test_scheduler.py
+47
-7
47 additions, 7 deletions
tests/appservice/test_scheduler.py
with
49 additions
and
9 deletions
synapse/appservice/scheduler.py
+
2
−
2
View file @
0fbfe1b0
...
...
@@ -174,7 +174,7 @@ class _Recoverer(object):
self
.
backoff_counter
=
1
def
recover
(
self
):
self
.
clock
.
call_later
(
2
000
**
self
.
backoff_counter
,
self
.
retry
)
self
.
clock
.
call_later
(
1
000
*
(
2
**
self
.
backoff_counter
)
,
self
.
retry
)
@defer.inlineCallbacks
def
retry
(
self
):
...
...
@@ -184,7 +184,7 @@ class _Recoverer(object):
txn
.
complete
(
self
.
store
)
# reset the backoff counter and retry immediately
self
.
backoff_counter
=
1
self
.
retry
()
yield
self
.
retry
()
else
:
self
.
backoff_counter
+=
1
self
.
recover
()
...
...
This diff is collapsed.
Click to expand it.
tests/appservice/test_scheduler.py
+
47
−
7
View file @
0fbfe1b0
...
...
@@ -21,6 +21,7 @@ from ..utils import MockClock
from
mock
import
Mock
from
tests
import
unittest
class
ApplicationServiceSchedulerRecovererTestCase
(
unittest
.
TestCase
):
def
setUp
(
self
):
...
...
@@ -37,21 +38,60 @@ class ApplicationServiceSchedulerRecovererTestCase(unittest.TestCase):
callback
=
self
.
callback
,
)
def
test_recover_service_single_txn
(
self
):
txns
=
self
.
_mk_txns
(
1
)
self
.
store
.
get_oldest_txn
=
Mock
(
return_value
=
defer
.
succeed
(
txns
[
0
]))
def
test_recover_single_txn
(
self
):
txn
=
Mock
()
# return one txn to send, then no more old txns
txns
=
[
txn
,
None
]
def
take_txn
(
*
args
,
**
kwargs
):
return
defer
.
succeed
(
txns
.
pop
(
0
))
self
.
store
.
get_oldest_txn
=
Mock
(
side_effect
=
take_txn
)
self
.
recoverer
.
recover
()
# shouldn't have called anything prior to waiting for exp backoff
self
.
assertEquals
(
0
,
self
.
store
.
get_oldest_txn
.
call_count
)
txn
.
send
=
Mock
(
return_value
=
True
)
# wait for exp backoff
self
.
clock
.
advance_time
(
2000
)
self
.
assertEquals
(
1
,
txn
.
send
.
call_count
)
self
.
assertEquals
(
1
,
txn
.
complete
.
call_count
)
# 2 because it needs to get None to know there are no more txns
self
.
assertEquals
(
2
,
self
.
store
.
get_oldest_txn
.
call_count
)
self
.
assertEquals
(
1
,
self
.
callback
.
call_count
)
def
_mk
_txn
s
(
self
,
num_txns
):
return
[
Mock
()
for
i
in
range
(
num_txns
)
]
def
test_recover_retry
_txn
(
self
):
txn
=
Mock
()
txns
=
[
txn
,
None
]
pop_txn
=
False
def
take_txn
(
*
args
,
**
kwargs
):
if
pop_txn
:
return
defer
.
succeed
(
txns
.
pop
(
0
))
else
:
return
defer
.
succeed
(
txn
)
self
.
store
.
get_oldest_txn
=
Mock
(
side_effect
=
take_txn
)
self
.
recoverer
.
recover
()
self
.
assertEquals
(
0
,
self
.
store
.
get_oldest_txn
.
call_count
)
txn
.
send
=
Mock
(
return_value
=
False
)
self
.
clock
.
advance_time
(
2000
)
self
.
assertEquals
(
1
,
txn
.
send
.
call_count
)
self
.
assertEquals
(
0
,
txn
.
complete
.
call_count
)
self
.
assertEquals
(
0
,
self
.
callback
.
call_count
)
self
.
clock
.
advance_time
(
4000
)
self
.
assertEquals
(
2
,
txn
.
send
.
call_count
)
self
.
assertEquals
(
0
,
txn
.
complete
.
call_count
)
self
.
assertEquals
(
0
,
self
.
callback
.
call_count
)
self
.
clock
.
advance_time
(
8000
)
self
.
assertEquals
(
3
,
txn
.
send
.
call_count
)
self
.
assertEquals
(
0
,
txn
.
complete
.
call_count
)
self
.
assertEquals
(
0
,
self
.
callback
.
call_count
)
txn
.
send
=
Mock
(
return_value
=
True
)
# successfully send the txn
pop_txn
=
True
# returns the txn the first time, then no more.
self
.
clock
.
advance_time
(
16000
)
self
.
assertEquals
(
1
,
txn
.
send
.
call_count
)
# new mock reset call count
self
.
assertEquals
(
1
,
txn
.
complete
.
call_count
)
self
.
assertEquals
(
1
,
self
.
callback
.
call_count
)
class
ApplicationServiceSchedulerEventGrouperTestCase
(
unittest
.
TestCase
):
...
...
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