Skip to content

Commit

Permalink
Disable tests that should not have been run without graphos being ena…
Browse files Browse the repository at this point in the history
…bled.
  • Loading branch information
bryn committed Jun 6, 2024
1 parent 3d2269f commit e2d7d97
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 60 deletions.
6 changes: 6 additions & 0 deletions .changesets/maint_bryn_disable_tests_apollo_key_missing.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
### Disable GraphOS tests when apollo key not present ([PR #5362](https://github.com/apollographql/router/pull/5362))

A number of tests require APOLLO_KEY and APOLLO_GRAPH_REF to be present to execute successfully.
These are now skipped if these env variables are not present.

By [@BrynCooke](https://github.com/BrynCooke) in https://github.com/apollographql/router/pull/5362
11 changes: 11 additions & 0 deletions apollo-router/tests/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1150,3 +1150,14 @@ fn merge_overrides(

serde_yaml::to_string(&config).unwrap()
}

#[allow(dead_code)]
pub fn graph_os_enabled() -> bool {
matches!(
(
std::env::var("TEST_APOLLO_KEY"),
std::env::var("TEST_APOLLO_GRAPH_REF"),
),
(Ok(_), Ok(_))
)
}
26 changes: 14 additions & 12 deletions apollo-router/tests/integration/coprocessor.rs
Original file line number Diff line number Diff line change
@@ -1,23 +1,25 @@
use crate::integration::common::graph_os_enabled;
use insta::assert_yaml_snapshot;
use tower::BoxError;

use crate::integration::IntegrationTest;

#[tokio::test(flavor = "multi_thread")]
async fn test_error_not_propagated_to_client() -> Result<(), BoxError> {
let mut router = IntegrationTest::builder()
.config(include_str!("fixtures/broken_coprocessor.router.yaml"))
.build()
.await;
if graph_os_enabled() {
let mut router = IntegrationTest::builder()
.config(include_str!("fixtures/broken_coprocessor.router.yaml"))
.build()
.await;

router.start().await;
router.assert_started().await;

let (_trace_id, response) = router.execute_default_query().await;
assert_eq!(response.status(), 500);
assert_yaml_snapshot!(response.text().await?);
router.assert_log_contains("INTERNAL_SERVER_ERROR").await;
router.graceful_shutdown().await;
router.start().await;
router.assert_started().await;

let (_trace_id, response) = router.execute_default_query().await;
assert_eq!(response.status(), 500);
assert_yaml_snapshot!(response.text().await?);
router.assert_log_contains("INTERNAL_SERVER_ERROR").await;
router.graceful_shutdown().await;
}
Ok(())
}
49 changes: 26 additions & 23 deletions apollo-router/tests/integration/redis.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use crate::integration::common::graph_os_enabled;
use apollo_router::plugin::test::MockSubgraph;
use apollo_router::services::execution::QueryPlan;
use apollo_router::services::router;
Expand Down Expand Up @@ -958,27 +959,29 @@ async fn query_planner_redis_update_reuse_query_fragments() {
}

async fn test_redis_query_plan_config_update(updated_config: &str, new_cache_key: &str) {
// This test shows that the redis key changes when the query planner config changes.
// The test starts a router with a specific config, executes a query, and checks the redis cache key.
// Then it updates the config, executes the query again, and checks the redis cache key.
let mut router = IntegrationTest::builder()
.config(include_str!(
"fixtures/query_planner_redis_config_update.router.yaml"
))
.build()
.await;

router.start().await;
router.assert_started().await;
router.clear_redis_cache().await;

let starting_key = "plan:0:v2.8.0:a9e605fa09adc5a4b824e690b4de6f160d47d84ede5956b58a7d300cca1f7204:3973e022e93220f9212c18d0d0c543ae7c309e46640da93a4a0314de999f5112:1910d63916aae7a1066cb8c7d622fc3a8e363ed1b6ac8e214deed4046abae85c";
router.execute_default_query().await;
router.assert_redis_cache_contains(starting_key, None).await;
router.update_config(updated_config).await;
router.assert_reloaded().await;
router.execute_default_query().await;
router
.assert_redis_cache_contains(new_cache_key, Some(starting_key))
.await;
if graph_os_enabled() {
// This test shows that the redis key changes when the query planner config changes.
// The test starts a router with a specific config, executes a query, and checks the redis cache key.
// Then it updates the config, executes the query again, and checks the redis cache key.
let mut router = IntegrationTest::builder()
.config(include_str!(
"fixtures/query_planner_redis_config_update.router.yaml"
))
.build()
.await;

router.start().await;
router.assert_started().await;
router.clear_redis_cache().await;

let starting_key = "plan:0:v2.8.0:a9e605fa09adc5a4b824e690b4de6f160d47d84ede5956b58a7d300cca1f7204:3973e022e93220f9212c18d0d0c543ae7c309e46640da93a4a0314de999f5112:1910d63916aae7a1066cb8c7d622fc3a8e363ed1b6ac8e214deed4046abae85c";
router.execute_default_query().await;
router.assert_redis_cache_contains(starting_key, None).await;
router.update_config(updated_config).await;
router.assert_reloaded().await;
router.execute_default_query().await;
router
.assert_redis_cache_contains(new_cache_key, Some(starting_key))
.await;
}
}
53 changes: 28 additions & 25 deletions apollo-router/tests/integration/telemetry/metrics.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use std::time::Duration;

use crate::integration::common::graph_os_enabled;
use serde_json::json;

use crate::integration::IntegrationTest;
Expand Down Expand Up @@ -189,30 +190,32 @@ async fn test_bad_queries() {

#[tokio::test(flavor = "multi_thread")]
async fn test_graphql_metrics() {
let mut router = IntegrationTest::builder()
.config(include_str!("fixtures/graphql.router.yaml"))
.build()
.await;
if graph_os_enabled() {
let mut router = IntegrationTest::builder()
.config(include_str!("fixtures/graphql.router.yaml"))
.build()
.await;

router.start().await;
router.assert_started().await;
router.execute_default_query().await;
router
.assert_metrics_contains(r#"graphql_field_list_length_sum{graphql_field_name="topProducts",graphql_field_type="Product",graphql_type_name="Query",otel_scope_name="apollo/router"} 3"#, None)
.await;
router
.assert_metrics_contains(r#"graphql_field_list_length_bucket{graphql_field_name="topProducts",graphql_field_type="Product",graphql_type_name="Query",otel_scope_name="apollo/router",le="5"} 1"#, None)
.await;
router
.assert_metrics_contains(r#"graphql_field_execution_total{graphql_field_name="name",graphql_field_type="String",graphql_type_name="Product",otel_scope_name="apollo/router"} 3"#, None)
.await;
router
.assert_metrics_contains(r#"graphql_field_execution_total{graphql_field_name="topProducts",graphql_field_type="Product",graphql_type_name="Query",otel_scope_name="apollo/router"} 1"#, None)
.await;
router
.assert_metrics_contains(r#"custom_counter_total{graphql_field_name="name",graphql_field_type="String",graphql_type_name="Product",otel_scope_name="apollo/router"} 3"#, None)
.await;
router
.assert_metrics_contains(r#"custom_histogram_sum{graphql_field_name="topProducts",graphql_field_type="Product",graphql_type_name="Query",otel_scope_name="apollo/router"} 3"#, None)
.await;
router.start().await;
router.assert_started().await;
router.execute_default_query().await;
router
.assert_metrics_contains(r#"graphql_field_list_length_sum{graphql_field_name="topProducts",graphql_field_type="Product",graphql_type_name="Query",otel_scope_name="apollo/router"} 3"#, None)
.await;
router
.assert_metrics_contains(r#"graphql_field_list_length_bucket{graphql_field_name="topProducts",graphql_field_type="Product",graphql_type_name="Query",otel_scope_name="apollo/router",le="5"} 1"#, None)
.await;
router
.assert_metrics_contains(r#"graphql_field_execution_total{graphql_field_name="name",graphql_field_type="String",graphql_type_name="Product",otel_scope_name="apollo/router"} 3"#, None)
.await;
router
.assert_metrics_contains(r#"graphql_field_execution_total{graphql_field_name="topProducts",graphql_field_type="Product",graphql_type_name="Query",otel_scope_name="apollo/router"} 1"#, None)
.await;
router
.assert_metrics_contains(r#"custom_counter_total{graphql_field_name="name",graphql_field_type="String",graphql_type_name="Product",otel_scope_name="apollo/router"} 3"#, None)
.await;
router
.assert_metrics_contains(r#"custom_histogram_sum{graphql_field_name="topProducts",graphql_field_type="Product",graphql_type_name="Query",otel_scope_name="apollo/router"} 3"#, None)
.await;
}
}

0 comments on commit e2d7d97

Please sign in to comment.