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

Add tests for new stat events #1177

Open
josecelano opened this issue Jan 9, 2025 · 0 comments
Open

Add tests for new stat events #1177

josecelano opened this issue Jan 9, 2025 · 0 comments
Labels
- Developer - Torrust Improvement Experience Testing Checking Torrust

Comments

@josecelano
Copy link
Member

New metrics have been added but some of them do not have a test.

A test for another event Event::Udp4Connect:

#[tokio::test]
async fn it_should_send_the_upd4_connect_event_when_a_client_tries_to_connect_using_a_ip4_socket_address() {
    let mut stats_event_sender_mock = statistics::event::sender::MockSender::new();
    stats_event_sender_mock
        .expect_send_event()
        .with(eq(statistics::event::Event::Udp4Connect))
        .times(1)
        .returning(|_| Box::pin(future::ready(Some(Ok(())))));
    let stats_event_sender = Box::new(stats_event_sender_mock);

    let client_socket_address = sample_ipv4_socket_address();

    let torrent_tracker = Arc::new(
        core::Tracker::new(
            &tracker_configuration().core,
            Some(stats_event_sender),
            statistics::repository::Repository::new(),
        )
        .unwrap(),
    );
    handle_connect(
        client_socket_address,
        &sample_connect_request(),
        &torrent_tracker,
        sample_issue_time(),
    )
    .await;
}

Only these events are covered:

  • Udp4Connect
  • Udp6Connect
  • Udp4Announce
  • Udp6Announce
  • Udp4Scrape
  • Udp6Scrape

And these are all the events:

pub enum Event {
    Tcp4Announce, // Covered
    Tcp4Scrape, // Covered
    Tcp6Announce, // Covered
    Tcp6Scrape, // Covered
    UdpRequestAborted,
    UdpRequestBanned,
    Udp4Request,
    Udp4Connect, // Covered
    Udp4Announce, // Covered
    Udp4Scrape, // Covered
    Udp4Response {
        kind: UdpResponseKind,
        req_processing_time: Duration,
    },
    Udp4Error,
    Udp6Request,
    Udp6Connect, // Covered
    Udp6Announce, // Covered
    Udp6Scrape, // Covered
    Udp6Response {
        kind: UdpResponseKind,
        req_processing_time: Duration,
    },
    Udp6Error,
}
@josecelano josecelano added Testing Checking Torrust - Developer - Torrust Improvement Experience labels Jan 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
- Developer - Torrust Improvement Experience Testing Checking Torrust
Projects
None yet
Development

No branches or pull requests

1 participant