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

Minimal Mockable Clock Implementation #81

Merged
merged 2 commits into from
Sep 14, 2022
Merged

Conversation

da2ce7
Copy link
Contributor

@da2ce7 da2ce7 commented Sep 9, 2022

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.

@da2ce7 da2ce7 marked this pull request as ready for review September 9, 2022 20:40
@da2ce7 da2ce7 changed the title Draft: New Clock New Clock Sep 9, 2022
@da2ce7 da2ce7 force-pushed the new-clock branch 2 times, most recently from 1f8d717 to b3b6fc1 Compare September 10, 2022 10:56
@da2ce7 da2ce7 marked this pull request as draft September 10, 2022 13:41
@da2ce7 da2ce7 marked this pull request as ready for review September 10, 2022 17:53
@mickvandijke
Copy link
Member

mickvandijke commented Sep 11, 2022

Hi @da2ce7 ,

I was looking through your PR and was wondering what the use of StoppedClock was. Is it just a timestamp? Is it a WorkingClock, but with fixed time?

@da2ce7
Copy link
Contributor Author

da2ce7 commented Sep 11, 2022

Hello @WarmBeer ,

I was looking through your PR and was wondering what the use of StoppedClock was. Is it just a timestamp? Is it a WorkingClock, but with fixed time?

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.

@da2ce7
Copy link
Contributor Author

da2ce7 commented Sep 11, 2022

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.).

@da2ce7 da2ce7 force-pushed the new-clock branch 2 times, most recently from 2ec2723 to 23b241b Compare September 12, 2022 00:00
@da2ce7 da2ce7 changed the title New Clock New Clock and basic Connection Cookie Implmentation Sep 12, 2022
@da2ce7 da2ce7 changed the title New Clock and basic Connection Cookie Implmentation New Clock and Basic Connection Cookie Implmentation Sep 12, 2022
#[macro_use]
extern crate lazy_static;

pub mod static_time {
Copy link
Member

Choose a reason for hiding this comment

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

@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 {
Copy link
Member

Choose a reason for hiding this comment

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

@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 {
Copy link
Member

Choose a reason for hiding this comment

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

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.

src/protocol/clock.rs Outdated Show resolved Hide resolved
src/udp/connection_cookie.rs Outdated Show resolved Hide resolved
src/udp/connection_cookie.rs Outdated Show resolved Hide resolved
src/udp/connection_cookie.rs Outdated Show resolved Hide resolved
src/udp/connection_cookie.rs Outdated Show resolved Hide resolved
src/udp/connection_cookie.rs Outdated Show resolved Hide resolved
@da2ce7 da2ce7 force-pushed the new-clock branch 3 times, most recently from 51e7c27 to 9b433dc Compare September 12, 2022 23:16
@da2ce7 da2ce7 changed the title New Clock and Basic Connection Cookie Implmentation Minimal Mockable Clock Implmentation Sep 12, 2022
@da2ce7 da2ce7 changed the title Minimal Mockable Clock Implmentation Minimal Mockable Clock Implementation Sep 12, 2022
@da2ce7
Copy link
Contributor Author

da2ce7 commented Sep 14, 2022

ACK cab093c

@da2ce7 da2ce7 merged commit 5870954 into torrust:develop Sep 14, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

Refactor: re-implement connection id for UDP tracker
3 participants