Minimal Mockable Clock Implementation#81
Conversation
1f8d717 to
b3b6fc1
Compare
|
Hi @da2ce7 , I was looking through your PR and was wondering what the use of |
|
Hello @WarmBeer ,
The stopped clock is an extension of the working clock, implementing the ´Time` trait, but also implementing the ´StoppedTime´ trait. This clock is for testing purposes (or could possibly be used for time stamping), where the time can be mocked. |
|
Hello @WarmBeer @josecelano , I've updated this clock with an minimal implementation of the connection cookie with test that make use of the clock's time mocking features. I think that this basic implementation could serve as a good basis for further improvement. (i.e, It is just the basic hashing algorithm as suggested by Mick, using the build-in default hasher.). |
2ec2723 to
23b241b
Compare
| #[macro_use] | ||
| extern crate lazy_static; | ||
|
|
||
| pub mod static_time { |
There was a problem hiding this comment.
@da2ce7 I think I would call it time_log or time_events if the idea is to statically keep track of when some events happen in the app. It happens to be "static" but I think that's an implementation detail. It could be a service.
src/lib.rs
Outdated
| } | ||
| } | ||
|
|
||
| pub mod static_keys { |
There was a problem hiding this comment.
@da2ce7 for the same reason, I would call it generic_keys or something like that. Unless in this case static means they do not change. I think it would be better to explain what they are used for instead of their immutability property.
| #[macro_use] | ||
| extern crate lazy_static; | ||
|
|
||
| pub mod static_time { |
There was a problem hiding this comment.
I know this is a small mod, but I tend to prefer creating a new independent mod instead of using the generic lib. For me, it's very helpful to check the dir tree when I'm trying to understand a new project.
51e7c27 to
9b433dc
Compare
|
ACK cab093c |
This is a new clock that lends itself for easier testing, it as two forms: the working clock, that tracks the system time; and the stopped clock that is paused, and must be manually set on a thread-local basis.
When testing, the stopped clock is set to zero, or implicitly the unix epoch. When not testing the default value of the stopped clock is the time that the application was started.