1717import socket
1818import ssl
1919import struct
20+ import time
2021import uuid
2122from collections .abc import Callable
2223from textwrap import dedent
@@ -99,11 +100,14 @@ def app_password(email: str) -> str:
99100 f"--frontegg-api-token-url={ FRONTEGG_URL } /identity/resources/auth/v1/api-token" ,
100101 f"--frontegg-admin-role={ ADMIN_ROLE } " ,
101102 "--https-sni-resolver-template=materialized:6876" ,
102- "--pgwire-sni-resolver-template=materialized:6875" ,
103+ # This will be turned off until we can resolve perf issues
104+ # https://github.com/MaterializeInc/database-issues/issues/9700
105+ # "--pgwire-sni-resolver-template=materialized:6875",
103106 "--tls-key=/secrets/balancerd.key" ,
104107 "--tls-cert=/secrets/balancerd.crt" ,
105- "--default-config=balancerd_inject_proxy_protocol_header_http=true" ,
106108 "--internal-tls" ,
109+ "--tls-mode=require" ,
110+ "--default-config=balancerd_inject_proxy_protocol_header_http=true" ,
107111 # Nonsensical but we don't need cancellations here
108112 "--cancellation-resolver-dir=/secrets/" ,
109113 ],
@@ -248,7 +252,6 @@ def workflow_plaintext(c: Composition) -> None:
248252 f"--frontegg-api-token-url={ FRONTEGG_URL } /identity/resources/auth/v1/api-token" ,
249253 f"--frontegg-admin-role={ ADMIN_ROLE } " ,
250254 "--https-resolver-template=materialized:6876" ,
251- "--pgwire-sni-resolver-template=materialized:6876" ,
252255 "--tls-key=/secrets/balancerd.key" ,
253256 "--tls-cert=/secrets/balancerd.crt" ,
254257 "--default-config=balancerd_inject_proxy_protocol_header_http=true" ,
@@ -593,6 +596,7 @@ def workflow_mz_not_running(c: Composition) -> None:
593596 "failure in name resolution" ,
594597 "failed to lookup address information" ,
595598 "Name or service not known" ,
599+ "SSL connection has been closed unexpectedly" ,
596600 ]
597601 )
598602 except :
@@ -605,24 +609,55 @@ def workflow_mz_not_running(c: Composition) -> None:
605609
606610def workflow_user (c : Composition ) -> None :
607611 """Test that the user is passed all the way to Mz itself."""
608- c .up ("balancerd" , "frontegg-mock" , "materialized" )
609-
610- # Non-admin user.
611- cursor = sql_cursor (c , email = OTHER_USER )
612+ with c .override (
613+ Balancerd (
614+ command = [
615+ "--startup-log-filter=debug" ,
616+ "service" ,
617+ "--pgwire-listen-addr=0.0.0.0:6875" ,
618+ "--https-listen-addr=0.0.0.0:6876" ,
619+ "--internal-http-listen-addr=0.0.0.0:6878" ,
620+ "--frontegg-resolver-template=materialized:6875" ,
621+ "--frontegg-jwk-file=/secrets/frontegg-mock.crt" ,
622+ f"--frontegg-api-token-url={ FRONTEGG_URL } /identity/resources/auth/v1/api-token" ,
623+ f"--frontegg-admin-role={ ADMIN_ROLE } " ,
624+ "--https-sni-resolver-template=materialized:6876" ,
625+ # Same defaults but we want to remove the pgwire-sni-resolver
626+ # In order for SNI to do tenant resoluition we need an extra CNAME rec to be added
627+ # which we can't do in docker compose
628+ # "--pgwire-sni-resolver-template=materialized:6875",
629+ "--tls-key=/secrets/balancerd.key" ,
630+ "--tls-cert=/secrets/balancerd.crt" ,
631+ "--internal-tls" ,
632+ "--tls-mode=require" ,
633+ "--default-config=balancerd_inject_proxy_protocol_header_http=true" ,
634+ # Nonsensical but we don't need cancellations here
635+ "--cancellation-resolver-dir=/secrets/" ,
636+ ],
637+ depends_on = ["test-certs" ],
638+ volumes = [
639+ "secrets:/secrets" ,
640+ ],
641+ ),
642+ ):
643+ c .up ("balancerd" , "frontegg-mock" , "materialized" )
644+ # Non-admin user.
645+ cursor = sql_cursor (c , email = OTHER_USER )
612646
613- try :
614- cursor .execute ("DROP DATABASE materialize CASCADE" )
615- raise RuntimeError ("execute() expected to fail" )
616- except ProgrammingError as e :
617- assert "must be owner of DATABASE materialize" in str (e )
618- except :
619- raise RuntimeError ("execute() threw an unexpected exception" )
647+ try :
648+ cursor .execute ("DROP DATABASE materialize CASCADE" )
649+ raise RuntimeError ("execute() expected to fail" )
650+ except ProgrammingError as e :
651+ assert "must be owner of DATABASE materialize" in str (e )
652+ except :
653+ raise RuntimeError ("execute() threw an unexpected exception" )
620654
621- cursor .execute ("SELECT current_user()" )
622- assert OTHER_USER in str (cursor .fetchall ())
655+ cursor .execute ("SELECT current_user()" )
656+ assert OTHER_USER in str (cursor .fetchall ())
657+ cursor .close ()
623658
624- assert_metrics (c , 'mz_balancer_tenant_connection_active{source="pgwire"' )
625- assert_metrics (c , 'mz_balancer_tenant_connection_rx{source="pgwire"' )
659+ assert_metrics (c , 'mz_balancer_tenant_connection_active{source="pgwire"' )
660+ assert_metrics (c , 'mz_balancer_tenant_connection_rx{source="pgwire"' )
626661
627662
628663def workflow_many_connections (c : Composition ) -> None :
@@ -631,9 +666,14 @@ def workflow_many_connections(c: Composition) -> None:
631666 cursors = []
632667 connections = 1000 - 10 # Go almost to the limit, but not above
633668 print (f"Opening { connections } connections." )
634- for i in range (connections ):
669+ start = time .time ()
670+ for _ in range (connections ):
635671 cursor = sql_cursor (c )
636672 cursors .append (cursor )
673+ duration = time .time () - start
674+ print (
675+ f"{ connections } connections opened in { duration } seconds, { duration / float (connections )} avg connection time"
676+ )
637677
638678 for cursor in cursors :
639679 cursor .execute ("SELECT 'abc'" )
0 commit comments