Since we have locks over the logs, use direct access rather than API requests to get to them

This commit is contained in:
Aldo Cortesi 2016-06-02 18:10:36 +12:00
parent 40156ce123
commit 254614e9f7
3 changed files with 7 additions and 10 deletions

View File

@ -75,16 +75,13 @@ class Daemon:
"""
Return the log buffer as a list of dictionaries.
"""
resp = requests.get("%s/api/log" % self.urlbase, verify=False)
return resp.json()["log"]
return self.thread.server.get_log()
def clear_log(self):
"""
Clear the log.
"""
self.logfp.truncate(0)
resp = requests.get("%s/api/clear_log" % self.urlbase, verify=False)
return resp.ok
return self.thread.server.clear_log()
def shutdown(self):
"""
@ -101,6 +98,7 @@ class _PaThread(threading.Thread):
self.name = "PathodThread"
self.iface, self.q, self.ssl = iface, q, ssl
self.daemonargs = daemonargs
self.server = None
def run(self):
self.server = pathod.Pathod(

View File

@ -27,7 +27,7 @@ class TestApp(tutils.DaemonTests):
def test_log(self):
assert self.getpath("/log").status_code == 200
assert self.get("200:da").status_code == 200
id = self.d.log()[0]["id"]
id = self.d.expect_log(1)[0]["id"]
assert self.getpath("/log").status_code == 200
assert self.getpath("/log/%s" % id).status_code == 200
assert self.getpath("/log/9999999").status_code == 404

View File

@ -142,11 +142,10 @@ class CommonTests(tutils.DaemonTests):
assert tuple(self.d.info()["version"]) == version.IVERSION
def test_logs(self):
assert self.d.clear_log()
assert not self.d.last_log()
self.d.clear_log()
assert self.get("202:da")
assert len(self.d.log()) == 1
assert self.d.clear_log()
assert self.d.expect_log(1)
self.d.clear_log()
assert len(self.d.log()) == 0
def test_disconnect(self):