-
Notifications
You must be signed in to change notification settings - Fork 19
Various fixes #177
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Various fixes #177
Conversation
rdumusc
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good in general!
deflect/ImageSegmenter.cpp
Outdated
|
|
||
| try | ||
| { | ||
| future.waitForFinished(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1, this was missing
|
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
too big -> invalid_argument?
deflect/StreamSendWorker.cpp
Outdated
| break; | ||
| } | ||
| if (request.promise) | ||
| request.promise->set_value(true); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
move std::make_exception_ptr inside make_exception_future to avoid repeating it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is make_exception_future<bool>(std::current_exception()); in StreamSendWorker which wouldn't work then
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
name it allFormats here? I think you can even use auto for the variable type (init list).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ping?
rdumusc
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this test case got lost, but I still valid
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no longer checked?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use this constant also in the 2 constructors with params (Observer + Stream)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
std::runtime_error here? Does not depend on the arguments
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
| 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ping?
tests/mock/DeflectServer.cpp
Outdated
| _thread.wait(); | ||
| } | ||
|
|
||
| void DeflectServer::processServerMessage() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
currently this is waitForMessage(), no processing happens here
|
|
||
| #include <QThread> | ||
|
|
||
| class MinimalDeflectServer |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, we should treat as good now and merge this :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK :-)
|
|
||
| #include <QThread> | ||
|
|
||
| class MinimalDeflectServer |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK :-)
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.