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

TtlCache and testing #20

Open
vi opened this issue Jan 30, 2020 · 3 comments
Open

TtlCache and testing #20

vi opened this issue Jan 30, 2020 · 3 comments

Comments

@vi
Copy link

vi commented Jan 30, 2020

As far as I undestand, TtlCache use std::time::{Duration, Instant} without any indirection layer.

This makes it trickier to [unit-]test the code without waiting.

Shall there be some additional testing version of TtlCache that has overridable timer?

@stusmall
Copy link
Owner

stusmall commented Feb 6, 2020

Great point. I'll look into doing this. Do you have any thoughts on what you would like the general API to look like?

@stusmall
Copy link
Owner

stusmall commented Feb 8, 2020

I was thinking about this. I think I might implement this as a generic type parameter. By default it will be an implementation that directly calls Duration/Instant but a user may optionally implement a struct that can mock it out.

Before I make my own trait, do you know of any good crates that define the abstraction? I'd rather just pull in something other people are already using.

@lerouxrgd
Copy link

I usually find that fake_clock is a nice solution if you can apply it to your use-case.

This blog post is a good example of 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

No branches or pull requests

3 participants