[next] tests: add event dispatch order test for same priority events
Adds a new test case for events with the same priority being delivered in the same order as they have been received. If the events are not correctly ordered, like as example a state change will result in the suspend-node hook wrongfully suspending clients.
I'm currently using this workaround:
From afa821620c23b2e890bbb08c6368faf0fee92e4a Mon Sep 17 00:00:00 2001
From: Duncan Overbruck <mail@duncano.de>
Date: Sun, 3 Sep 2023 14:17:25 +0200
Subject: [PATCH] WIP: hack in sequence numbers for events
---
lib/wp/event-dispatcher.c | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/lib/wp/event-dispatcher.c b/lib/wp/event-dispatcher.c
index 9a481dcd..1cc8e506 100644
--- a/lib/wp/event-dispatcher.c
+++ b/lib/wp/event-dispatcher.c
@@ -21,14 +21,18 @@ struct _EventData
WpEvent *event;
WpIterator *hooks_iter;
WpEventHook *current_hook_in_async;
+ guint64 seq;
};
+static guint64 seqn;
+
static inline EventData *
event_data_new (WpEvent * event)
{
EventData *event_data = g_new0 (EventData, 1);
event_data->event = wp_event_ref (event);
event_data->hooks_iter = wp_event_new_hooks_iterator (event);
+ event_data->seq = seqn++;
return event_data;
}
@@ -238,7 +242,9 @@ wp_event_dispatcher_get_instance (WpCore * core)
static gint
event_cmp_func (const EventData *a, const EventData *b)
{
- return wp_event_get_priority (b->event) - wp_event_get_priority (a->event);
+ int c = wp_event_get_priority (b->event) - wp_event_get_priority (a->event);
+ if (c != 0) return c;
+ return a->seq - b->seq;
}
/*!
--
2.42.0