diff options
author | Makarand Dharmapurikar <makarandd@google.com> | 2016-12-01 10:51:10 -0800 |
---|---|---|
committer | Makarand Dharmapurikar <makarandd@google.com> | 2016-12-01 10:51:10 -0800 |
commit | 323bfa733d8b23c19d48601dd4d9d5f71ab3bc5f (patch) | |
tree | 5d5cdc468ac55f9daebfefc047748a0d7d07b763 /test/http2_test | |
parent | af37b809aa931856764e766ebe3e9baaaaaa0897 (diff) |
Broke up code in multiple modules..
Diffstat (limited to 'test/http2_test')
-rw-r--r-- | test/http2_test/test_goaway.py | 51 | ||||
-rw-r--r-- | test/http2_test/test_max_streams.py | 30 | ||||
-rw-r--r-- | test/http2_test/test_ping.py | 36 | ||||
-rw-r--r-- | test/http2_test/test_rst_after_data.py | 23 | ||||
-rw-r--r-- | test/http2_test/test_rst_after_header.py | 19 |
5 files changed, 159 insertions, 0 deletions
diff --git a/test/http2_test/test_goaway.py b/test/http2_test/test_goaway.py new file mode 100644 index 0000000000..419bd7b3f8 --- /dev/null +++ b/test/http2_test/test_goaway.py @@ -0,0 +1,51 @@ +import logging +import http2_base_server + +class TestcaseGoaway(object): + """ + This test does the following: + Process incoming request normally, i.e. send headers, data and trailers. + Then send a GOAWAY frame with the stream id of the processed request. + It assert that the next request is made on a different TCP connection. + """ + def __init__(self, iteration): + self._base_server = http2_base_server.H2ProtocolBaseServer() + self._base_server._handlers['RequestReceived'] = self.on_request_received + self._base_server._handlers['DataReceived'] = self.on_data_received + self._base_server._handlers['WindowUpdated'] = self.on_window_update_default + self._base_server._handlers['SendDone'] = self.on_send_done + self._base_server._handlers['ConnectionLost'] = self.on_connection_lost + self._ready_to_send = False + self._iteration = iteration + + def get_base_server(self): + return self._base_server + + def on_connection_lost(self, reason): + logging.info('Disconnect received. Count %d'%self._iteration) + # _iteration == 2 => Two different connections have been used. + if self._iteration == 2: + self._base_server.on_connection_lost(reason) + + def on_send_done(self): + self._base_server.on_send_done_default() + if self._base_server._stream_id == 1: + logging.info('Sending GOAWAY for stream 1') + self._base_server._conn.close_connection(error_code=0, additional_data=None, last_stream_id=1) + + def on_request_received(self, event): + self._ready_to_send = False + self._base_server.on_request_received_default(event) + + def on_data_received(self, event): + self._base_server.on_data_received_default(event) + sr = self._base_server.parse_received_data(self._base_server._recv_buffer) + if sr: + logging.info('Creating response size = %s'%sr.response_size) + response_data = self._base_server.default_response_data(sr.response_size) + self._ready_to_send = True + self._base_server.setup_send(response_data) + + def on_window_update_default(self, event): + if self._ready_to_send: + self._base_server.default_send() diff --git a/test/http2_test/test_max_streams.py b/test/http2_test/test_max_streams.py new file mode 100644 index 0000000000..a85dde48b5 --- /dev/null +++ b/test/http2_test/test_max_streams.py @@ -0,0 +1,30 @@ +import logging +import http2_base_server +from hyperframe.frame import SettingsFrame + +class TestcaseSettingsMaxStreams(object): + """ + This test sets MAX_CONCURRENT_STREAMS to 1 and asserts that at any point + only 1 stream is active. + """ + def __init__(self): + self._base_server = http2_base_server.H2ProtocolBaseServer() + self._base_server._handlers['DataReceived'] = self.on_data_received + self._base_server._handlers['ConnectionMade'] = self.on_connection_made + + def get_base_server(self): + return self._base_server + + def on_connection_made(self): + logging.info('Connection Made') + self._base_server._conn.initiate_connection() + self._base_server._conn.update_settings({SettingsFrame.MAX_CONCURRENT_STREAMS: 1}) + self._base_server.transport.setTcpNoDelay(True) + self._base_server.transport.write(self._base_server._conn.data_to_send()) + + def on_data_received(self, event): + self._base_server.on_data_received_default(event) + sr = self._base_server.parse_received_data(self._base_server._recv_buffer) + logging.info('Creating response size = %s'%sr.response_size) + response_data = self._base_server.default_response_data(sr.response_size) + self._base_server.setup_send(response_data) diff --git a/test/http2_test/test_ping.py b/test/http2_test/test_ping.py new file mode 100644 index 0000000000..bade9df9b1 --- /dev/null +++ b/test/http2_test/test_ping.py @@ -0,0 +1,36 @@ +import logging +import http2_base_server + +class TestcasePing(object): + """ + This test injects PING frames before and after header and data. Keeps count + of outstanding ping response and asserts when the count is non-zero at the + end of the test. + """ + def __init__(self): + self._base_server = http2_base_server.H2ProtocolBaseServer() + self._base_server._handlers['RequestReceived'] = self.on_request_received + self._base_server._handlers['DataReceived'] = self.on_data_received + self._base_server._handlers['ConnectionLost'] = self.on_connection_lost + + def get_base_server(self): + return self._base_server + + def on_request_received(self, event): + self._base_server.default_ping() + self._base_server.on_request_received_default(event) + self._base_server.default_ping() + + def on_data_received(self, event): + self._base_server.on_data_received_default(event) + sr = self._base_server.parse_received_data(self._base_server._recv_buffer) + logging.info('Creating response size = %s'%sr.response_size) + response_data = self._base_server.default_response_data(sr.response_size) + self._base_server.default_ping() + self._base_server.setup_send(response_data) + self._base_server.default_ping() + + def on_connection_lost(self, reason): + logging.info('Disconnect received. Ping Count %d'%self._base_server._outstanding_pings) + assert(self._base_server._outstanding_pings == 0) + self._base_server.on_connection_lost(reason) diff --git a/test/http2_test/test_rst_after_data.py b/test/http2_test/test_rst_after_data.py new file mode 100644 index 0000000000..ef8d4084d9 --- /dev/null +++ b/test/http2_test/test_rst_after_data.py @@ -0,0 +1,23 @@ +import http2_base_server + +class TestcaseRstStreamAfterData(object): + """ + In response to an incoming request, this test sends headers, followed by + data, followed by a reset stream frame. Client asserts that the RPC failed. + """ + def __init__(self): + self._base_server = http2_base_server.H2ProtocolBaseServer() + self._base_server._handlers['DataReceived'] = self.on_data_received + + def get_base_server(self): + return self._base_server + + def on_data_received(self, event): + self._base_server.on_data_received_default(event) + sr = self._base_server.parse_received_data(self._base_server._recv_buffer) + assert(sr is not None) + response_data = self._base_server.default_response_data(sr.response_size) + self._ready_to_send = True + self._base_server.setup_send(response_data) + # send reset stream + self._base_server.send_reset_stream() diff --git a/test/http2_test/test_rst_after_header.py b/test/http2_test/test_rst_after_header.py new file mode 100644 index 0000000000..e9a6b1129c --- /dev/null +++ b/test/http2_test/test_rst_after_header.py @@ -0,0 +1,19 @@ +import http2_base_server + +class TestcaseRstStreamAfterHeader(object): + """ + In response to an incoming request, this test sends headers, followed by + a reset stream frame. Client asserts that the RPC failed. + """ + def __init__(self): + self._base_server = http2_base_server.H2ProtocolBaseServer() + self._base_server._handlers['RequestReceived'] = self.on_request_received + + def get_base_server(self): + return self._base_server + + def on_request_received(self, event): + # send initial headers + self._base_server.on_request_received_default(event) + # send reset stream + self._base_server.send_reset_stream() |