Skip to content

Commit

Permalink
Merge #1324: Refactor packages: move integration tests to packages
Browse files Browse the repository at this point in the history
3f50803 tests: scaffolding for integration tests (Jose Celano)
f233dd2 refactor: remove unsued dependencies from the main Cargo.toml (Jose Celano)
c34c8bc refactor: [#1316] remove unsued code (Jose Celano)
60c5826 refactor: remove duplicate test (Jose Celano)
f783dbd refactor: [#1316] move the rest of the Health Check API integration tests to the server pkg (Jose Celano)
1aef0c1 refactor: [#1316] move HTTP tracker integration tests to pkg (Jose Celano)
92505b9 refactor: [#1316] UDP tracker integration tests to pkg (Jose Celano)
08efc3b refactor: [#1316] move tracker API integration tests to pkg (Jose Celano)
a841e03 refactor: [#1316] move health check API integration tests to pkg (Jose Celano)

Pull request description:

  Refactor packages: move integration tests to packages.

  - [x] Move Health Check API integration tests to the server package (`axum-health-check-api-server`).
  - [x] Move Tracker API integration tests to the server package (`axum-tracker-api-server`).
  - [x] Move UDP Tracker integration tests to the server package (`udp-tracker-server`).
  - [x] Move HTTP Tracker integration tests to the server package (`axum-http-tracker-server`).

ACKs for top commit:
  josecelano:
    ACK 3f50803

Tree-SHA512: 21e6dc8bca036f2d90062032e7fc6b714069b792eb529ddf6784ff071dbfc41ca21953c6ea44e361bdaf4d19ddb96fc8f6c1c091b796c00eae2104d0504a78ed
  • Loading branch information
josecelano committed Feb 25, 2025
2 parents c248caf + 3f50803 commit e437f63
Show file tree
Hide file tree
Showing 69 changed files with 430 additions and 324 deletions.
41 changes: 22 additions & 19 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 0 additions & 32 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,32 +34,18 @@ version = "3.0.0-develop"

[dependencies]
anyhow = "1"
aquatic_udp_protocol = "0"
axum-server = { version = "0", features = ["tls-rustls-no-provider"] }
bittorrent-http-tracker-core = { version = "3.0.0-develop", path = "packages/http-tracker-core" }
bittorrent-primitives = "0.1.0"
bittorrent-tracker-client = { version = "3.0.0-develop", path = "packages/tracker-client" }
bittorrent-tracker-core = { version = "3.0.0-develop", path = "packages/tracker-core" }
bittorrent-udp-tracker-core = { version = "3.0.0-develop", path = "packages/udp-tracker-core" }
chrono = { version = "0", default-features = false, features = ["clock"] }
clap = { version = "4", features = ["derive", "env"] }
crossbeam-skiplist = "0"
dashmap = "6"
figment = "0"
futures = "0"
parking_lot = "0"
percent-encoding = "2"
r2d2 = "0"
r2d2_mysql = "25"
r2d2_sqlite = { version = "0", features = ["bundled"] }
rand = "0"
regex = "1"
reqwest = { version = "0", features = ["json"] }
serde = { version = "1", features = ["derive"] }
serde_bencode = "0"
serde_bytes = "0"
serde_json = { version = "1", features = ["preserve_order"] }
serde_repr = "0"
tokio = { version = "1", features = ["macros", "net", "rt-multi-thread", "signal", "sync"] }
torrust-axum-health-check-api-server = { version = "3.0.0-develop", path = "packages/axum-health-check-api-server" }
torrust-axum-http-tracker-server = { version = "3.0.0-develop", path = "packages/axum-http-tracker-server" }
Expand All @@ -69,27 +55,9 @@ torrust-server-lib = { version = "3.0.0-develop", path = "packages/server-lib" }
torrust-tracker-api-core = { version = "3.0.0-develop", path = "packages/tracker-api-core" }
torrust-tracker-clock = { version = "3.0.0-develop", path = "packages/clock" }
torrust-tracker-configuration = { version = "3.0.0-develop", path = "packages/configuration" }
torrust-tracker-primitives = { version = "3.0.0-develop", path = "packages/primitives" }
torrust-tracker-torrent-repository = { version = "3.0.0-develop", path = "packages/torrent-repository" }
torrust-udp-tracker-server = { version = "3.0.0-develop", path = "packages/udp-tracker-server" }
tracing = "0"
tracing-subscriber = { version = "0", features = ["json"] }
url = { version = "2", features = ["serde"] }
uuid = { version = "1", features = ["v4"] }
zerocopy = "0.7"

[package.metadata.cargo-machete]
ignored = [
"crossbeam-skiplist",
"dashmap",
"figment",
"parking_lot",
"r2d2",
"r2d2_mysql",
"r2d2_sqlite",
"serde_bytes",
"torrust-tracker-torrent-repository",
]

[dev-dependencies]
local-ip-address = "0"
Expand Down
9 changes: 9 additions & 0 deletions packages/axum-health-check-api-server/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,16 @@ serde_json = { version = "1", features = ["preserve_order"] }
tokio = { version = "1", features = ["macros", "net", "rt-multi-thread", "signal", "sync"] }
torrust-axum-server = { version = "3.0.0-develop", path = "../axum-server" }
torrust-server-lib = { version = "3.0.0-develop", path = "../server-lib" }
torrust-tracker-configuration = { version = "3.0.0-develop", path = "../configuration" }
tower-http = { version = "0", features = ["compression-full", "cors", "propagate-header", "request-id", "trace"] }
tracing = "0"

[dev-dependencies]
reqwest = { version = "0", features = ["json"] }
torrust-axum-health-check-api-server = { version = "3.0.0-develop", path = "../axum-health-check-api-server" }
torrust-axum-http-tracker-server = { version = "3.0.0-develop", path = "../axum-http-tracker-server" }
torrust-axum-tracker-api-server = { version = "3.0.0-develop", path = "../axum-tracker-api-server" }
torrust-tracker-clock = { version = "3.0.0-develop", path = "../clock" }
torrust-tracker-test-helpers = { version = "3.0.0-develop", path = "../test-helpers" }
torrust-udp-tracker-server = { version = "3.0.0-develop", path = "../udp-tracker-server" }
tracing-subscriber = { version = "0", features = ["json"] }
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@ use std::sync::Arc;

use tokio::sync::oneshot::{self, Sender};
use tokio::task::JoinHandle;
use torrust_axum_health_check_api_server::{server, HEALTH_CHECK_API_LOG_TARGET};
use torrust_server_lib::registar::Registar;
use torrust_server_lib::signals::{self, Halted, Started};
use torrust_server_lib::signals::{self, Halted as SignalHalted, Started as SignalStarted};
use torrust_tracker_configuration::HealthCheckApi;

use crate::{server, HEALTH_CHECK_API_LOG_TARGET};

pub type Started = Environment<Running>;

#[derive(Debug)]
pub enum Error {
#[allow(dead_code)]
Expand All @@ -30,6 +33,7 @@ pub struct Environment<S> {
}

impl Environment<Stopped> {
#[must_use]
pub fn new(config: &Arc<HealthCheckApi>, registar: Registar) -> Self {
let bind_to = config.bind_address;

Expand All @@ -41,9 +45,13 @@ impl Environment<Stopped> {

/// Start the test environment for the Health Check API.
/// It runs the API server.
///
/// # Panics
///
/// Will panic if it cannot start the service in a spawned task.
pub async fn start(self) -> Environment<Running> {
let (tx_start, rx_start) = oneshot::channel::<Started>();
let (tx_halt, rx_halt) = tokio::sync::oneshot::channel::<Halted>();
let (tx_start, rx_start) = oneshot::channel::<SignalStarted>();
let (tx_halt, rx_halt) = tokio::sync::oneshot::channel::<SignalHalted>();

let register = self.registar.entries();

Expand Down Expand Up @@ -81,10 +89,17 @@ impl Environment<Running> {
Environment::<Stopped>::new(config, registar).start().await
}

/// # Errors
///
/// Will return an error if it cannot send the halt signal.
///
/// # Panics
///
/// Will panic if it cannot shutdown the service.
pub async fn stop(self) -> Result<Environment<Stopped>, Error> {
self.state
.halt_task
.send(Halted::Normal)
.send(SignalHalted::Normal)
.map_err(|e| Error::Error(e.to_string()))?;

let bind_to = self.state.task.await.expect("it should shutdown the service");
Expand Down
1 change: 1 addition & 0 deletions packages/axum-health-check-api-server/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
pub mod environment;
pub mod handlers;
pub mod resources;
pub mod responses;
Expand Down
19 changes: 19 additions & 0 deletions packages/axum-health-check-api-server/tests/integration.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//! Integration tests.
//!
//! ```text
//! cargo test --test integration
//! ```
mod server;

use torrust_tracker_clock::clock;

/// This code needs to be copied into each crate.
/// Working version, for production.
#[cfg(not(test))]
#[allow(dead_code)]
pub(crate) type CurrentClock = clock::Working;

/// Stopped version, for testing.
#[cfg(test)]
#[allow(dead_code)]
pub(crate) type CurrentClock = clock::Stopped;
File renamed without changes.
Loading

0 comments on commit e437f63

Please sign in to comment.