@@ -112,35 +112,44 @@ def logs(self):
112
112
return read_files ([self .stdout , self .stderr ])
113
113
114
114
115
- def wait_for_crash_reports (test_agent_client : TestAgentClient ) -> List [TestAgentRequest ]:
116
- crash_reports = []
117
- for _ in range (10 ): # 10 iterations * 0.1 second = 1 second total
118
- incoming_reports = test_agent_client .crash_reports ()
119
- if incoming_reports :
120
- crash_reports .extend (incoming_reports )
115
+ def wait_for_crash_messages (test_agent_client : TestAgentClient ) -> List [TestAgentRequest ]:
116
+ seen_report_ids = set ()
117
+ crash_messages = []
118
+ # 5 iterations * 0.2 second = 1 second total should be enough to get ping + report
119
+ for _ in range (5 ):
120
+ incoming_messages = test_agent_client .crash_messages ()
121
+ for message in incoming_messages :
122
+ body = message .get ("body" , b"" )
123
+ if isinstance (body , str ):
124
+ body = body .encode ("utf-8" )
125
+ report_id = (hash (body ), frozenset (message .get ("headers" , {}).items ()))
126
+ if report_id not in seen_report_ids :
127
+ seen_report_ids .add (report_id )
128
+ crash_messages .append (message )
129
+
121
130
# If we have both crash ping and crash report (2 reports), we can return early
122
- if len (crash_reports ) >= 2 :
123
- return crash_reports
124
- time .sleep (0.1 )
131
+ if len (crash_messages ) >= 2 :
132
+ return crash_messages
133
+ time .sleep (0.2 )
125
134
126
- return crash_reports
135
+ return crash_messages
127
136
128
137
129
138
def get_crash_report (test_agent_client : TestAgentClient ) -> TestAgentRequest :
130
139
"""Wait for a crash report from the crashtracker listener socket."""
131
- crash_reports = wait_for_crash_reports (test_agent_client )
140
+ crash_messages = wait_for_crash_messages (test_agent_client )
132
141
# We want at least the crash report
133
- assert len (crash_reports ) == 2 , f"Expected at 2 messages; one ping and one report, got { len (crash_reports )} "
142
+ assert len (crash_messages ) == 2 , f"Expected at least 2 messages; got { len (crash_messages )} "
134
143
135
- # Find the actual crash report (the one with "is_crash":"true")
136
- actual_crash_report = None
137
- for report in crash_reports :
138
- if b"is_crash:true" in report ["body" ]:
139
- actual_crash_report = report
144
+ # Find the crash report (the one with "is_crash":"true")
145
+ crash_report = None
146
+ for message in crash_messages :
147
+ if b"is_crash:true" in message ["body" ]:
148
+ crash_report = message
140
149
break
141
150
142
- assert actual_crash_report is not None , "Could not find crash report with 'is_crash:true' tag"
143
- return actual_crash_report
151
+ assert crash_report is not None , "Could not find crash report with 'is_crash:true' tag"
152
+ return crash_report
144
153
145
154
146
155
@contextmanager
0 commit comments