From 595a0e58455e95e5be0d6974af87998d0df14274 Mon Sep 17 00:00:00 2001 From: Brian Warner Date: Thu, 8 Oct 2015 18:35:26 -0700 Subject: [PATCH] server API: include "mood" when closing the channel This will be used as a simple unverifiable counter of success/failure. --- src/wormhole/blocking/transcribe.py | 5 +++-- src/wormhole/test/test_blocking.py | 5 +++-- src/wormhole/test/test_twisted.py | 4 ++-- src/wormhole/twisted/transcribe.py | 5 +++-- 4 files changed, 11 insertions(+), 8 deletions(-) diff --git a/src/wormhole/blocking/transcribe.py b/src/wormhole/blocking/transcribe.py index 12f51a1..4386c59 100644 --- a/src/wormhole/blocking/transcribe.py +++ b/src/wormhole/blocking/transcribe.py @@ -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() diff --git a/src/wormhole/test/test_blocking.py b/src/wormhole/test/test_blocking.py index 324732e..ee564fb 100644 --- a/src/wormhole/test/test_blocking.py +++ b/src/wormhole/test/test_blocking.py @@ -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) diff --git a/src/wormhole/test/test_twisted.py b/src/wormhole/test/test_twisted.py index 3628fcf..9fe04c9 100644 --- a/src/wormhole/test/test_twisted.py +++ b/src/wormhole/test/test_twisted.py @@ -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) diff --git a/src/wormhole/twisted/transcribe.py b/src/wormhole/twisted/transcribe.py index ee21ead..9af8470 100644 --- a/src/wormhole/twisted/transcribe.py +++ b/src/wormhole/twisted/transcribe.py @@ -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