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

refactor: [#682] handle UDP Tracker timeouts #827

Closed
wants to merge 1 commit into from

Conversation

hungfnt
Copy link
Contributor

@hungfnt hungfnt commented May 3, 2024

I don't know how to simulate the timeout yet.

Copy link

codecov bot commented May 3, 2024

Codecov Report

Attention: Patch coverage is 0% with 4 lines in your changes are missing coverage. Please review.

Project coverage is 78.61%. Comparing base (3c78bba) to head (2a8a15d).

Files Patch % Lines
src/shared/bit_torrent/tracker/udp/client.rs 0.00% 4 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           develop     #827      +/-   ##
===========================================
- Coverage    78.83%   78.61%   -0.23%     
===========================================
  Files          169      169              
  Lines         9341     9225     -116     
===========================================
- Hits          7364     7252     -112     
+ Misses        1977     1973       -4     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@josecelano josecelano linked an issue May 3, 2024 that may be closed by this pull request
@josecelano
Copy link
Member

I don't know how to simulate the timeout yet.

Hi @ngthhu, for receiving data from the socket:

let size_result = match time::timeout(self.timeout, self.socket.recv(bytes)).await {
    Ok(recv_result) => match recv_result {
        Ok(size) => Ok(size),
        Err(e) => Err(anyhow!("IO error during send: {e:?}")),
    },
    Err(_) => bail!(ClientError::ConnectionTimeout),
};

You can manually test just by running the tracker with a delay (thread sleep) in the handler.

For other timeouts, like waiting for the socket to be writable, I do not have any idea either. I would probably try to write unit tests mocking the UdpSocket. I'm writting articles about testing in Rust.

The problem is testing time-related stuff is hard and slow. We could research how to do it properly. I don't like having tests that have to "wait" to test functionality, even if we set a short timeout for testing.

@josecelano josecelano added the Needs Rebase Base Branch has Incompatibilities label May 7, 2024
@josecelano
Copy link
Member

Hi @ngthhu, @da2ce7 was also working on adding timeouts to the UDP client.

Regarding how to test this code. I have not thought about it yet but I have the impression that we will need:

  • To mock the time and timeout.
  • Be able to set each timeout with different values. SO we can assign high values for the ones we don't want to test and a low value for the timeout we want to capture.

I've also found this post about this topic:

https://ditto.live/blog/mocking-time-in-async-rust

@da2ce7
Copy link
Contributor

da2ce7 commented Jul 13, 2024

closed as stale.

@da2ce7 da2ce7 closed this Jul 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs Rebase Base Branch has Incompatibilities
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Tracker Checker: handle UDP Tracker timeouts
3 participants