Skip to content

Commit

Permalink
Disable GraphOS tests when apollo key not present (#5362)
Browse files Browse the repository at this point in the history
Co-authored-by: bryn <bryn@apollographql.com>
  • Loading branch information
BrynCooke and bryn authored Jun 6, 2024
1 parent 3d2269f commit 08889ec
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 13 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(_))
)
}
5 changes: 4 additions & 1 deletion apollo-router/tests/integration/coprocessor.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
use insta::assert_yaml_snapshot;
use tower::BoxError;

use crate::integration::common::graph_os_enabled;
use crate::integration::IntegrationTest;

#[tokio::test(flavor = "multi_thread")]
async fn test_error_not_propagated_to_client() -> Result<(), BoxError> {
if !graph_os_enabled() {
return Ok(());
}
let mut router = IntegrationTest::builder()
.config(include_str!("fixtures/broken_coprocessor.router.yaml"))
.build()
Expand All @@ -18,6 +22,5 @@ async fn test_error_not_propagated_to_client() -> Result<(), BoxError> {
assert_yaml_snapshot!(response.text().await?);
router.assert_log_contains("INTERNAL_SERVER_ERROR").await;
router.graceful_shutdown().await;

Ok(())
}
4 changes: 4 additions & 0 deletions apollo-router/tests/integration/redis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ use serde_json::Value;
use tower::BoxError;
use tower::ServiceExt;

use crate::integration::common::graph_os_enabled;
use crate::integration::IntegrationTest;

#[tokio::test(flavor = "multi_thread")]
Expand Down Expand Up @@ -958,6 +959,9 @@ async fn query_planner_redis_update_reuse_query_fragments() {
}

async fn test_redis_query_plan_config_update(updated_config: &str, new_cache_key: &str) {
if !graph_os_enabled() {
return;
}
// 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.
Expand Down
28 changes: 16 additions & 12 deletions apollo-router/tests/integration/telemetry/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use std::time::Duration;

use serde_json::json;

use crate::integration::common::graph_os_enabled;
use crate::integration::IntegrationTest;

const PROMETHEUS_CONFIG: &str = include_str!("fixtures/prometheus.router.yaml");
Expand Down Expand Up @@ -189,6 +190,9 @@ async fn test_bad_queries() {

#[tokio::test(flavor = "multi_thread")]
async fn test_graphql_metrics() {
if !graph_os_enabled() {
return;
}
let mut router = IntegrationTest::builder()
.config(include_str!("fixtures/graphql.router.yaml"))
.build()
Expand All @@ -198,21 +202,21 @@ async fn test_graphql_metrics() {
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;
.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;
.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;
.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;
.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;
.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;
.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 08889ec

Please sign in to comment.