Skip to content

A platform for community discussion. Free, open, simple.

DEV: Fix flaky explicit tracking tests in request_tracker_spec (#37008)

Régis Hanol4819bc9f675b
diff --git a/spec/system/request_tracker_spec.rb b/spec/system/request_tracker_spec.rb
index 9bad0496369..02899a01129 100644
--- a/spec/system/request_tracker_spec.rb
+++ b/spec/system/request_tracker_spec.rb
@@ -326,7 +326,10 @@ describe "Request tracking", type: :system do
end
end
- event = events[0][:params].last
+ # Find the event for the topic we navigated to (by topic_id) to avoid flakiness
+ # from potential timing issues with multiple events
+ event = events.find { |e| e[:params].last[:topic_id] == topic.id }&.dig(:params)&.last
+ expect(event).to be_present
expect(event[:user_id]).to eq(current_user.id)
expect(event[:url]).to eq("#{Discourse.base_url_no_prefix}/t/#{topic.slug}/#{topic.id}")
@@ -386,7 +389,10 @@ describe "Request tracking", type: :system do
end
end
- event = events[0][:params].last
+ # Find the event for the topic we navigated to (by topic_id) to avoid flakiness
+ # from potential timing issues with multiple events
+ event = events.find { |e| e[:params].last[:topic_id] == topic.id }&.dig(:params)&.last
+ expect(event).to be_present
expect(event[:user_id]).to be_blank
expect(event[:url]).to eq("#{Discourse.base_url_no_prefix}/t/#{topic.slug}/#{topic.id}")