Skip to content

chore: replace sleep-based polling with Event synchronization in tests#1467

Open
WilliamBergamin wants to merge 7 commits intomainfrom
imporve-unit-test-around-assistant
Open

chore: replace sleep-based polling with Event synchronization in tests#1467
WilliamBergamin wants to merge 7 commits intomainfrom
imporve-unit-test-around-assistant

Conversation

@WilliamBergamin
Copy link
Contributor

Summary

These changes aims to improve the unit tests around assistant behavior by using the python Event object to synchronize threaded test behaviors rather then relying on home grown sleep based polling

This should make tests faster and more reliable (note: the 0.1s timeout might be to short we can adjust if we see flakiness)

Testing

CI should be sufficient

Category

  • slack_bolt.App and/or its core components
  • slack_bolt.async_app.AsyncApp and/or its core components
  • Adapters in slack_bolt.adapter
  • Document pages under /docs
  • Others

Requirements

Please read the Contributing guidelines and Code of Conduct before creating this issue or pull request. By submitting, you are agreeing to those rules.

  • I've read and understood the Contributing Guidelines and have done my best effort to follow them.
  • I've read and agree to the Code of Conduct.
  • I've run ./scripts/install_all_and_run_tests.sh after making the changes.

@codecov
Copy link

codecov bot commented Mar 20, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 91.31%. Comparing base (6406058) to head (21d0ad7).
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1467   +/-   ##
=======================================
  Coverage   91.31%   91.31%           
=======================================
  Files         229      229           
  Lines        7266     7266           
=======================================
  Hits         6635     6635           
  Misses        631      631           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Member

@zimeg zimeg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@WilliamBergamin Amazing find in improvements to the test patterns! 💰

Please feel free to merge whenever's right, but I'm wondering if this is a change that we ought match elsewhere or add to maintainer's guide adjacent?

Comment on lines -7 to +6
from slack_bolt import App, BoltRequest, Assistant, Say, SetSuggestedPrompts, SetStatus, BoltContext
from slack_bolt import App, Assistant, BoltContext, BoltRequest, Say, SetStatus, SetSuggestedPrompts
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🌟 praise: Thanks for these reorderings!

👾 ramble: The ruff linter supports patterns similar to isort that we might find useful I hope!

Comment on lines 44 to +53
@@ -54,37 +43,37 @@ def start_thread(say: Say, set_suggested_prompts: SetSuggestedPrompts, set_statu
set_suggested_prompts(
prompts=[{"title": "What does SLACK stand for?", "message": "What does SLACK stand for?"}], title="foo"
)
called["value"] = True
listener_called.set()

app.assistant(assistant)

request = BoltRequest(body=thread_started_event_body, mode="socket_mode")
response = app.dispatch(request)
assert response.status == 200
assert_target_called(called)
assert listener_called.wait(timeout=0.1) is True
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧪 praise: This builds nice confidence to me! TIL about event threading too!

response = app.dispatch(request)
assert response.status == 404
assert called["value"] is False
assert listener_called.wait(timeout=0.1) is False
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤓 praise: This is a nice pattern too!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants