summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLaurent Pinchart <laurent.pinchart@ideasonboard.com>2024-01-21 04:45:40 +0200
committerLaurent Pinchart <laurent.pinchart@ideasonboard.com>2024-01-25 02:39:12 +0200
commitedbcdebba7602aeb30a12817088bbabbfc57c98b (patch)
tree9710e8369d61b8df5a4201dec09ba44ebd1fc583
parent652b47249a63f3cf9abb8fc2c51d6a16dedab81a (diff)
test: message: Destroy Object from correct thread context
The MessageReceiver and RecursiveMessageReceiver used in the test are destroyed from the main thread, which is invalid for a thread-bound object bound to a different thread. Fix it by destroying them with deleteLater(). Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Milan Zamazal <mzamazal@redhat.com>
-rw-r--r--test/message.cpp19
1 files changed, 12 insertions, 7 deletions
diff --git a/test/message.cpp b/test/message.cpp
index a34e0f0b..2f9f281c 100644
--- a/test/message.cpp
+++ b/test/message.cpp
@@ -109,16 +109,19 @@ protected:
return TestFail;
}
- MessageReceiver receiver;
- receiver.moveToThread(&thread_);
+ MessageReceiver *receiver = new MessageReceiver();
+ receiver->moveToThread(&thread_);
thread_.start();
- receiver.postMessage(std::make_unique<Message>(Message::None));
+ receiver->postMessage(std::make_unique<Message>(Message::None));
this_thread::sleep_for(chrono::milliseconds(100));
- switch (receiver.status()) {
+ MessageReceiver::Status status = receiver->status();
+ receiver->deleteLater();
+
+ switch (status) {
case MessageReceiver::NoMessage:
cout << "No message received" << endl;
return TestFail;
@@ -135,8 +138,7 @@ protected:
* leaks. Two messages need to be posted to ensure we don't only
* test the simple case of a queue containing a single message.
*/
- std::unique_ptr<RecursiveMessageReceiver> recursiveReceiver =
- std::make_unique<RecursiveMessageReceiver>();
+ RecursiveMessageReceiver *recursiveReceiver = new RecursiveMessageReceiver();
recursiveReceiver->moveToThread(&thread_);
recursiveReceiver->postMessage(std::make_unique<Message>(Message::None));
@@ -144,7 +146,10 @@ protected:
this_thread::sleep_for(chrono::milliseconds(10));
- if (!recursiveReceiver->success()) {
+ bool success = recursiveReceiver->success();
+ recursiveReceiver->deleteLater();
+
+ if (!success) {
cout << "Recursive message delivery failed" << endl;
return TestFail;
}