tests/test-wireproto-serverreactor.py
changeset 37056 861e9d37e56e
parent 37055 61393f888dfe
child 37057 2ec1fb9de638
--- a/tests/test-wireproto-serverreactor.py	Wed Mar 14 13:57:52 2018 -0700
+++ b/tests/test-wireproto-serverreactor.py	Wed Mar 14 14:01:16 2018 -0700
@@ -9,8 +9,8 @@
 
 ffs = framing.makeframefromhumanstring
 
-def makereactor():
-    return framing.serverreactor()
+def makereactor(deferoutput=False):
+    return framing.serverreactor(deferoutput=deferoutput)
 
 def sendframes(reactor, gen):
     """Send a generator of frame bytearray to a reactor.
@@ -95,6 +95,9 @@
             'data': None,
         })
 
+        result = reactor.oninputeof()
+        self.assertaction(result, 'noop')
+
     def test1argument(self):
         reactor = makereactor()
         results = list(sendcommandframes(reactor, b'mycommand',
@@ -310,6 +313,37 @@
             b'error-response application some message',
         ])
 
+    def test1commanddeferresponse(self):
+        """Responses when in deferred output mode are delayed until EOF."""
+        reactor = makereactor(deferoutput=True)
+        results = list(sendcommandframes(reactor, b'mycommand', {}))
+        self.assertEqual(len(results), 1)
+        self.assertaction(results[0], 'runcommand')
+
+        result = reactor.onbytesresponseready(b'response')
+        self.assertaction(result, 'noop')
+        result = reactor.oninputeof()
+        self.assertaction(result, 'sendframes')
+        self.assertframesequal(result[1]['framegen'], [
+            b'bytes-response eos response',
+        ])
+
+    def testmultiplecommanddeferresponse(self):
+        reactor = makereactor(deferoutput=True)
+        list(sendcommandframes(reactor, b'command1', {}))
+        list(sendcommandframes(reactor, b'command2', {}))
+
+        result = reactor.onbytesresponseready(b'response1')
+        self.assertaction(result, 'noop')
+        result = reactor.onbytesresponseready(b'response2')
+        self.assertaction(result, 'noop')
+        result = reactor.oninputeof()
+        self.assertaction(result, 'sendframes')
+        self.assertframesequal(result[1]['framegen'], [
+            b'bytes-response eos response1',
+            b'bytes-response eos response2'
+        ])
+
 if __name__ == '__main__':
     import silenttestrunner
     silenttestrunner.main(__name__)