Conversation
deflect/ImageSegmenter.cpp
Outdated
|
|
||
| try | ||
| { | ||
| future.waitForFinished(); |
There was a problem hiding this comment.
No, we shouldn't wait for the result. The sending should start while the compression is in progress (see comments below).
There was a problem hiding this comment.
Of course. I just focused on getting the exception from the async execution. Too bad
| std::stringstream msg; | ||
| msg << "libjpeg-turbo image conversion failure: " << tjGetErrorStr() | ||
| << std::endl; | ||
| throw std::runtime_error(msg.str()); |
There was a problem hiding this comment.
OK but the header should mention that the function can throw.
|
I kept the empty bytearray for indicating errors and check it accordingly. |
tests/cpp/StreamTests.cpp
Outdated
| // Note: the following send tests only work as the small segment send does not | ||
| // need the sendWorker thread to be present. So fortunate for us we can skip | ||
| // setting up a stream server. | ||
| BOOST_AUTO_TEST_CASE(testErrorOnUncompressedRGBA) |
There was a problem hiding this comment.
Great, this was indeed missing! Let's be fully complete and split this in three test cases:
- testSendUncompressedRGBA
- testErrorOnUnsupportedUncompressedFormats
- testErrorOnNullUncompressedImage
tests/cpp/ServerTests.cpp
Outdated
|
|
||
| deflect::ImageWrapper bigImage(nullptr, 1000, 1000, deflect::ARGB); | ||
| bigImage.compressionPolicy = deflect::COMPRESSION_ON; | ||
| BOOST_CHECK(!stream.send(bigImage).get()); |
There was a problem hiding this comment.
I that the only line we are truly testing? The amount of boilerplate code in this test suite is starting to be worrying, we should look for a way to mock the server / connection or at least reuse a shared Fixture.
deflect/ImageJpegCompressor.h
Outdated
| * @param sourceImage The source image containing uncompressed image data. | ||
| * @param imageRegion The region of the image to be compressed. Must not | ||
| * exceed image dimensions. | ||
| * @return compressed image if successful, otherwise QByteArray.isEmpty() |
|
Build finished. |
deflect/ImageJpegCompressor.cpp
Outdated
| return QByteArray(); | ||
| std::stringstream msg; | ||
| msg << "libjpeg-turbo image conversion failure: " << tjGetErrorStr(); | ||
| throw std::invalid_argument(msg.str()); |
There was a problem hiding this comment.
I would say this is more a runtime_error at this point
deflect/ImageJpegCompressor.h
Outdated
| * @return compressed image if successful, otherwise QByteArray.isEmpty() | ||
| * @return compressed image | ||
| * @throw std::invalid_argument if sourceImage.data is nullptr or | ||
| * tjCompress2 failed |
There was a problem hiding this comment.
don't mention tjCompress2 in the doc, it's an implementation detail and has the potential to become outdated
deflect/ImageSegmenter.h
Outdated
| * | ||
| * @param image The image to be compressed | ||
| * @return the compressed segment | ||
| * @throw std::runtime_error if image is too big |
deflect/StreamSendWorker.cpp
Outdated
| break; | ||
| } | ||
| if (request.promise) | ||
| request.promise->set_value(true); |
There was a problem hiding this comment.
I don't think this works, does it pass unit tests? you have changed the logic and doing set_value() for each task, which should fail at the second set (and be caught again by the catch (...)). Recommendation: Keep the logic as it was before, with the try/catch surrounding the entire for-loop.
deflect/StreamSendWorker.cpp
Outdated
| << image.compressionQuality << std::endl; | ||
| return make_ready_future(false); | ||
| return make_exception_future<bool>( | ||
| std::make_exception_ptr(std::invalid_argument(msg.str()))); |
There was a problem hiding this comment.
move std::make_exception_ptr inside make_exception_future to avoid repeating it?
There was a problem hiding this comment.
There is make_exception_future<bool>(std::current_exception()); in StreamSendWorker which wouldn't work then
There was a problem hiding this comment.
maybe we could have two, or an overload for Exception=std::exception_ptr, something like:
template <typename T>
std::future<T> make_exception_future(std::exception_ptr&& e)
{
std::promise<T> promise;
promise.set_exception(std::move(e));
return promise.get_future();
}
template <typename T, typename Exception>
std::future<T> make_exception_future(Exception&& e)
{
return make_exception_future(std::make_exception_ptr(std::move(e)));
}
There was a problem hiding this comment.
That would work. Looks nice, thx!
| deflect::Stream stream("id", "dummyhost"); | ||
| std::vector<unsigned char> pixels(4 * 4 * 4); | ||
|
|
||
| std::vector<deflect::PixelFormat> unsupportedUncompressedFormats = { |
There was a problem hiding this comment.
name it allFormats here? I think you can even use auto for the variable type (init list).
rdumusc
left a comment
There was a problem hiding this comment.
This improves the readability quite a bit, good job!
| BOOST_CHECK_THROW(deflect::Stream("id", "localhost"), std::runtime_error); | ||
| } | ||
|
|
||
| BOOST_AUTO_TEST_CASE(testDefaultConstructorReadsEnvironmentVariables) |
There was a problem hiding this comment.
this test case got lost, but I still valid
There was a problem hiding this comment.
It cannot be replicated if a server is used that does not run on port 1701, which shouldn't be hardcoded in a unit test. DEFLECT_PORT as an env variable can be the only solution then.
| serverThread.wait(); | ||
| processServerMessage(); | ||
|
|
||
| BOOST_CHECK_EQUAL(openedStreams, 0); |
There was a problem hiding this comment.
I wasn't fully done yet yesterday, you reviewed too early :) I have not adapted all tests in here yet
There was a problem hiding this comment.
should be checked again
bb78046 to
ee4128c
Compare
| { | ||
| public: | ||
| /** The default communication port */ | ||
| static const unsigned short defaultPortNumber; |
There was a problem hiding this comment.
use this constant also in the 2 constructors with params (Observer + Stream)
deflect/StreamSendWorker.cpp
Outdated
| return make_exception_future<bool>(std::make_exception_ptr( | ||
| std::invalid_argument("Pending finish, no send allowed"))); | ||
| return make_exception_future<bool>( | ||
| std::invalid_argument("Pending finish, no send allowed")); |
There was a problem hiding this comment.
std::runtime_error here? Does not depend on the arguments
| deflect::Stream stream("id", "dummyhost"); | ||
| std::vector<unsigned char> pixels(4 * 4 * 4); | ||
|
|
||
| std::vector<deflect::PixelFormat> unsupportedUncompressedFormats = { |
tests/mock/DeflectServer.cpp
Outdated
| _thread.wait(); | ||
| } | ||
|
|
||
| void DeflectServer::processServerMessage() |
There was a problem hiding this comment.
currently this is waitForMessage(), no processing happens here
|
|
||
| #include <QThread> | ||
|
|
||
| class MinimalDeflectServer |
There was a problem hiding this comment.
I was going to suggest letting DeflectServer derive from MinimalDeflectServer, but realized they are not the same, because this one is in fact a wrapper for the MockServer. We should find clearer names...
There was a problem hiding this comment.
No, we should treat as good now and merge this :)
|
|
||
| #include <QThread> | ||
|
|
||
| class MinimalDeflectServer |
Also report stream connection errors in the GUI instead of cerr.
Also report stream connection errors in the GUI instead of cerr.
This bug was introduced in BlueBrain#177 and could result in the global QThreadPool threads being locked forever.
This bug was introduced in #177 and could result in the global QThreadPool threads being locked forever.
Also report stream connection errors in the GUI instead of cerr.
Uh oh!
There was an error while loading. Please reload this page.