test: message: Add slow receiver test
There's a race in the message delivery against object deletion. Add a test that triggers it reliably. This test is expected to fail with an assertion error. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Jacopo Mondi <jacopo@jmondi.org> Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
This commit is contained in:
parent
1f6342f46b
commit
d9dac46e6f
1 changed files with 32 additions and 0 deletions
|
@ -52,6 +52,25 @@ private:
|
||||||
Status status_;
|
Status status_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class SlowMessageReceiver : public Object
|
||||||
|
{
|
||||||
|
protected:
|
||||||
|
void message(Message *msg)
|
||||||
|
{
|
||||||
|
if (msg->type() != Message::None) {
|
||||||
|
Object::message(msg);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Don't access any member of the object here (including the
|
||||||
|
* vtable) as the object will be deleted by the main thread
|
||||||
|
* while we're sleeping.
|
||||||
|
*/
|
||||||
|
this_thread::sleep_for(chrono::milliseconds(100));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
class MessageTest : public Test
|
class MessageTest : public Test
|
||||||
{
|
{
|
||||||
protected:
|
protected:
|
||||||
|
@ -88,6 +107,19 @@ protected:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Test for races between message delivery and object deletion.
|
||||||
|
* Failures result in assertion errors, there is no need for
|
||||||
|
* explicit checks.
|
||||||
|
*/
|
||||||
|
SlowMessageReceiver *slowReceiver = new SlowMessageReceiver();
|
||||||
|
slowReceiver->moveToThread(&thread_);
|
||||||
|
slowReceiver->postMessage(utils::make_unique<Message>(Message::None));
|
||||||
|
|
||||||
|
this_thread::sleep_for(chrono::milliseconds(10));
|
||||||
|
|
||||||
|
delete slowReceiver;
|
||||||
|
|
||||||
return TestPass;
|
return TestPass;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue