Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adapter: Refactor environmentd test #23275

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 26 additions & 17 deletions src/balancerd/tests/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,15 +89,14 @@ use mz_frontegg_auth::{
use mz_frontegg_mock::FronteggMockServer;
use mz_ore::metrics::MetricsRegistry;
use mz_ore::now::SYSTEM_TIME;
use mz_ore::task::RuntimeExt;
use mz_ore::task;
use mz_server_core::TlsCertConfig;
use openssl::ssl::{SslConnectorBuilder, SslVerifyMode};
use postgres::Client;
use uuid::Uuid;

#[mz_ore::test]
#[mz_ore::test(tokio::test(flavor = "multi_thread", worker_threads = 1))]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens if you leave out flavor = "multi_thread", worker_threads = 1?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For some reason the test hangs, everything runs but we're blocked on cleanup. I haven't figured out exactly what's happening yet, but will dig in further when I have a free cycle or two

#[cfg_attr(miri, ignore)] // too slow
fn test_balancer() {
async fn test_balancer() {
let ca = Ca::new_root("test ca").unwrap();
let (server_cert, server_key) = ca
.request_cert("server", vec![IpAddr::V4(Ipv4Addr::LOCALHOST)])
Expand Down Expand Up @@ -127,6 +126,7 @@ fn test_balancer() {
None,
)
.unwrap();

let frontegg_auth = FronteggAuthentication::new(
FronteggConfig {
admin_api_token_url: frontegg_server.url.clone(),
Expand All @@ -141,21 +141,28 @@ fn test_balancer() {
let frontegg_user = "user@_.com";
let frontegg_password = format!("mzp_{client_id}{secret}");

let config = test_util::Config::default()
let envd_server = test_util::TestHarness::default()
// Enable SSL on the main port. There should be a balancerd port with no SSL.
.with_tls(server_cert.clone(), server_key.clone())
.with_frontegg(&frontegg_auth)
.with_metrics_registry(metrics_registry);
let envd_server = test_util::start_server(config).unwrap();
.with_metrics_registry(metrics_registry)
.start()
.await;

// Ensure we could connect directly to envd without SSL on the balancer port.
let mut pg_client_envd = envd_server
.pg_config_balancer()
let pg_client_envd = envd_server
.connect()
.balancer()
.user(frontegg_user)
.password(&frontegg_password)
.connect(tokio_postgres::NoTls)
.await
.unwrap();
let res: i32 = pg_client_envd.query_one("SELECT 4", &[]).unwrap().get(0);

let res: i32 = pg_client_envd
.query_one("SELECT 4", &[])
.await
.unwrap()
.get(0);
assert_eq!(res, 4);

let resolvers = vec![
Expand All @@ -181,15 +188,13 @@ fn test_balancer() {
cert_config.clone(),
MetricsRegistry::new(),
);
let balancer_server = envd_server
.runtime
.block_on(async { BalancerService::new(balancer_cfg).await.unwrap() });
let balancer_server = BalancerService::new(balancer_cfg).await.unwrap();
let balancer_pgwire_listen = balancer_server.pgwire.0.local_addr();
envd_server.runtime.spawn_named(|| "balancer", async {
task::spawn(|| "balancer", async {
balancer_server.serve().await.unwrap();
});

let mut pg_client = Client::connect(
let (pg_client, conn) = tokio_postgres::connect(
&format!(
"user={frontegg_user} password={frontegg_password} host={} port={} sslmode=require",
balancer_pgwire_listen.ip(),
Expand All @@ -199,9 +204,13 @@ fn test_balancer() {
Ok(b.set_verify(SslVerifyMode::NONE))
})),
)
.await
.unwrap();
task::spawn(|| "balancer-pg_client", async move {
conn.await.expect("balancer-pg_client")
});

let res: i32 = pg_client.query_one("SELECT 2", &[]).unwrap().get(0);
let res: i32 = pg_client.query_one("SELECT 2", &[]).await.unwrap().get(0);
assert_eq!(res, 2);
}
}
Loading