Merge ~cjwatson/turnip:hookrpc-handle-timeout into turnip:master

Proposed by Colin Watson
Status: Merged
Approved by: Colin Watson
Approved revision: f3706e99f37d749393f8eb5b55721c4e9a1e5e79
Merge reported by: Otto Co-Pilot
Merged at revision: not available
Proposed branch: ~cjwatson/turnip:hookrpc-handle-timeout
Merge into: turnip:master
Diff against target: 54 lines (+16/-2)
2 files modified
turnip/pack/hookrpc.py (+6/-2)
turnip/pack/tests/test_hookrpc.py (+10/-0)
Reviewer Review Type Date Requested Status
William Grant code Approve
Review via email: mp+371301@code.launchpad.net

Commit message

Handle timeout errors in hookrpc calls

LP: #1838675

To post a comment you must log in.
Revision history for this message
Jonathan Hartley (tartley) wrote :

Hi Colin! Diffs look good to me, based on a naive scan.

Again though, I don't know turnip or twisted, so on reflection I'll let someone else approve. :-)

Revision history for this message
William Grant (wgrant) :
review: Approve (code)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/turnip/pack/hookrpc.py b/turnip/pack/hookrpc.py
2index 5a73fff..dac851a 100644
3--- a/turnip/pack/hookrpc.py
4+++ b/turnip/pack/hookrpc.py
5@@ -79,8 +79,12 @@ class RPCServerProtocol(JSONNetstringProtocol):
6 if op not in self.methods:
7 self.sendValue({"error": "Unknown op: %s" % op})
8 return
9- res = yield self.methods[op](self, val)
10- self.sendValue({"result": res})
11+ try:
12+ res = yield self.methods[op](self, val)
13+ except defer.TimeoutError:
14+ self.sendValue({"error": "%s timed out" % op})
15+ else:
16+ self.sendValue({"result": res})
17
18 def invalidValueReceived(self, string):
19 self.sendValue({"error": "Command must be a JSON object"})
20diff --git a/turnip/pack/tests/test_hookrpc.py b/turnip/pack/tests/test_hookrpc.py
21index 5aec94b..2a56054 100644
22--- a/turnip/pack/tests/test_hookrpc.py
23+++ b/turnip/pack/tests/test_hookrpc.py
24@@ -105,6 +105,10 @@ def sync_rpc_method(proto, args):
25 return list(args.items())
26
27
28+def timeout_rpc_method(proto, args):
29+ raise defer.TimeoutError()
30+
31+
32 class TestRPCServerProtocol(TestCase):
33 """Test the socket server that handles git hook callbacks."""
34
35@@ -113,6 +117,7 @@ class TestRPCServerProtocol(TestCase):
36 self.proto = hookrpc.RPCServerProtocol({
37 'sync': sync_rpc_method,
38 'async': async_rpc_method,
39+ 'timeout': timeout_rpc_method,
40 })
41 self.transport = proto_helpers.StringTransportWithDisconnection()
42 self.transport.protocol = self.proto
43@@ -150,6 +155,11 @@ class TestRPCServerProtocol(TestCase):
44 b'42:{"error": "Command must be a JSON object"},',
45 self.transport.value())
46
47+ def test_timeout(self):
48+ self.proto.dataReceived(b'31:{"op": "timeout", "bar": "baz"},')
49+ self.assertEqual(
50+ b'30:{"error": "timeout timed out"},', self.transport.value())
51+
52
53 class TestHookRPCHandler(TestCase):
54 """Test the hook RPC handler."""

Subscribers

People subscribed via source and target branches