Skip to content

Commit 180a0f6

Browse files
Merge 642ba0b into d7f5b80
2 parents d7f5b80 + 642ba0b commit 180a0f6

File tree

1 file changed

+92
-0
lines changed

1 file changed

+92
-0
lines changed

pydatalab/tests/server/test_blocks.py

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
import tempfile
2+
import time
3+
from pathlib import Path
4+
15
import pytest
26

37
from pydatalab.apps import BLOCK_TYPES, BLOCKS
@@ -197,3 +201,91 @@ def test_block_info_endpoint_contains_all_blocks(client):
197201
assert expected_block_types.issubset(
198202
returned_block_types
199203
), f"Missing block types in /info/blocks: {expected_block_types - returned_block_types}"
204+
205+
206+
@pytest.mark.dependency(depends=["test_get_all_available_block_types"])
207+
@pytest.mark.parametrize("n_points", [1000, 100000, 500000])
208+
def test_bokeh_plot_stress(admin_client, default_sample_dict, n_points):
209+
"""Test bokeh plot performance with large CSV datasets (1K, 100K, 500K points)."""
210+
sample_id = f"test_bokeh_stress_{n_points}_points"
211+
sample_data = default_sample_dict.copy()
212+
sample_data["item_id"] = sample_id
213+
214+
response = admin_client.post("/new-sample/", json=sample_data)
215+
assert response.status_code == 201
216+
assert response.json["status"] == "success"
217+
218+
csv_lines = ["X,Y"]
219+
for i in range(1, n_points + 1):
220+
csv_lines.append(f"{i},{i}")
221+
csv_content = "\n".join(csv_lines)
222+
223+
with tempfile.NamedTemporaryFile(mode="w", suffix=".csv", delete=False) as temp_file:
224+
temp_file.write(csv_content)
225+
temp_csv_path = temp_file.name
226+
227+
temp_file_path = Path(temp_csv_path)
228+
229+
try:
230+
with open(temp_file_path, "rb") as f:
231+
response = admin_client.post(
232+
"/upload-file/",
233+
buffered=True,
234+
content_type="multipart/form-data",
235+
data={
236+
"item_id": sample_id,
237+
"file": [(f, f"stress_test_{n_points}.csv")],
238+
"type": "text/csv",
239+
"replace_file": "null",
240+
"relativePath": "null",
241+
},
242+
)
243+
244+
assert response.status_code == 201, f"Failed to upload CSV with {n_points} points"
245+
assert response.json["status"] == "success"
246+
file_id = response.json["file_id"]
247+
248+
start_time = time.time()
249+
250+
response = admin_client.post(
251+
"/add-data-block/",
252+
json={
253+
"block_type": "tabular",
254+
"item_id": sample_id,
255+
"index": 0,
256+
},
257+
)
258+
259+
assert response.status_code == 200, f"Failed to add tabular block for {n_points} points"
260+
assert response.json["status"] == "success"
261+
block_id = response.json["new_block_obj"]["block_id"]
262+
263+
response = admin_client.get(f"/get-item-data/{sample_id}")
264+
assert response.status_code == 200
265+
item_data = response.json["item_data"]
266+
block_data = item_data["blocks_obj"][block_id]
267+
block_data["file_id"] = file_id
268+
269+
response = admin_client.post(
270+
"/update-block/", json={"block_data": block_data, "save_to_db": True}
271+
)
272+
assert response.status_code == 200
273+
274+
processing_time = time.time() - start_time
275+
276+
response = admin_client.get(f"/get-item-data/{sample_id}")
277+
assert response.status_code == 200
278+
assert response.json["status"] == "success"
279+
280+
item_data = response.json["item_data"]
281+
assert "blocks_obj" in item_data
282+
assert len(item_data["blocks_obj"]) == 1
283+
284+
updated_block = item_data["blocks_obj"][block_id]
285+
assert updated_block["blocktype"] == "tabular"
286+
assert updated_block.get("file_id") == file_id
287+
288+
print(f"✓ Bokeh plot with {n_points} points processed in {processing_time:.2f}s")
289+
290+
finally:
291+
temp_file_path.unlink(missing_ok=True)

0 commit comments

Comments
 (0)