Skip to content

Commit

Permalink
Added a test for the component cache.
Browse files Browse the repository at this point in the history
  • Loading branch information
Murmeldyret committed Oct 10, 2023
1 parent baff951 commit 99ab671
Showing 1 changed file with 55 additions and 0 deletions.
55 changes: 55 additions & 0 deletions src/tests/grpc/send_query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,60 @@ mod refinements {
}
}

#[tokio::test]
async fn send_query_using_cache() {
let backend = ConcreteEcdarBackend::default();
let query_request = construct_query_request_for_cache("refinement: Machine <= Machine");

// Normal query request, including component.
let query_response = backend.send_query(query_request.0).await;

let query_result = query_response.unwrap().into_inner();
let normal_result = query_result.result.unwrap();

// Component should be cached now.
// Query without component utilizing cache
let query_response = backend.send_query(query_request.1).await;

let query_result = query_response.unwrap().into_inner();
let cache_result = query_result.result.unwrap();

// Compare normal and cache response.
assert_eq!(normal_result, cache_result);
}

fn construct_query_request_for_cache(
query: &str,
) -> (Request<QueryRequest>, Request<QueryRequest>) {
let json =
std::fs::read_to_string(format!("{}/Components/Machine.json", ECDAR_UNI)).unwrap();

let normal_request = Request::new(QueryRequest {
user_id: 0,
query_id: 0,
query: String::from(query),
components_info: Some(ComponentsInfo {
components: vec![Component {
rep: Some(Rep::Json(json)),
}],
components_hash: 1,
}),
settings: Some(crate::tests::TEST_SETTINGS),
});

let cached_request = Request::new(QueryRequest {
user_id: 0,
query_id: 0,
query: String::from(query),
components_info: Some(ComponentsInfo {
components: vec![],
components_hash: 1,
}),
settings: Some(crate::tests::TEST_SETTINGS),
});
(normal_request, cached_request)
}

fn construct_query_request(query: &str) -> Request<QueryRequest> {
let json =
std::fs::read_to_string(format!("{}/Components/Machine.json", ECDAR_UNI)).unwrap();
Expand Down Expand Up @@ -108,3 +162,4 @@ mod refinements {
}

Check warning on line 162 in src/tests/grpc/send_query.rs

View workflow job for this annotation

GitHub Actions / cargo fmt

Diff in /home/runner/work/Reveaal/Reveaal/src/tests/grpc/send_query.rs
}
}

0 comments on commit 99ab671

Please sign in to comment.