From d8d3a43abdc8b6038fb169da9e211b2a61914cb7 Mon Sep 17 00:00:00 2001 From: nazeh Date: Tue, 30 Jul 2024 13:46:04 +0300 Subject: [PATCH] chore: fix tests in ci --- .github/workflows/rust.yaml | 24 +++++++++++++----------- pubky-homeserver/src/config.rs | 33 +++++++++++++++++++++++++-------- pubky-homeserver/src/main.rs | 17 +++++------------ pubky-homeserver/src/server.rs | 1 - pubky/src/native.rs | 2 +- pubky/src/shared/pkarr.rs | 8 +------- 6 files changed, 45 insertions(+), 40 deletions(-) diff --git a/.github/workflows/rust.yaml b/.github/workflows/rust.yaml index eca9a84..85357b4 100644 --- a/.github/workflows/rust.yaml +++ b/.github/workflows/rust.yaml @@ -36,6 +36,7 @@ jobs: restore-keys: | ${{ runner.os }}-cargo-index- - name: Cache cargo build + id: cargo-build-cache uses: actions/cache@v2 with: path: target @@ -54,20 +55,21 @@ jobs: cargo install cargo-nextest fi - # - name: Check no default features - # run: cargo check --no-default-features + - name: Check no default features + run: cargo check --no-default-features - # - name: Check formatting - # run: cargo fmt -- --check + - name: Check formatting + run: cargo fmt -- --check - # - name: Lint with Clippy - # run: cargo clippy --workspace --all-features --bins --tests + - name: Lint with Clippy + run: cargo clippy --workspace --all-features --bins --tests - # - name: Build - # run: cargo build --release --workspace --all-features --verbose + - name: Build + if: steps.cargo-build-cache.outputs.cache-hit != 'true' + run: cargo build --release --workspace --all-features --verbose - name: Run tests with Nextest - run: cargo nextest run homeserver_in_tokio + run: cargo nextest run --all-features --workspace --verbose - # - name: Run docs - # run: cargo doc --workspace --all-features --no-deps --document-private-items --verbose + - name: Run docs + run: cargo doc --workspace --all-features --no-deps --document-private-items --verbose diff --git a/pubky-homeserver/src/config.rs b/pubky-homeserver/src/config.rs index 2136e0c..25fbc66 100644 --- a/pubky-homeserver/src/config.rs +++ b/pubky-homeserver/src/config.rs @@ -16,15 +16,14 @@ const DEFAULT_STORAGE_DIR: &str = "pubky"; Clone, )] pub struct Config { - pub port: Option, - pub bootstrap: Option>, - pub domain: String, + port: Option, + bootstrap: Option>, + domain: String, /// Path to the storage directory /// /// Defaults to a directory in the OS data directory - pub storage: Option, - pub keypair: Keypair, - pub request_timeout: Option, + storage: Option, + keypair: Keypair, } impl Config { @@ -37,6 +36,26 @@ impl Config { // Ok(config) // } + /// Testnet configurations + pub fn testnet() -> Self { + let testnet = pkarr::mainline::Testnet::new(10); + + let bootstrap = Some(testnet.bootstrap.to_owned()); + let storage = Some( + std::env::temp_dir() + .join(Timestamp::now().to_string()) + .join(DEFAULT_STORAGE_DIR), + ); + + Self { + bootstrap, + storage, + port: Some(15411), + keypair: Keypair::from_secret_key(&[0_u8; 32]), + ..Default::default() + } + } + /// Test configurations pub fn test(testnet: &pkarr::mainline::Testnet) -> Self { let bootstrap = Some(testnet.bootstrap.to_owned()); @@ -49,7 +68,6 @@ impl Config { Self { bootstrap, storage, - request_timeout: Some(Duration::from_millis(10)), ..Default::default() } } @@ -93,7 +111,6 @@ impl Default for Config { domain: "localhost".to_string(), storage: None, keypair: Keypair::random(), - request_timeout: None, } } } diff --git a/pubky-homeserver/src/main.rs b/pubky-homeserver/src/main.rs index e45cf3d..2a17bda 100644 --- a/pubky-homeserver/src/main.rs +++ b/pubky-homeserver/src/main.rs @@ -1,5 +1,4 @@ use anyhow::Result; -use pkarr::{mainline::Testnet, Keypair}; use pubky_homeserver::{config::Config, Homeserver}; use clap::Parser; @@ -24,18 +23,12 @@ async fn main() -> Result<()> { ) .init(); - let server = if args.testnet { - let testnet = Testnet::new(10); - - Homeserver::start(Config { - port: Some(15411), - keypair: Keypair::from_secret_key(&[0_u8; 32]), - ..Config::test(&testnet) - }) - .await? + let server = Homeserver::start(if args.testnet { + Config::testnet() } else { - Homeserver::start(Default::default()).await? - }; + Default::default() + }) + .await?; server.run_until_done().await?; diff --git a/pubky-homeserver/src/server.rs b/pubky-homeserver/src/server.rs index 12d497c..9837ed9 100644 --- a/pubky-homeserver/src/server.rs +++ b/pubky-homeserver/src/server.rs @@ -39,7 +39,6 @@ impl Homeserver { let pkarr_client = PkarrClient::new(Settings { dht: DhtSettings { bootstrap: config.bootstsrap(), - request_timeout: config.request_timeout, ..Default::default() }, ..Default::default() diff --git a/pubky/src/native.rs b/pubky/src/native.rs index b63c844..a2afea0 100644 --- a/pubky/src/native.rs +++ b/pubky/src/native.rs @@ -44,7 +44,7 @@ impl PubkyClient { .unwrap(), pkarr: PkarrClient::new(Settings { dht: DhtSettings { - request_timeout: Some(Duration::from_millis(10)), + request_timeout: Some(Duration::from_millis(100)), bootstrap: Some(testnet.bootstrap.to_owned()), ..DhtSettings::default() }, diff --git a/pubky/src/shared/pkarr.rs b/pubky/src/shared/pkarr.rs index f35ce5c..c0a800e 100644 --- a/pubky/src/shared/pkarr.rs +++ b/pubky/src/shared/pkarr.rs @@ -139,17 +139,11 @@ mod tests { use pkarr::{ dns::{rdata::SVCB, Packet}, - mainline::{dht::DhtSettings, Testnet}, + mainline::{dht::DhtSettings, Dht, Testnet}, Keypair, PkarrClient, Settings, SignedPacket, }; use pubky_homeserver::Homeserver; - #[tokio::test] - fn homeserver_in_tokio() { - let testnet = Testnet::new(10); - let server = Homeserver::start_test(&testnet).await.unwrap(); - } - #[tokio::test] async fn resolve_homeserver() { let testnet = Testnet::new(10);