-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add e2e tests (broken due to issue? in API)
- Loading branch information
Showing
2 changed files
with
81 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,91 @@ | ||
use std::future::Future; | ||
|
||
pub mod common; | ||
|
||
#[tokio::test] | ||
async fn end_to_end_test() { | ||
async fn e2e_test_wrapper<T: Future<Output = ()>>(test: T) { | ||
let api_server = common::init_api_server().await; | ||
let ingestor = common::init_ingestion_server().await; | ||
|
||
let test = async { | ||
// TODO: ingest data | ||
// TODO: test API | ||
println!("Testing that stuff works..."); | ||
}; | ||
|
||
tokio::select! { | ||
_ = api_server => panic!("API server task terminated first"), | ||
// TODO: right now `ingestor` errors out, so it finishes first. | ||
// need to figure out the permission thing | ||
_ = ingestor => panic!("Ingestor server task terminated first"), | ||
_ = test => {} | ||
} | ||
} | ||
|
||
#[tokio::test] | ||
async fn existing_timeseries() { | ||
e2e_test_wrapper(async move { | ||
let station_id = 1800; | ||
let param_id = 211; | ||
|
||
let client = reqwest::Client::new(); | ||
let obsinn_msg = format!( | ||
"kldata/nationalnr={}/type=508/messageid=23 | ||
TA,TWD(0,0) | ||
20240607164900,20.0,15.2 | ||
20240607165100,20.1,15.3 | ||
20240607165200,20.0,15.3 | ||
20240607165300,20.2,15.1 | ||
20240607165400,20.2,15.2 | ||
20240607165500,20.1,15.2 | ||
", | ||
station_id | ||
); | ||
|
||
let resp = client | ||
.post("http://localhost:3001/kldata") | ||
.body(obsinn_msg) | ||
.send() | ||
.await | ||
.unwrap(); | ||
println!("\ningestion resp: {}", resp.text().await.unwrap()); | ||
|
||
let url = format!( | ||
"http://localhost:3000/stations/{}/params/{}", | ||
station_id, param_id | ||
); | ||
let resp = client.get(url).send().await.unwrap(); | ||
println!("api resp: {}", resp.text().await.unwrap()); | ||
}) | ||
.await | ||
} | ||
|
||
#[tokio::test] | ||
async fn new_timeseries() { | ||
e2e_test_wrapper(async move { | ||
let station_id = 40001; | ||
let param_id = 145; | ||
|
||
let client = reqwest::Client::new(); | ||
// 145, AGM, mean(air_gap PT10M) | ||
// 146, AGX, max(air_gap PT10M) | ||
let obsinn_msg = "kldata/nationalnr=40001/type=506/messageid=23 | ||
AGM(1,2),AGX(1,2) | ||
20240606000000,11.0,12.0 | ||
20240606001000,12.0,19.0 | ||
20240606002000,10.0,16.0 | ||
20240606003000,12.0,16.0 | ||
20240606004000,11.0,15.0 | ||
"; | ||
|
||
// ingest data | ||
let resp = client | ||
.post("http://localhost:3001/kldata") | ||
.body(obsinn_msg) | ||
.send() | ||
.await | ||
.unwrap(); | ||
|
||
println!("\ningestor_resp: {}", resp.text().await.unwrap()); | ||
|
||
let url = format!( | ||
"http://localhost:3000/stations/{}/params/{}", | ||
station_id, param_id | ||
); | ||
let resp = client.get(url).send().await.unwrap(); | ||
println!("api_resp: {}", resp.text().await.unwrap()); | ||
// TODO: do something with the response | ||
}) | ||
.await | ||
} |