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

Added async delay and checked delay #104

Merged
merged 9 commits into from
Feb 3, 2024
Merged

Conversation

Artur-Romaniuk
Copy link
Contributor

Delay lacked async implementation.

Needed it for my test so I added it.

Copy link
Owner

@dbrgn dbrgn left a comment

Choose a reason for hiding this comment

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

Thanks! I left two comments.

src/eh1/delay.rs Outdated Show resolved Hide resolved
src/eh1/delay.rs Show resolved Hide resolved
@dbrgn dbrgn added the enhancement New feature or request label Dec 27, 2023
@Artur-Romaniuk Artur-Romaniuk changed the title Added async delay Added async delay and checked delay Dec 28, 2023
@Artur-Romaniuk
Copy link
Contributor Author

@dbrgn Fixed raised issues.

At the same time, the existing implementations weren't actually mocks, rather stubs. I added a new delay instance called CheckedDelay which is a proper mock with transactions.

@dbrgn
Copy link
Owner

dbrgn commented Jan 10, 2024

Hi @Artur-Romaniuk, thanks for the update! I improved the module documentation and pushed a commit directly to your fork, I hope that's OK. I'll also rebase the branch against main, because there we changed the testing configuration (causing the tests to fail right now).

@dbrgn
Copy link
Owner

dbrgn commented Jan 10, 2024

I'm really confused why the doc tests fail in CI... They work without any issues locally 😕 I'll try to investigate another day (but any pointers would be welcome).

By the way, @Artur-Romaniuk, I noticed that you used a different e-mail for the first commit compared to the others. If this was a mistake, now you could still fix it using git rebase 🙂

@Artur-Romaniuk
Copy link
Contributor Author

Happy to see your changes. Will look at it tomorrow.

src/eh1/delay.rs Show resolved Hide resolved
src/eh1/delay.rs Show resolved Hide resolved
- simplified impl to use only Ns delays
- now default delay is accepting blocking and async
@tommy-gilligan
Copy link
Contributor

Love that you've added a checked delay. This was something I needed so I came up with my own one of those (not as good ofc).

Not really that relevant to this PR but something minor and relevant enough that I figure I should bring it up here:
In looking at delay.rs on main I saw that currently methods with default implementations are being overridden. AFAICT only delay_ns needs to be implemented. I'm wondering if there's a good reason to override delay_ms/delay_us @dbrgn

Looking forward to this being merged. Let me know if there is any way in which I can help.

Copy link
Owner

@dbrgn dbrgn left a comment

Choose a reason for hiding this comment

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

Thanks for the updates, @Artur-Romaniuk! I think the simplification with the nanosecond-only delay has improved the readability a lot!

I left some more comments. I hope that was the last round of review.

(Note to self: When merging, we should use squash mode.)

src/eh1/delay.rs Outdated Show resolved Hide resolved
src/eh1/delay.rs Outdated Show resolved Hide resolved
src/eh1/delay.rs Outdated Show resolved Hide resolved
src/eh1/delay.rs Outdated Show resolved Hide resolved
src/eh1/delay.rs Outdated Show resolved Hide resolved
@dbrgn
Copy link
Owner

dbrgn commented Feb 1, 2024

Not really that relevant to this PR but something minor and relevant enough that I figure I should bring it up here:
In looking at delay.rs on main I saw that currently methods with default implementations are being overridden. AFAICT only delay_ns needs to be implemented. I'm wondering if there's a good reason to override delay_ms/delay_us @dbrgn

I think you are right, thanks for bringing this up! @Artur-Romaniuk could you test if everything keeps working if you remove those potentially unneeded overrides?

@Artur-Romaniuk
Copy link
Contributor Author

Not really that relevant to this PR but something minor and relevant enough that I figure I should bring it up here:
In looking at delay.rs on main I saw that currently methods with default implementations are being overridden. AFAICT only delay_ns needs to be implemented. I'm wondering if there's a good reason to override delay_ms/delay_us @dbrgn

I think you are right, thanks for bringing this up! @Artur-Romaniuk could you test if everything keeps working if you remove those potentially unneeded overrides?

I think there is a valid reason for doing it this way.
The way the std version is implemented with default implementations is that they call the delay_ns function for N amount of times in order to achieve us or ms. This means, that the mock would only receive delay_ns calls.

In that case, mock would have to add N expectations of delay_ns for each call of delay_ms. Not only does it complicate the expectation addition logic, but also expectation verification becomes much harder.
Look at this example:

delay_ms(5);
// do something
delay_ns(10);

using defaults, this would equate to

for(some N amount of times){
   delay_ns(MAX_NS);
} 
delay_ns(5 * NANOS_PER_MILI - N*MAX_NS);
// do something
delay_ns(10);

I believe the current impl is the easiest one and there is no benefit in using default impl.

@dbrgn
Copy link
Owner

dbrgn commented Feb 3, 2024

I think there is a valid reason for doing it this way. (...)

You are right, thanks for your explanation!

Copy link
Owner

@dbrgn dbrgn left a comment

Choose a reason for hiding this comment

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

I think this is now good to merge! Thanks @Artur-Romaniuk for your patience!

@dbrgn dbrgn merged commit e01d736 into dbrgn:main Feb 3, 2024
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants