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

tests: added unit test in fedimint-core/src/runtime.rs #5141

Conversation

sivasathyaseeelan
Copy link
Contributor

Fix

This PR adds unit test fin fedimint/fedimint-core/src/runtime.rs and closes #5140

Signed-off-by: sivasathyaseeelan <dnsiva.sathyaseelan.chy21@iitbhu.ac.in>
@sivasathyaseeelan sivasathyaseeelan requested a review from a team as a code owner April 27, 2024 20:41
Copy link
Contributor

@dpc dpc left a comment

Choose a reason for hiding this comment

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

Please don't use sleep, or at least not with 1 second values. CI time is a scarce resource. Where you really need to guarantee sleep, maybe use 1 millisecond. where you need coordination between threads use https://docs.rs/tokio/latest/tokio/sync/oneshot/index.html to unblock things.

Signed-off-by: sivasathyaseeelan <dnsiva.sathyaseelan.chy21@iitbhu.ac.in>
@sivasathyaseeelan sivasathyaseeelan requested a review from dpc May 1, 2024 23:07
@sivasathyaseeelan
Copy link
Contributor Author

Please don't use sleep, or at least not with 1 second values. CI time is a scarce resource. Where you really need to guarantee sleep, maybe use 1 millisecond. where you need coordination between threads use https://docs.rs/tokio/latest/tokio/sync/oneshot/index.html to unblock things.

Hi @dpc, I have changed from 1 second to 1 millisecond. Can you please review this pr again?

Signed-off-by: sivasathyaseeelan <dnsiva.sathyaseelan.chy21@iitbhu.ac.in>
@sivasathyaseeelan sivasathyaseeelan requested a review from dpc May 2, 2024 10:15
assert!(result.is_ok());
}
_ = rx => {
assert!(false, "Timeout occurred before future completed");
Copy link
Contributor

Choose a reason for hiding this comment

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

assert(false is just panic!, AFAIK.

async fn test_timeout_elapsed() {
let duration = Duration::from_millis(1);
let future = async {
tokio::time::sleep(duration * 2).await;
Copy link
Contributor

Choose a reason for hiding this comment

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

std::future::pending().await can be used if you just want to test timeout

async fn test_sleep() {
let duration = Duration::from_millis(1);
let start = Instant::now();
sleep(duration).await;
Copy link
Contributor

Choose a reason for hiding this comment

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

Meh. This might be a test in tokio, it doesn't test our code really.

let future = async move {
// Simulating some work
tokio::time::sleep(Duration::from_millis(1)).await;
let _ = tx.send("done");
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't understand what this test is trying to test.

But probably the future should be only rx.recv();

Then spawn that future as a task, then tx.send() to unblock it, then await on the result.

};

tokio::select! {
result = timeout(duration, future) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Here also, timeout, sleep, everything seems to be outside code, so I don't understand what we're testing.

My point with oneshot channels was that rx.recv() can be used as sleep, that you can "wake up" from anywhere with tx.send() thus guaranteeing order of operations, instead of relying on sleeps waiting up in a given sequence (which is never really guranteed).

Copy link
Member

@maan2003 maan2003 left a comment

Choose a reason for hiding this comment

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

native code for runtime module is mostly uninteresting.

wasm code has some logic, that might be good to test.

@dpc
Copy link
Contributor

dpc commented May 24, 2024

Closing. Feel free to reopen with improvements or just create a different PR.

@dpc dpc closed this May 24, 2024
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.

tests: missing unit test in fedimint/fedimint-core/src/runtime.rs
3 participants