Merge pull request 'Run image decoding and resizing off the event loop' (#75) from perf/offload-image-processing into main
This commit was merged in pull request #75.
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
"""Tests for conversation file attachments: extraction, /upload and stream-query file_key."""
|
||||
|
||||
import io
|
||||
import threading
|
||||
from datetime import timedelta
|
||||
from types import SimpleNamespace
|
||||
from unittest.mock import AsyncMock, patch
|
||||
@@ -190,6 +191,21 @@ class TestUploadRoute:
|
||||
s3.upload_image.assert_awaited_once()
|
||||
s3.upload_file.assert_not_awaited()
|
||||
|
||||
async def test_image_processing_runs_off_the_event_loop(
|
||||
self, app, headers, s3, monkeypatch
|
||||
):
|
||||
threads = []
|
||||
real = conv.process_image
|
||||
|
||||
def recording(*args):
|
||||
threads.append(threading.current_thread())
|
||||
return real(*args)
|
||||
|
||||
monkeypatch.setattr(conv, "process_image", recording)
|
||||
resp = await _upload(app, headers, _png_bytes(), "cat.png", "image/png")
|
||||
assert resp.status_code == 200
|
||||
assert threads and threads[0] is not threading.main_thread()
|
||||
|
||||
async def test_unsupported_type_is_415(self, app, headers, s3):
|
||||
resp = await _upload(app, headers, b"PK\x03\x04", "a.zip", "application/zip")
|
||||
assert resp.status_code == 415
|
||||
|
||||
Reference in New Issue
Block a user