From 5fb5f1c92bb8e221ed0a88867891438a5c6f5baf Mon Sep 17 00:00:00 2001 From: Vlad Zahorodnii Date: Sun, 23 Apr 2023 23:06:04 +0300 Subject: [PATCH] autotests: Stabilize testWaylandSeat TestWaylandSeat::sync() ensures that events and requests can't be reordered after it. That is, it guarantees that - events sent from the compositor will be processed by the client before sync() finishes - requests issued by the client will be processed by the compositor before sync() finishes WaylandSyncPoint relies on the fact that wl_display_sync()'s callback and other wayland events will be processed in the same event queue. But, it's not the case right now. The wl_callback belongs to the default event queue and KWayland::Client::Seat belongs to a different queue. If the default event queue is dispatched first, the WaylandSyncPoint may emit the done signal too early. In order to fix sync(), this change ensures that WaylandSyncPoint's wl_callback uses the correct event queue. --- src/wayland/autotests/client/test_wayland_seat.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/wayland/autotests/client/test_wayland_seat.cpp b/src/wayland/autotests/client/test_wayland_seat.cpp index a796c41a53..7552b22cc3 100644 --- a/src/wayland/autotests/client/test_wayland_seat.cpp +++ b/src/wayland/autotests/client/test_wayland_seat.cpp @@ -53,7 +53,7 @@ class WaylandSyncPoint : public QObject Q_OBJECT public: - explicit WaylandSyncPoint(wl_display *display) + explicit WaylandSyncPoint(KWayland::Client::ConnectionThread *connection, KWayland::Client::EventQueue *eventQueue) { static const wl_callback_listener listener = { .done = [](void *data, wl_callback *callback, uint32_t callback_data) { @@ -62,7 +62,8 @@ public: }, }; - m_callback = wl_display_sync(display); + m_callback = wl_display_sync(connection->display()); + eventQueue->addProxy(m_callback); wl_callback_add_listener(m_callback, &listener, this); } @@ -283,7 +284,7 @@ void TestWaylandSeat::cleanup() bool TestWaylandSeat::sync() { - WaylandSyncPoint syncPoint(m_connection->display()); + WaylandSyncPoint syncPoint(m_connection, m_queue); QSignalSpy doneSpy(&syncPoint, &WaylandSyncPoint::done); return doneSpy.wait(); }