@@ -36,165 +36,6 @@ def _generate_payload(size_bytes: int, *, channels: list[str] | None = None) ->
3636@pytest .mark .min_sync_gateways (1 )
3737@pytest .mark .min_couchbase_servers (1 )
3838class TestLargeDocWorkloads (CBLTestClass ):
39- @pytest .mark .asyncio (loop_scope = "session" )
40- async def test_doc_body_size_boundary (self , cblpytest : CBLPyTest ) -> None :
41- """This test does not use a TS/CBL to replicate documents to SGW
42- This is because the batch updater cannot handle such 20MB docs
43- And returns 500 error then'n'there..."""
44- sg = cblpytest .sync_gateways [0 ]
45- cbs = cblpytest .couchbase_servers [0 ]
46- sg_db = "db"
47- bucket_name = "large-doc-bucket"
48-
49- self .mark_test_step ("Create bucket on Couchbase Server." )
50- cbs .create_bucket (bucket_name )
51-
52- self .mark_test_step ("Configure Sync Gateway database endpoint." )
53- db_config = {
54- "bucket" : bucket_name ,
55- "index" : {"num_replicas" : 0 },
56- "scopes" : {"_default" : {"collections" : {"_default" : {}}}},
57- }
58- db_payload = PutDatabasePayload (db_config )
59- await sg .put_database (sg_db , db_payload )
60- await sg .wait_for_db_up (sg_db )
61-
62- self .mark_test_step (
63- "Create a 19.9 MB document via SGW admin API — expect acceptance."
64- )
65- under_limit_payload = _generate_payload (int (19.9 * SIZE_MB ), channels = ["test" ])
66- under_limit_doc = await sg .create_document (
67- sg_db , "doc_19_9mb" , under_limit_payload
68- )
69- assert under_limit_doc is not None , (
70- "SGW should return a RemoteDocument for accepted 19.9 MB doc"
71- )
72- assert under_limit_doc .id == "doc_19_9mb" , (
73- f"Returned doc ID mismatch: expected 'doc_19_9mb', got '{ under_limit_doc .id } '"
74- )
75- assert under_limit_doc .revid is not None or under_limit_doc .cv is not None , (
76- "Accepted document must have a revision ID or CV assigned by SGW"
77- )
78-
79- self .mark_test_step (
80- "Verify the 19.9 MB document is retrievable from SGW with correct content."
81- )
82- retrieved_doc = await sg .get_document (
83- sg_db , "doc_19_9mb" , "_default" , "_default"
84- )
85- assert retrieved_doc is not None , (
86- "19.9 MB doc should be retrievable via GET after successful creation"
87- )
88- assert retrieved_doc .id == "doc_19_9mb" , "Retrieved doc ID mismatch"
89- assert "data" in retrieved_doc .body , (
90- "Retrieved doc body must contain the 'data' field"
91- )
92- assert len (retrieved_doc .body ["data" ]) > 19 * SIZE_MB , (
93- "Retrieved doc 'data' field should be approximately 19.9 MB"
94- )
95-
96- self .mark_test_step ("Verify 19.9 MB doc appears in _all_docs listing on SGW." )
97- all_docs = await sg .get_all_documents (sg_db , "_default" , "_default" )
98- all_doc_ids = {row .id for row in all_docs .rows }
99- assert "doc_19_9mb" in all_doc_ids , (
100- "Accepted 19.9 MB doc must appear in SGW _all_docs response"
101- )
102-
103- self .mark_test_step (
104- "Attempt to create a 20.1 MB document via SGW admin API — expect HTTP 413."
105- )
106- over_limit_payload = _generate_payload (int (20.1 * SIZE_MB ), channels = ["test" ])
107- with pytest .raises (CblSyncGatewayBadResponseError ) as exc_info :
108- await sg .create_document (sg_db , "doc_20_1mb" , over_limit_payload )
109-
110- assert exc_info .value .code == 413 , (
111- f"SGW should return HTTP 413 for oversized doc, got { exc_info .value .code } "
112- )
113-
114- self .mark_test_step (
115- "Verify the rejected 20.1 MB document does NOT exist in SGW."
116- )
117- try :
118- rejected_doc = await sg .get_document (
119- sg_db , "doc_20_1mb" , "_default" , "_default"
120- )
121- assert rejected_doc is None , (
122- "Rejected 20.1 MB doc must NOT be retrievable from SGW"
123- )
124- except CblSyncGatewayBadResponseError as e :
125- assert e .code == 404 , (
126- f"Expected 404 for non-existent rejected doc, got HTTP { e .code } "
127- )
128-
129- self .mark_test_step ("Verify rejected doc does NOT appear in _all_docs listing." )
130- all_docs_after = await sg .get_all_documents (sg_db , "_default" , "_default" )
131- all_doc_ids_after = {row .id for row in all_docs_after .rows }
132- assert "doc_20_1mb" not in all_doc_ids_after , (
133- "Rejected 20.1 MB doc must NOT appear in SGW _all_docs"
134- )
135- assert "doc_19_9mb" in all_doc_ids_after , (
136- "Previously accepted 19.9 MB doc must still be in _all_docs after rejection"
137- )
138-
139- self .mark_test_step (
140- "Create a normal 1 KB document to confirm writes still work after rejection."
141- )
142- small_payload = _generate_payload (1024 , channels = ["test" ])
143- small_doc = await sg .create_document (sg_db , "doc_1kb_control" , small_payload )
144- assert small_doc is not None , (
145- "SGW must accept a 1 KB doc after rejecting oversized one"
146- )
147- assert small_doc .id == "doc_1kb_control" , (
148- f"Control doc ID mismatch: expected 'doc_1kb_control', got '{ small_doc .id } '"
149- )
150-
151- self .mark_test_step (
152- "Verify SGW endpoints are responsive — _config, _changes, _all_docs, database status."
153- )
154- db_config_resp = await sg .get_database_config (sg_db )
155- assert db_config_resp is not None , "SGW _config endpoint must respond"
156- assert db_config_resp .get ("bucket" ) == bucket_name , (
157- f"_config bucket mismatch: expected '{ bucket_name } ', got '{ db_config_resp .get ('bucket' )} '"
158- )
159-
160- changes = await sg .get_changes (sg_db , "_default" , "_default" )
161- assert changes is not None , "SGW _changes endpoint must respond"
162- change_doc_ids = {r .id for r in changes .results }
163- assert "doc_19_9mb" in change_doc_ids , "19.9 MB doc must appear in _changes"
164- assert "doc_1kb_control" in change_doc_ids , (
165- "1 KB control doc must appear in _changes"
166- )
167- assert "doc_20_1mb" not in change_doc_ids , (
168- "Rejected 20.1 MB doc must NOT appear in _changes"
169- )
170-
171- final_all_docs = await sg .get_all_documents (sg_db , "_default" , "_default" )
172- final_ids = {row .id for row in final_all_docs .rows }
173- assert "doc_19_9mb" in final_ids , "19.9 MB doc must be in _all_docs"
174- assert "doc_1kb_control" in final_ids , "1 KB control doc must be in _all_docs"
175- assert "doc_20_1mb" not in final_ids , "20.1 MB doc must NOT be in _all_docs"
176-
177- db_status = await sg .get_database_status (sg_db )
178- assert db_status is not None , "SGW database status endpoint must respond"
179- assert db_status .state == "Online" , (
180- f"SGW database should be Online, got '{ db_status .state } '"
181- )
182-
183- self .mark_test_step (
184- "Verify previously accepted 19.9 MB doc is still accessible."
185- )
186- final_check = await sg .get_document (sg_db , "doc_19_9mb" , "_default" , "_default" )
187- assert final_check is not None , (
188- "Previously accepted 19.9 MB doc must remain accessible after boundary tests"
189- )
190-
191- self .mark_test_step (
192- "Verify CBS bucket — rejected doc must NOT exist. "
193- "(Skipping CBS fetch for accepted large docs due to KV timeout on ~20 MB bodies.)"
194- )
195- cbs_over = cbs .get_document (bucket_name , "doc_20_1mb" )
196- assert cbs_over is None , "Rejected 20.1 MB doc must NOT exist in CBS bucket"
197-
19839 @pytest .mark .asyncio (loop_scope = "session" )
19940 async def test_oversized_attachment_push (self , cblpytest : CBLPyTest ) -> None :
20041 sg = cblpytest .sync_gateways [0 ]
0 commit comments