Skip to content

Commit

Permalink
rebase
Browse files Browse the repository at this point in the history
  • Loading branch information
Tulsishah committed Oct 27, 2024
1 parent 6795ccb commit 49de595
Showing 1 changed file with 107 additions and 0 deletions.
107 changes: 107 additions & 0 deletions tests/test_testbench_retry.py
Original file line number Diff line number Diff line change
Expand Up @@ -1176,6 +1176,113 @@ def test_write_retry_test_stall_after_bytes(self):
self.assertIn("size", create_rest)
self.assertEqual(int(create_rest.get("size")), 2 * UPLOAD_QUANTUM)

def test_retry_test_return_error_after_bytes_for_single_shot_upload(self):
# Create a new bucket
response = self.client.post(
"/storage/v1/b", data=json.dumps({"name": "bucket-name"})
)
self.assertEqual(response.status_code, 200)

# Setup a stall for reading back the object.
response = self.client.post(
"/retry_test",
data=json.dumps(
{
"instructions": {
"storage.objects.insert": [
"return-503-after-250K",
]
}
}
),
content_type="application/json",
)
self.assertEqual(response.status_code, 200)
self.assertTrue(
response.headers.get("content-type").startswith("application/json")
)

create_rest = json.loads(response.data)
self.assertIn("id", create_rest)
test_id = create_rest.get("id")

# Upload the 256KiB of data and trigger the stall.
data = self._create_block(UPLOAD_QUANTUM)
self.assertEqual(len(data), UPLOAD_QUANTUM)

boundary, payload = format_multipart_upload({}, data)
response = self.client.post(
"/upload/storage/v1/b/bucket-name/o",
query_string={"uploadType": "multipart", "name": "stall"},
content_type="multipart/related; boundary=" + boundary,
headers={
"x-retry-test-id": test_id,
},
data=payload,
)
self.assertEqual(response.status_code, 503)

# Upload the data again and check that stall not happen.
response = self.client.post(
"/upload/storage/v1/b/bucket-name/o",
query_string={"uploadType": "multipart", "name": "stall"},
content_type="multipart/related; boundary=" + boundary,
headers={
"x-retry-test-id": test_id,
},
data=payload,
)
self.assertEqual(response.status_code, 200)

def test_write_retry_error_single_shot_while_upload_size_less_than_size(
self,
):
# Create a new bucket
response = self.client.post(
"/storage/v1/b", data=json.dumps({"name": "bucket-name"})
)
self.assertEqual(response.status_code, 200)

# Setup a error for reading back the object.
response = self.client.post(
"/retry_test",
data=json.dumps(
{
"instructions": {
"storage.objects.insert": [
"return-503-after-250K",
]
}
}
),
content_type="application/json",
)
self.assertEqual(response.status_code, 200)
self.assertTrue(
response.headers.get("content-type").startswith("application/json")
)

create_rest = json.loads(response.data)
self.assertIn("id", create_rest)
test_id = create_rest.get("id")

# Upload the 200KiB of data and check error not happen.
data = self._create_block(200 * 1024)
self.assertEqual(len(data), 200 * 1024)

boundary, payload = format_multipart_upload({}, data)
response = self.client.post(
"/upload/storage/v1/b/bucket-name/o",
query_string={"uploadType": "multipart", "name": "error"},
content_type="multipart/related; boundary=" + boundary,
headers={
"x-retry-test-id": test_id,
},
data=payload,
)
self.assertEqual(response.status_code, 200)


class TestTestbenchRetryGrpc(unittest.TestCase):
def setUp(self):
rest_server.db.clear()
Expand Down

0 comments on commit 49de595

Please sign in to comment.