Skip to content

Test MJPEGStream#131

Merged
rwb27 merged 5 commits intomainfrom
test-mjpeg-stream-2
Jul 7, 2025
Merged

Test MJPEGStream#131
rwb27 merged 5 commits intomainfrom
test-mjpeg-stream-2

Conversation

@rwb27
Copy link
Copy Markdown
Collaborator

@rwb27 rwb27 commented Jul 3, 2025

The MJPEGStream output was the single biggest bit of untested code. There is now a very basic test that makes sure it sends a response with at least one frame separator in it.

In doing this, it was necessary to add code to cleanly close the stream. This has changed the signature of the stop method, which may require calling code to be updated.

The TestClient we use to test without serving on HTTP does not support streaming: this means we get all the frames at once, which limits exactly what can be tested. Adding the code to cleanly stop the stream is important, as otherwise the TestClient would hang.

@barecheck
Copy link
Copy Markdown

barecheck bot commented Jul 3, 2025

Barecheck - Code coverage report

Total: 92.16%

Your code coverage diff: 2.98% ▴

Uncovered files and lines
FileLines
src/labthings_fastapi/outputs/mjpeg_stream.py122, 124, 127, 130, 158-160, 167-169, 180-182, 265, 279

rwb27 added 4 commits July 3, 2025 01:38
Currently this fails, because the `TestClient` doesn't actually stream responses :(

A work-around might be to implement stopping (i.e. get it to raise an exception and close the stream), then check the response includes some frames.
It's now possible to tell MJPEGStream that the stream has stopped. This terminates the streaming
response, and gets around the lack of streaming
support in starlette's test client.

With a bit of thought, this could potentially fix the longstanding issue that MJPEG Streams
prevent a labthings server from restarting.
@rwb27 rwb27 force-pushed the test-mjpeg-stream-2 branch from d93a68a to febdac5 Compare July 3, 2025 00:38
Copy link
Copy Markdown
Contributor

@julianstirling julianstirling left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good. We should make a note to go back and do function by function unit testing at some point.

Am I correct in understanding that the StopAsyncIteration error and handling now means the server should exit gracefully when we run ofm restart with a browser open?

@julianstirling julianstirling added this to the v0.0.10 milestone Jul 6, 2025
@rwb27 rwb27 merged commit 62adb82 into main Jul 7, 2025
14 checks passed
@rwb27 rwb27 deleted the test-mjpeg-stream-2 branch July 7, 2025 10:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants