File tree Expand file tree Collapse file tree 2 files changed +15
-2
lines changed
Expand file tree Collapse file tree 2 files changed +15
-2
lines changed Original file line number Diff line number Diff line change @@ -23,8 +23,8 @@ def test_send_to_slack(slack_channel: SlackChannel):
2323 finding = Finding (title = msg , aggregation_key = msg )
2424 finding .add_enrichment ([MarkdownBlock ("testing" )])
2525 slack_params = SlackSinkParams (name = "test_slack" , slack_channel = slack_channel .channel_name , api_key = "" )
26- slack_sender .send_finding_to_slack (finding , slack_params , False )
27- assert slack_channel .get_latest_message ( ) == msg
26+ ts = slack_sender .send_finding_to_slack (finding , slack_params , False )
27+ assert slack_channel .get_message_by_ts ( ts ) == msg
2828
2929
3030def test_long_slack_messages (slack_channel : SlackChannel ):
Original file line number Diff line number Diff line change @@ -18,10 +18,23 @@ def was_message_sent_recently(self, expected) -> bool:
1818 return False
1919
2020 def get_latest_message (self ):
21+ # Note: Prefer get_message_by_ts() to avoid race conditions when tests share a channel
2122 results = self .client .conversations_history (channel = self .channel_id )
2223 messages = results ["messages" ]
2324 return messages [0 ]["text" ]
2425
26+ def get_message_by_ts (self , ts : str ) -> str :
27+ """Get message by timestamp - avoids race conditions unlike get_latest_message()."""
28+ results = self .client .conversations_history (
29+ channel = self .channel_id ,
30+ latest = ts ,
31+ oldest = ts ,
32+ inclusive = True ,
33+ limit = 1
34+ )
35+ messages = results ["messages" ]
36+ return messages [0 ]["text" ] if messages else None
37+
2538 def get_complete_latest_message (self ):
2639 results = self .client .conversations_history (channel = self .channel_id )
2740 messages = results ["messages" ]
You can’t perform that action at this time.
0 commit comments