From b5d9805f1d67ad2d5e2f0cd183ca54f14d142874 Mon Sep 17 00:00:00 2001 From: "benjamin.747" Date: Thu, 11 Jan 2024 18:44:07 +0800 Subject: [PATCH] add http integration test code --- Cargo.toml | 8 +- gateway/src/api_service/obj_service.rs | 56 +++++- gateway/src/api_service/router.rs | 45 +++-- gateway/src/https_server.rs | 11 +- gateway/src/model/mod.rs | 2 +- .../model/{object_detail.rs => objects.rs} | 0 git/src/internal/pack/counter.rs | 16 +- git/src/internal/pack/mod.rs | 2 +- git/src/protocol/pack.rs | 6 +- p2p/src/node/client_http.rs | 2 +- p2p/src/node/command_handler.rs | 171 ++++++++---------- storage/entity/src/lib.rs | 1 + storage/entity/src/model/mod.rs | 1 + storage/entity/src/model/query_result.rs | 7 + storage/src/driver/database/storage.rs | 47 +++-- tests/common_test/mod.rs | 108 +++++++---- tests/integration_test.rs | 52 ++++-- 17 files changed, 341 insertions(+), 194 deletions(-) rename gateway/src/model/{object_detail.rs => objects.rs} (100%) create mode 100644 storage/entity/src/model/mod.rs create mode 100644 storage/entity/src/model/query_result.rs diff --git a/Cargo.toml b/Cargo.toml index 230db3c5..ae5901e1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -27,7 +27,13 @@ serde = { version = "1.0", features = ["derive"] } [dev-dependencies] -reqwest = "0.11.23" +reqwest = {version = "0.11.23", features = ["stream", "multipart"]} +env_logger = "0.10.1" +futures-util = "0.3.30" +tokio-util = "0.7.10" +go-defer = "0.1.0" +bytes = "1.5.0" + [build-dependencies] shadow-rs = "0.26.0" diff --git a/gateway/src/api_service/obj_service.rs b/gateway/src/api_service/obj_service.rs index 39f16227..ad639d87 100644 --- a/gateway/src/api_service/obj_service.rs +++ b/gateway/src/api_service/obj_service.rs @@ -7,11 +7,13 @@ use axum::{http::StatusCode, response::Response}; use git::internal::object::commit::Commit; use git::internal::object::tree::Tree; use git::internal::object::ObjectT; +use git::internal::pack::counter::GitTypeCounter; use storage::driver::database::storage::ObjectStorage; -use crate::model::object_detail::{BlobObjects, Directories, Item}; +use crate::model::objects::{BlobObjects, Directories, Item}; use crate::model::query::DirectoryQuery; +#[derive(Clone)] pub struct ObjectService { pub storage: Arc, } @@ -140,7 +142,7 @@ impl ObjectService { for item in &mut items { let related_c_id = item.commit_id.clone().unwrap(); let commit = related_c_map.get(&related_c_id).unwrap(); - item.commit_msg = Some(remove_useless_str( + item.commit_msg = Some(utils::remove_useless_str( commit.message.clone(), SIGNATURE_END.to_owned(), )); @@ -171,14 +173,50 @@ impl ObjectService { .unwrap(); Ok(res) } + + pub async fn count_object_num( + &self, + repo_path: &str, + ) -> Result, (StatusCode, String)> { + let query_res = self + .storage + .count_obj_from_commit_and_node(repo_path) + .await + .unwrap(); + let tree = query_res + .iter() + .find(|x| x.node_type == "tree") + .map(|x| x.count) + .unwrap() + .try_into() + .unwrap(); + let blob = query_res + .iter() + .find(|x| x.node_type == "blob") + .map(|x| x.count) + .unwrap() + .try_into() + .unwrap(); + let counter = GitTypeCounter { + commit: 0, + tree, + blob, + tag: 0, + ofs_delta: 0, + ref_delta: 0, + }; + Ok(Json(counter)) + } } -fn remove_useless_str(content: String, remove_str: String) -> String { - if let Some(index) = content.find(&remove_str) { - let filtered_text = &content[index + remove_str.len()..].replace('\n', ""); - let truncated_text = filtered_text.chars().take(50).collect::(); - truncated_text.to_owned() - } else { - "".to_owned() +pub mod utils { + pub(crate) fn remove_useless_str(content: String, remove_str: String) -> String { + if let Some(index) = content.find(&remove_str) { + let filtered_text = &content[index + remove_str.len()..].replace('\n', ""); + let truncated_text = filtered_text.chars().take(50).collect::(); + truncated_text.to_owned() + } else { + "".to_owned() + } } } diff --git a/gateway/src/api_service/router.rs b/gateway/src/api_service/router.rs index 8a01c255..82499610 100644 --- a/gateway/src/api_service/router.rs +++ b/gateway/src/api_service/router.rs @@ -7,53 +7,62 @@ use axum::{ routing::get, Json, Router, }; +use git::internal::pack::counter::GitTypeCounter; use crate::{ api_service::obj_service::ObjectService, model::{ - object_detail::{BlobObjects, Directories}, + objects::{BlobObjects, Directories}, query::DirectoryQuery, }, }; -use crate::AppState; +#[derive(Clone)] +pub struct ApiServiceState { + pub object_service: ObjectService, +} -pub fn routers(state: AppState) -> Router { +pub fn routers(state: ApiServiceState) -> Router { Router::new() .route("/blob", get(get_blob_object)) .route("/tree", get(get_directories)) .route("/object", get(get_origin_object)) + .route("/status", get(life_cycle_check)) + .route("/count-nums", get(get_count_nums)) .with_state(state) } +async fn life_cycle_check() -> Result { + Ok(Json("http ready")) +} + +async fn get_count_nums( + Query(query): Query>, + state: State, +) -> Result, (StatusCode, String)> { + let repo_path = query.get("repo_path").unwrap(); + state.object_service.count_object_num(repo_path).await +} + async fn get_blob_object( Query(query): Query>, - state: State, + state: State, ) -> Result, (StatusCode, String)> { let object_id = query.get("object_id").unwrap(); - let object_service = ObjectService { - storage: state.storage.clone(), - }; - object_service.get_blob_objects(object_id).await + state.object_service.get_blob_objects(object_id).await } async fn get_directories( Query(query): Query, - state: State, + state: State, ) -> Result, (StatusCode, String)> { - let object_service = ObjectService { - storage: state.storage.clone(), - }; - object_service.get_directories(query).await + state.object_service.get_directories(query).await } async fn get_origin_object( Query(query): Query>, - state: State, + state: State, ) -> Result { let object_id = query.get("object_id").unwrap(); - let object_service = ObjectService { - storage: state.storage.clone(), - }; - object_service.get_objects_data(object_id).await + state.object_service.get_objects_data(object_id).await } diff --git a/gateway/src/https_server.rs b/gateway/src/https_server.rs index db6e2cf3..917f239e 100644 --- a/gateway/src/https_server.rs +++ b/gateway/src/https_server.rs @@ -29,6 +29,8 @@ use storage::driver::database; use storage::driver::database::storage::ObjectStorage; use tower_http::trace::TraceLayer; +use crate::api_service::obj_service::ObjectService; +use crate::api_service::router::ApiServiceState; use crate::{api_service, git_protocol, lfs}; #[derive(Args, Clone, Debug)] @@ -92,8 +94,15 @@ pub async fn start_server(options: &HttpOptions) { storage: database::init(data_source).await, options: options.to_owned(), }; + + let api_state = ApiServiceState { + object_service: ObjectService { + storage: state.storage.clone(), + } + }; + let app = Router::new() - .nest("/api/v1", api_service::router::routers(state.clone())) + .nest("/api/v1", api_service::router::routers(api_state)) .route( "/*path", get(get_method_router) diff --git a/gateway/src/model/mod.rs b/gateway/src/model/mod.rs index c0c09559..5b2c04f9 100644 --- a/gateway/src/model/mod.rs +++ b/gateway/src/model/mod.rs @@ -1,2 +1,2 @@ -pub mod object_detail; +pub mod objects; pub mod query; diff --git a/gateway/src/model/object_detail.rs b/gateway/src/model/objects.rs similarity index 100% rename from gateway/src/model/object_detail.rs rename to gateway/src/model/objects.rs diff --git a/git/src/internal/pack/counter.rs b/git/src/internal/pack/counter.rs index 6c3908e4..caf29b90 100644 --- a/git/src/internal/pack/counter.rs +++ b/git/src/internal/pack/counter.rs @@ -1,13 +1,15 @@ use std::fmt::Display; + +use serde::{Serialize, Deserialize}; /// A Counter for counting git object types -#[derive(Default,Clone, Copy)] +#[derive(Default,Clone, Copy, Serialize, Deserialize)] pub struct GitTypeCounter{ - commit:usize, - tree:usize, - blob:usize, - tag:usize, - ofs_delta:usize, - ref_delta:usize, + pub commit:usize, + pub tree:usize, + pub blob:usize, + pub tag:usize, + pub ofs_delta:usize, + pub ref_delta:usize, } impl GitTypeCounter { diff --git a/git/src/internal/pack/mod.rs b/git/src/internal/pack/mod.rs index 49b04676..2cbbe825 100644 --- a/git/src/internal/pack/mod.rs +++ b/git/src/internal/pack/mod.rs @@ -14,7 +14,7 @@ use crate::hash::Hash; use crate::internal::object::ObjectT; mod cache; -mod counter; +pub mod counter; mod cqueue; pub mod decode; pub mod delta; diff --git a/git/src/protocol/pack.rs b/git/src/protocol/pack.rs index d070fc58..973c0f80 100644 --- a/git/src/protocol/pack.rs +++ b/git/src/protocol/pack.rs @@ -391,14 +391,14 @@ pub fn read_pkt_line(bytes: &mut Bytes) -> (usize, Bytes) { return (0, Bytes::new()); } let pkt_length = bytes.copy_to_bytes(4); - let pkt_length = - usize::from_str_radix(&String::from_utf8(pkt_length.to_vec()).unwrap(), 16).unwrap(); - + let pkt_length = usize::from_str_radix(&String::from_utf8(pkt_length.to_vec()).unwrap(), 16) + .unwrap_or_else(|_| panic!("{:?} is not a valid digit?", pkt_length)); if pkt_length == 0 { return (0, Bytes::new()); } // this operation will change the original bytes let pkt_line = bytes.copy_to_bytes(pkt_length - 4); + tracing::debug!("pkt line: {:?}", pkt_line); (pkt_length, pkt_line) } diff --git a/p2p/src/node/client_http.rs b/p2p/src/node/client_http.rs index 5579b4d9..e6530695 100644 --- a/p2p/src/node/client_http.rs +++ b/p2p/src/node/client_http.rs @@ -55,7 +55,7 @@ pub fn mega_routers() -> Router { } async fn life_cycle_check() -> Result { - Ok(Json("ok")) + Ok(Json("p2p node http ready")) } async fn mega_provide( diff --git a/p2p/src/node/command_handler.rs b/p2p/src/node/command_handler.rs index f1bbb1ee..93223368 100644 --- a/p2p/src/node/command_handler.rs +++ b/p2p/src/node/command_handler.rs @@ -21,41 +21,39 @@ pub async fn provide( client_paras: &mut ClientParas, repo_name: &str, ) { + if !repo_name.ends_with(".git") { + eprintln!("repo_name should end with .git"); + return; + } + let path = get_repo_full_path(repo_name); + let pack_protocol: git::protocol::PackProtocol = + get_pack_protocol(&path, client_paras.storage.clone()); + let object_id = pack_protocol.get_head_object_id(Path::new(&path)).await; + if object_id == *utils::ZERO_ID { + eprintln!("Repository not found"); + return; + } + //Construct repoInfo + let mega_repo_info = MegaRepoInfo { + origin: swarm.local_peer_id().to_string(), + name: repo_name.to_string(), + latest: object_id, + forks: vec![], + timestamp: get_utc_timestamp(), + }; + let record = Record { + key: kad::RecordKey::new(&repo_name), + value: serde_json::to_vec(&mega_repo_info).unwrap(), + publisher: None, + expires: None, + }; + + if let Err(e) = swarm + .behaviour_mut() + .kademlia + .put_record(record, Quorum::One) { - if !repo_name.ends_with(".git") { - eprintln!("repo_name should end with .git"); - return; - } - let path = get_repo_full_path(repo_name); - let pack_protocol: git::protocol::PackProtocol = - get_pack_protocol(&path, client_paras.storage.clone()); - let object_id = pack_protocol.get_head_object_id(Path::new(&path)).await; - if object_id == *utils::ZERO_ID { - eprintln!("Repository not found"); - return; - } - // //Construct repoInfo - let mega_repo_info = MegaRepoInfo { - origin: swarm.local_peer_id().to_string(), - name: repo_name.to_string(), - latest: object_id, - forks: vec![], - timestamp: get_utc_timestamp(), - }; - let record = Record { - key: kad::RecordKey::new(&repo_name), - value: serde_json::to_vec(&mega_repo_info).unwrap(), - publisher: None, - expires: None, - }; - - if let Err(e) = swarm - .behaviour_mut() - .kademlia - .put_record(record, Quorum::One) - { - eprintln!("Failed to store record:{}", e); - } + eprintln!("Failed to store record:{}", e); } } @@ -64,12 +62,10 @@ pub async fn search( _client_paras: &mut ClientParas, repo_name: &str, ) { - { - swarm - .behaviour_mut() - .kademlia - .get_record(kad::RecordKey::new(&repo_name)); - } + swarm + .behaviour_mut() + .kademlia + .get_record(kad::RecordKey::new(&repo_name)); } pub async fn clone( @@ -87,15 +83,14 @@ pub async fn clone( } }; let path = get_repo_full_path(repo_name); - { - let request_file_id = swarm.behaviour_mut().git_upload_pack.send_request( - &peer_id, - GitUploadPackReq(HashSet::new(), HashSet::new(), path), - ); - client_paras - .pending_git_upload_package - .insert(request_file_id, repo_name.to_string()); - } + + let request_file_id = swarm.behaviour_mut().git_upload_pack.send_request( + &peer_id, + GitUploadPackReq(HashSet::new(), HashSet::new(), path), + ); + client_paras + .pending_git_upload_package + .insert(request_file_id, repo_name.to_string()); } pub async fn pull( @@ -117,16 +112,15 @@ pub async fn pull( eprintln!("local repo not found"); return; } - { - // Request to get git_info_refs - let request_id = swarm - .behaviour_mut() - .git_info_refs - .send_request(&peer_id, GitInfoRefsReq(path, Vec::new())); - client_paras - .pending_git_pull - .insert(request_id, repo_name.to_string()); - } + + // Request to get git_info_refs + let request_id = swarm + .behaviour_mut() + .git_info_refs + .send_request(&peer_id, GitInfoRefsReq(path, Vec::new())); + client_paras + .pending_git_pull + .insert(request_id, repo_name.to_string()); } pub async fn clone_obj( @@ -138,16 +132,15 @@ pub async fn clone_obj( eprintln!("repo_name should end with .git"); return; } - { - let kad_query_id = swarm - .behaviour_mut() - .kademlia - .get_record(kad::RecordKey::new(&repo_name)); - - client_paras - .pending_repo_info_search_to_download_obj - .insert(kad_query_id, repo_name.to_owned()); - } + + let kad_query_id = swarm + .behaviour_mut() + .kademlia + .get_record(kad::RecordKey::new(&repo_name)); + + client_paras + .pending_repo_info_search_to_download_obj + .insert(kad_query_id, repo_name.to_owned()); } pub async fn pull_obj( @@ -163,11 +156,10 @@ pub async fn pull_obj( .behaviour_mut() .kademlia .get_record(kad::RecordKey::new(&repo_name)); - { - client_paras - .pending_repo_info_search_to_download_obj - .insert(kad_query_id, repo_name.to_owned()); - } + + client_paras + .pending_repo_info_search_to_download_obj + .insert(kad_query_id, repo_name.to_owned()); } pub async fn subscribe( @@ -179,12 +171,10 @@ pub async fn subscribe( let filters = vec![Filter::new().repo_name(repo_name.to_string())]; let client_req = ClientMessage::new_req(SubscriptionId::generate(), filters); - { - swarm - .behaviour_mut() - .nostr - .send_request(&relay_peer_id, NostrReq(client_req.as_json())); - } + swarm + .behaviour_mut() + .nostr + .send_request(&relay_peer_id, NostrReq(client_req.as_json())); } pub async fn event_update( @@ -296,9 +286,7 @@ pub async fn kad_get( key: &str, ) { let key = kad::RecordKey::new(&key); - { - swarm.behaviour_mut().kademlia.get_record(key); - } + swarm.behaviour_mut().kademlia.get_record(key); } pub async fn kad_put( @@ -315,14 +303,13 @@ pub async fn kad_put( publisher: None, expires: None, }; + + if let Err(e) = swarm + .behaviour_mut() + .kademlia + .put_record(record, Quorum::One) { - if let Err(e) = swarm - .behaviour_mut() - .kademlia - .put_record(record, Quorum::One) - { - eprintln!("Put record failed :{}", e); - } + eprintln!("Put record failed :{}", e); } } @@ -337,9 +324,7 @@ pub async fn get_peer( return; } }; - { - swarm.behaviour_mut().kademlia.get_closest_peers(peer_id); - } + swarm.behaviour_mut().kademlia.get_closest_peers(peer_id); } pub fn parse_peer_id(peer_id_str: Option<&str>) -> Option { diff --git a/storage/entity/src/lib.rs b/storage/entity/src/lib.rs index 3991e1c0..2ee9b0c3 100644 --- a/storage/entity/src/lib.rs +++ b/storage/entity/src/lib.rs @@ -13,3 +13,4 @@ pub mod refs; pub mod issue; pub mod repo_directory; pub mod pull_request; +pub mod model; diff --git a/storage/entity/src/model/mod.rs b/storage/entity/src/model/mod.rs new file mode 100644 index 00000000..e48e4a30 --- /dev/null +++ b/storage/entity/src/model/mod.rs @@ -0,0 +1 @@ +pub mod query_result; \ No newline at end of file diff --git a/storage/entity/src/model/query_result.rs b/storage/entity/src/model/query_result.rs new file mode 100644 index 00000000..a3aaf300 --- /dev/null +++ b/storage/entity/src/model/query_result.rs @@ -0,0 +1,7 @@ +use sea_orm::FromQueryResult; + +#[derive(Debug, FromQueryResult)] +pub struct SelectResult { + pub node_type: String, + pub count: i64, +} \ No newline at end of file diff --git a/storage/src/driver/database/storage.rs b/storage/src/driver/database/storage.rs index 02433f04..47c75275 100644 --- a/storage/src/driver/database/storage.rs +++ b/storage/src/driver/database/storage.rs @@ -9,19 +9,7 @@ use std::path::Path; use std::path::PathBuf; use async_trait::async_trait; - -use entity::commit; -use entity::issue; -use entity::locks; -use entity::meta; -use entity::mr; -use entity::mr_info; -use entity::node; -use entity::objects; -use entity::pull_request; -use entity::refs; - -use entity::repo_directory; +use entity::model::query_result::SelectResult; use sea_orm::sea_query::OnConflict; use sea_orm::ActiveModelTrait; use sea_orm::ColumnTrait; @@ -37,6 +25,17 @@ use sea_orm::Set; use sea_orm::TryIntoModel; use common::errors::MegaError; +use entity::commit; +use entity::issue; +use entity::locks; +use entity::meta; +use entity::mr; +use entity::mr_info; +use entity::node; +use entity::objects; +use entity::pull_request; +use entity::refs; +use entity::repo_directory; use crate::driver::file_storage; @@ -470,6 +469,28 @@ pub trait ObjectStorage: Send + Sync { .await .unwrap()) } + + async fn count_obj_from_commit_and_node( + &self, + repo_path: &str, + ) -> Result, MegaError> { + let select = node::Entity::find() + .select_only() + .filter(node::Column::RepoPath.eq(repo_path)) + .column(node::Column::NodeType) + .column_as(node::Column::NodeType.count(), "count") + .group_by(node::Column::NodeType); + // .into_json(); + // .all(self.get_connection()) + // .await + // .unwrap(); + let results = select + .into_model::() + .all(self.get_connection()) + .await + .unwrap(); + Ok(results) + } } /// Performs batch saving of models in the database. diff --git a/tests/common_test/mod.rs b/tests/common_test/mod.rs index ffbecdcf..30bef3b3 100644 --- a/tests/common_test/mod.rs +++ b/tests/common_test/mod.rs @@ -1,27 +1,44 @@ use std::{ + env, process::Command, thread::{self, sleep}, time::Duration, }; +use bytes::Bytes; +use futures_util::StreamExt; +use tokio_util::io::ReaderStream; + #[derive(Clone)] pub struct P2pTestConfig { pub compose_path: String, + pub pack_path: String, pub lifecycle_url: String, pub lifecycle_retrying: u64, + pub repo_name: String, + pub commit_id: String, + pub obj_num: i32, +} + +pub fn build_image(config: &P2pTestConfig) { + let child = Command::new("docker") + .arg("compose") // Provide arguments if needed + .arg("-f") + .arg(&config.compose_path) + .arg("build") + .output() + .expect("Failed to execute command"); + assert!(child.status.success()); } -pub async fn init_p2p_server(config: P2pTestConfig) { + +pub fn start_server(config: &P2pTestConfig) { + let path = config.compose_path.clone(); // docker compose -f tests/compose/mega_p2p/compose.yaml up --build - let P2pTestConfig { - compose_path, - lifecycle_url, - lifecycle_retrying, - } = config; thread::spawn(move || { let mut child = Command::new("docker") .arg("compose") // Provide arguments if needed .arg("-f") - .arg(compose_path) + .arg(path) .arg("up") .stdin(std::process::Stdio::piped()) // Pass the standard input stream as an argument .stdout(std::process::Stdio::piped()) @@ -30,50 +47,73 @@ pub async fn init_p2p_server(config: P2pTestConfig) { // Wait for the child process to finish and get the result let _ = child.wait().expect("Failed to wait for child process"); }); +} +pub async fn lifecycle_check(config: &P2pTestConfig) { loop { - let resp = reqwest::get(&lifecycle_url).await.unwrap(); + let resp = reqwest::get(config.lifecycle_url.clone()).await.unwrap(); if resp.status() == 200 { + println!("lifecycle check passed"); break; } else { println!( "lifecycle check failed, retrying in {} secs ...", - lifecycle_retrying + config.lifecycle_retrying ); } - sleep(Duration::from_secs(lifecycle_retrying)); + sleep(Duration::from_secs(config.lifecycle_retrying)); } } -pub fn provide_data_before_test() { - let res = Command::new("git") - .arg("remote") - .arg("set-url") - .arg("local") - .arg("http://localhost:8000/projects/mega.git") - .output() - .expect("Failed to execute command"); - assert!(res.status.success()); - let res2 = Command::new("git") - .arg("push") - .arg("local") - .arg("main") - .output() - .expect("Failed to execute command"); - assert!(res2.status.success()); +// pub fn init_by_command() { +// let res = Command::new("git") +// .arg("remote") +// .arg("set-url") +// .arg("local") +// .arg("http://localhost:8000/projects/mega.git") +// .output() +// .expect("Failed to execute command"); +// assert!(res.status.success()); +// let res2 = Command::new("git") +// .arg("push") +// .arg("local") +// .arg("main") +// .output() +// .expect("Failed to execute command"); +// assert!(res2.status.success()); +// } + +pub async fn init_by_pack(config: &P2pTestConfig) { + let mut source = env::current_dir().unwrap(); + source.push(&config.pack_path); + let pkt_line = format!("00980000000000000000000000000000000000000000 {} refs/heads/master\0 report-status-v2 side-band-64k agent=mega-test\n0000", config.commit_id); + let pkt_line = std::io::Cursor::new(Bytes::from(pkt_line)); + + let f = tokio::fs::File::open(source).await.unwrap(); + let stream = ReaderStream::new(pkt_line).chain(ReaderStream::new(f)); + let client = reqwest::Client::new(); + let url = format!( + "http://localhost:8000/projects/{}/git-receive-pack", + config.repo_name + ); + let resp = client + .post(url) + .body(reqwest::Body::wrap_stream(stream)) + .send() + .await + .unwrap(); + assert_eq!(resp.status(), 200); + println!("resp: {:?}", resp.bytes().await); + + //TODO: check objenums matchs } -pub fn stop_p2p_server(config: P2pTestConfig) { - let P2pTestConfig { - compose_path, - lifecycle_url: _, - lifecycle_retrying: _, - } = config; - println!("stoping p2p server and cleaning resources..."); +pub fn stop_server(config: &P2pTestConfig) { + println!("stoping server and cleaning resources..."); Command::new("docker") .arg("compose") // Provide arguments if needed .arg("-f") - .arg(compose_path) + .arg(&config.compose_path) .arg("down") .output() .expect("Failed to execute command"); diff --git a/tests/integration_test.rs b/tests/integration_test.rs index 316d1eb6..852c11bd 100644 --- a/tests/integration_test.rs +++ b/tests/integration_test.rs @@ -1,20 +1,28 @@ use crate::common_test::P2pTestConfig; +use go_defer::defer; + mod common_test; #[tokio::test] #[ignore] -async fn test_peovide_and_clone_e2e() { +async fn test_p2p_basic() { let init_config = P2pTestConfig { compose_path: "tests/compose/mega_p2p/compose.yaml".to_string(), + pack_path: "tests/data/packs/pack-d50df695086eea6253a237cb5ac44af1629e7ced.pack".to_string(), lifecycle_url: "http://localhost:8301/api/v1/status".to_string(), lifecycle_retrying: 5, + repo_name: "git".to_string(), + commit_id: "d50df695086eea6253a237cb5ac44af1629e7ced".to_string(), + obj_num: 0 }; - common_test::init_p2p_server(init_config.clone()).await; - common_test::provide_data_before_test(); + defer!( + common_test::stop_server(&init_config); + ); + common_test::start_server(&init_config); + common_test::lifecycle_check(&init_config).await; + common_test::init_by_pack(&init_config).await; test_mega_provide().await; test_mega_clone().await; - test_mega_clone_obj().await; - common_test::stop_p2p_server(init_config); } async fn test_mega_provide() { @@ -28,14 +36,34 @@ async fn test_mega_provide() { } async fn test_mega_clone() { - //note that if secret of nodeA in compose file has been change, should also update the perrid in the below link - let resp = reqwest::get("http://localhost:8401/api/v1/mega/clone?mega_address=p2p://16Uiu2HAmCpKDLiX1NK6ULnYycq88jqaptNMRo1f4mRSu3VqHMry1/mega.git") - .await.unwrap(); + //note that if secret of nodeA in compose file has been change, peerid in the below link should also be updated + let resp = reqwest::get("http://localhost:8401/api/v1/mega/clone?mega_address=p2p://16Uiu2HAmCpKDLiX1NK6ULnYycq88jqaptNMRo1f4mRSu3VqHMry1/mega.git").await.unwrap(); assert_eq!(resp.status(), 200); } -async fn test_mega_clone_obj() { - let resp = reqwest::get("http://localhost:8501/api/v1/mega/clone-obj?mega_address=p2p://16Uiu2HAmCpKDLiX1NK6ULnYycq88jqaptNMRo1f4mRSu3VqHMry1/mega.git") - .await.unwrap(); - assert_eq!(resp.status(), 200); +// async fn test_mega_clone_obj() { +// let resp = reqwest::get("http://localhost:8501/api/v1/mega/clone-obj?mega_address=p2p://16Uiu2HAmCpKDLiX1NK6ULnYycq88jqaptNMRo1f4mRSu3VqHMry1/mega.git").await.unwrap(); +// assert_eq!(resp.status(), 200); +// } + +#[tokio::test] +#[ignore] +async fn test_http() { + let init_config = P2pTestConfig { + compose_path: "tests/compose/http/compose.yaml".to_string(), + pack_path: "tests/data/packs/pack-d50df695086eea6253a237cb5ac44af1629e7ced.pack".to_string(), + lifecycle_url: "http://localhost:8000/api/v1/status".to_string(), + lifecycle_retrying: 5, + repo_name: "git".to_string(), + commit_id: "d50df695086eea6253a237cb5ac44af1629e7ced".to_string(), + obj_num: 10000 + }; + defer!( + common_test::stop_server(&init_config); + ); + common_test::build_image(&init_config); + common_test::start_server(&init_config); + common_test::lifecycle_check(&init_config).await; + common_test::init_by_pack(&init_config).await; + }