Skip to content

Commit

Permalink
fix: preserve headers through retry test decorator (#334)
Browse files Browse the repository at this point in the history
  • Loading branch information
coryan authored May 6, 2022
1 parent c991aff commit e1d93ac
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
8 changes: 7 additions & 1 deletion testbench/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -641,6 +641,12 @@ def _extract_data(data):
return data


def _extract_headers(response):
if isinstance(response, flask.Response):
return response.headers
return dict()


def __get_streamer_response_fn(database, method, conn, test_id, limit=4, chunk_size=4):
def response_handler(data):
def streamer():
Expand All @@ -666,7 +672,7 @@ def streamer():
"Injected 'broken stream' fault", 500
)

return flask.Response(streamer())
return flask.Response(streamer(), headers=_extract_headers(data))

return response_handler

Expand Down
1 change: 1 addition & 0 deletions tests/test_testbench_retry.py
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,7 @@ def test_retry_test_return_broken_stream_after_bytes(self):
query_string={"alt": "media"},
headers={"x-retry-test-id": id},
)
self.assertIn("x-goog-generation", response.headers)
with self.assertRaises(testbench.error.RestException) as ex:
_ = len(response.data)
self.assertIn("broken stream", ex.exception.msg)
Expand Down

0 comments on commit e1d93ac

Please sign in to comment.