Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add testing util to poll for async event testing #758

Merged
merged 14 commits into from
Jun 18, 2024

Conversation

LiranCohen
Copy link
Member

@LiranCohen LiranCohen commented Jun 13, 2024

Due to the async nature of testing EventStream and Subscriptions, and some external pub/sub systems taking a longer time to publish and/or receive a message, we have added a helper method to help wait for a test case to assert.

Additionally we modified the tests to be able to more accurately check negative test cases where testing the absence of something which arrives async could be challenging.

  • pollUntilSuccessOrTimeout will execute a delegate function passed to it, if it fails it will sleep retrySleep ms, and will retry. If the total retry time exceeds timeout, it will finally fail.

@codecov-commenter
Copy link

codecov-commenter commented Jun 13, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 98.62%. Comparing base (94da019) to head (2fea4de).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #758      +/-   ##
==========================================
+ Coverage   98.55%   98.62%   +0.07%     
==========================================
  Files          73       73              
  Lines       10929    10929              
  Branches     1573     1577       +4     
==========================================
+ Hits        10771    10779       +8     
+ Misses        152      144       -8     
  Partials        6        6              

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

@LiranCohen LiranCohen force-pushed the lirancohen/subscription-timing-tests branch from 644acab to e647146 Compare June 13, 2024 23:32
@LiranCohen LiranCohen marked this pull request as ready for review June 14, 2024 17:09
csuwildcat
csuwildcat previously approved these changes Jun 14, 2024
Copy link
Contributor

@thehenrytsai thehenrytsai left a comment

Choose a reason for hiding this comment

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

🐐
The number the tests you have for subscription is astounding!

tests/utils/test-timing-utils.ts Outdated Show resolved Hide resolved
tests/utils/test-timing-utils.ts Outdated Show resolved Hide resolved
tests/test-suite.ts Show resolved Hide resolved
tests/event-log/event-stream.spec.ts Outdated Show resolved Hide resolved
tests/features/author-delegated-grant.spec.ts Outdated Show resolved Hide resolved
tests/handlers/records-subscribe.spec.ts Outdated Show resolved Hide resolved
tests/handlers/records-subscribe.spec.ts Show resolved Hide resolved
tests/event-log/event-stream.spec.ts Outdated Show resolved Hide resolved
@LiranCohen LiranCohen force-pushed the lirancohen/subscription-timing-tests branch from 14ec331 to 35b5986 Compare June 18, 2024 20:28
thehenrytsai
thehenrytsai previously approved these changes Jun 18, 2024
Copy link
Contributor

@thehenrytsai thehenrytsai left a comment

Choose a reason for hiding this comment

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

🚀

Consider renaming the test to "root/context role authorized ..." for clarity in a future PR.

Copy link
Contributor

@thehenrytsai thehenrytsai left a comment

Choose a reason for hiding this comment

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

🐐

@LiranCohen LiranCohen merged commit 5f36efa into main Jun 18, 2024
4 checks passed
@LiranCohen LiranCohen deleted the lirancohen/subscription-timing-tests branch June 18, 2024 22:31
@alanhkarp
Copy link

I needed to test async events on another project. I initially polled to make sure the event had finished, but the tests were taking a long time. Instead, I created a promise in the test code that I resolved in the event handler, and the tests ran 2-3 times faster. I don't know if this approach is appropriate for what you're doing, but I thought I'd mention it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants