server API: include "mood" when closing the channel
This will be used as a simple unverifiable counter of success/failure.
This commit is contained in:
parent
7a3b18b7f7
commit
595a0e5845
|
@ -104,11 +104,12 @@ class Channel:
|
|||
time.sleep(self._wait)
|
||||
return body
|
||||
|
||||
def deallocate(self):
|
||||
def deallocate(self, mood=u"unknown"):
|
||||
# only try once, no retries
|
||||
data = json.dumps({"appid": self._appid,
|
||||
"channelid": self._channelid,
|
||||
"side": self._side}).encode("utf-8")
|
||||
"side": self._side,
|
||||
"mood": mood}).encode("utf-8")
|
||||
requests.post(self._relay_url+"deallocate", data=data)
|
||||
# ignore POST failure, don't call r.raise_for_status()
|
||||
|
||||
|
|
|
@ -28,7 +28,8 @@ class Channel(ServerBase, unittest.TestCase):
|
|||
def _connected(c):
|
||||
self._channel = c
|
||||
d.addCallback(_connected)
|
||||
d.addCallback(lambda _: deferToThread(self._channel.deallocate))
|
||||
d.addCallback(lambda _: deferToThread(self._channel.deallocate,
|
||||
u"happy"))
|
||||
return d
|
||||
|
||||
def test_messages(self):
|
||||
|
@ -54,7 +55,7 @@ class Channel(ServerBase, unittest.TestCase):
|
|||
self.failUnlessEqual(len(self._relay_server._apps), 1)
|
||||
d.addCallback(_not_yet)
|
||||
# but deallocating both will make the messages go away
|
||||
d.addCallback(lambda _: deferToThread(c1.deallocate))
|
||||
d.addCallback(lambda _: deferToThread(c1.deallocate, u"sad"))
|
||||
def _gone(_):
|
||||
self._relay_server.prune()
|
||||
self.failUnlessEqual(len(self._relay_server._apps), 0)
|
||||
|
|
|
@ -27,7 +27,7 @@ class Channel(ServerBase, unittest.TestCase):
|
|||
def _connected(c):
|
||||
self._channel = c
|
||||
d.addCallback(_connected)
|
||||
d.addCallback(lambda _: self._channel.deallocate())
|
||||
d.addCallback(lambda _: self._channel.deallocate(u"happy"))
|
||||
return d
|
||||
|
||||
def test_messages(self):
|
||||
|
@ -53,7 +53,7 @@ class Channel(ServerBase, unittest.TestCase):
|
|||
self.failUnlessEqual(len(self._relay_server._apps), 1)
|
||||
d.addCallback(_not_yet)
|
||||
# but deallocating both will make the messages go away
|
||||
d.addCallback(lambda _: c1.deallocate())
|
||||
d.addCallback(lambda _: c1.deallocate(u"sad"))
|
||||
def _gone(_):
|
||||
self._relay_server.prune()
|
||||
self.failUnlessEqual(len(self._relay_server._apps), 0)
|
||||
|
|
|
@ -133,12 +133,13 @@ class Channel:
|
|||
d.addCallback(lambda _: msgs[0])
|
||||
return d
|
||||
|
||||
def deallocate(self):
|
||||
def deallocate(self, mood=u"unknown"):
|
||||
# only try once, no retries
|
||||
d = post_json(self._agent, self._relay_url+"deallocate",
|
||||
{"appid": self._appid,
|
||||
"channelid": self._channelid,
|
||||
"side": self._side})
|
||||
"side": self._side,
|
||||
"mood": mood})
|
||||
d.addBoth(lambda _: None) # ignore POST failure
|
||||
return d
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user