Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix session.shutdown arguments #2635

Merged
merged 2 commits into from
Nov 22, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 5 additions & 8 deletions Tribler/Core/Modules/restapi/shutdown_endpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

class ShutdownEndpoint(resource.Resource):
"""
With this endpoint you can trigger a Tribler shutdown.
With this endpoint you can shutdown Tribler.
"""

def __init__(self, session):
Expand All @@ -23,7 +23,7 @@ def render_PUT(self, request):
"""
.. http:put:: /shutdown

A PUT request to this endpoint triggers a Tribler shutdown.
A PUT request to this endpoint will shutdown Tribler.

**Example request**:

Expand All @@ -36,12 +36,9 @@ def render_PUT(self, request):
.. sourcecode:: javascript

{
"shutdown": True,
"gracetime": 2.0
"shutdown": True
}
"""
gracetime = 2.0

def shutdown_process(_, code=1):
reactor.addSystemEventTrigger('after', 'shutdown', os._exit, code)
reactor.stop()
Expand All @@ -51,8 +48,8 @@ def log_and_shutdown(failure):
self._logger.error(failure.value)
shutdown_process(failure, 0)

task.deferLater(reactor, 0, self.session.shutdown, gracetime=gracetime) \
task.deferLater(reactor, 0, self.session.shutdown) \
.addCallback(shutdown_process) \
.addErrback(log_and_shutdown)

return json.dumps({"shutdown": True, "gracetime": gracetime})
return json.dumps({"shutdown": True})
8 changes: 2 additions & 6 deletions Tribler/Test/Core/Modules/RestApi/test_shutdown_endpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,7 @@ def test_shutdown(self):
def verify_shutdown_called(_):
self.assertTrue(self.shutdown_called)

def fake_shutdown(checkpoint=True, gracetime=2.0, hacksessconfcheckpoint=True):
# Assert shutdown arguments
self.assertTrue(checkpoint)
self.assertEqual(2.0, gracetime)
self.assertTrue(hacksessconfcheckpoint)
def fake_shutdown():
# Record session.shutdown was called
self.shutdown_called = True
# Restore original shutdown for test teardown
Expand All @@ -30,6 +26,6 @@ def fake_shutdown(checkpoint=True, gracetime=2.0, hacksessconfcheckpoint=True):

self.session.shutdown = fake_shutdown

expected_json = {"shutdown": True, "gracetime": 2.0}
expected_json = {"shutdown": True}
return self.do_request('shutdown', expected_code=200, expected_json=expected_json, request_type='PUT')\
.addCallback(verify_shutdown_called)