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

chore: use sleep_in_test over sleep in tests #4376

Merged
merged 1 commit into from
Feb 21, 2024

Conversation

kernelkind
Copy link
Contributor

The function fedimint_core::task::sleep_in_test should be used over fedimint_core::task::sleep in tests so the duration of the sleep and a comment describing the reason for sleeping can be logged.

Closes: #1792

@kernelkind kernelkind marked this pull request as ready for review February 20, 2024 18:57
@kernelkind kernelkind requested a review from a team as a code owner February 20, 2024 18:57
The function fedimint_core::task::sleep_in_test should be used over
fedimint_core::task::sleep in tests so the duration of the sleep and a
comment describing the reason for sleeping can be logged.

Closes: fedimint#1792
@@ -617,6 +617,19 @@ impl<T: Sync> MaybeSync for T {}
#[cfg(target_family = "wasm")]
impl<T> MaybeSync for T {}

// Used in tests when sleep functionality is desired so it can be logged.
// Must include comment describing the reason for sleeping.
pub async fn sleep_in_test(comment: impl AsRef<str>, duration: Duration) {
Copy link
Member

@maan2003 maan2003 Feb 21, 2024

Choose a reason for hiding this comment

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

better to use tracing::Span instead of str comment

Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't comment be reason, and just another value with a fixed "Sleep" message? Or are there any other benefits? I'm not even sure how to do Span :D

Copy link
Member

Choose a reason for hiding this comment

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

Span just lets you express variables better instead of using format!. also spans have parent-child relation.

something like this

async move {
    info!(target: LOG_TEST, ?duration, "sleeping");
    sleep(duration).await;
}.instrument(span).await

Copy link
Member

Choose a reason for hiding this comment

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

caller is expected to use info_span! or debug_span! to create spans

Copy link
Contributor

Choose a reason for hiding this comment

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

Is it useful to create a new span just for a sleep? I guess if you already have one it's nice, but what would one gain from adding it here otherwise?

@@ -617,6 +617,19 @@ impl<T: Sync> MaybeSync for T {}
#[cfg(target_family = "wasm")]
impl<T> MaybeSync for T {}

// Used in tests when sleep functionality is desired so it can be logged.
// Must include comment describing the reason for sleeping.
pub async fn sleep_in_test(comment: impl AsRef<str>, duration: Duration) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it useful to create a new span just for a sleep? I guess if you already have one it's nice, but what would one gain from adding it here otherwise?

@elsirion elsirion added this pull request to the merge queue Feb 21, 2024
Merged via the queue into fedimint:master with commit f808f4b Feb 21, 2024
20 checks passed
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.

Any sleep or wait in tests should be preceeded by log statement
4 participants