Skip to content

Commit

Permalink
fix b0ff882
Browse files Browse the repository at this point in the history
  • Loading branch information
brussee committed Nov 21, 2016
1 parent 6bda08f commit 8b037bf
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 15 deletions.
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})
2 changes: 1 addition & 1 deletion Tribler/Main/tribler_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -842,7 +842,7 @@ def OnExit(self):

self.utility.session.notifier.notify(NTFY_CLOSE_TICK, NTFY_INSERT, None, 'Shutdown session')
wx.Yield()
self.utility.session.shutdown(hacksessconfcheckpoint=False)
self.utility.session.shutdown()

# Arno, 2012-07-12: Shutdown should be quick
# Niels, 2013-03-21: However, setting it too low will prevent checkpoints from being written to disk
Expand Down
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)

0 comments on commit 8b037bf

Please sign in to comment.