107107 db_user = res ['username' ] or db_user
108108 db_pwd = res ['password' ] or db_pwd
109109elif TEST_SERVERLESS :
110- res = parse_uri ( os . environ [ "MONGODB_URI" ])
111- host , port = res [ 'nodelist' ]. pop ( 0 )
112- additional_serverless_mongoses = res ['nodelist' ]
110+ TEST_LOADBALANCER = True
111+ res = parse_uri ( SINGLE_MONGOS_LB_URI )
112+ host , port = res ['nodelist' ][ 0 ]
113113 db_user = res ['username' ] or db_user
114114 db_pwd = res ['password' ] or db_pwd
115115 TLS_OPTIONS = {'tls' : True }
116+ # Spec says serverless tests must be run with compression.
117+ COMPRESSORS = COMPRESSORS or 'zlib'
116118
117119
118120def is_server_resolvable ():
@@ -226,7 +228,7 @@ def __init__(self):
226228 self .version = Version (- 1 ) # Needs to be comparable with Version
227229 self .auth_enabled = False
228230 self .test_commands_enabled = False
229- self .server_parameters = None
231+ self .server_parameters = {}
230232 self .is_mongos = False
231233 self .mongoses = []
232234 self .is_rs = False
@@ -241,7 +243,7 @@ def __init__(self):
241243 self .is_data_lake = False
242244 self .load_balancer = TEST_LOADBALANCER
243245 self .serverless = TEST_SERVERLESS
244- if self .load_balancer :
246+ if self .load_balancer or self . serverless :
245247 self .default_client_options ["loadBalanced" ] = True
246248 if COMPRESSORS :
247249 self .default_client_options ["compressors" ] = COMPRESSORS
@@ -381,7 +383,11 @@ def _init_client(self):
381383 self .w = len (hello .get ("hosts" , [])) or 1
382384 self .version = Version .from_client (self .client )
383385
384- if TEST_SERVERLESS :
386+ if self .serverless :
387+ self .server_parameters = {
388+ 'requireApiVersion' : False ,
389+ 'enableTestCommands' : True ,
390+ }
385391 self .test_commands_enabled = True
386392 self .has_ipv6 = False
387393 else :
@@ -401,14 +407,11 @@ def _init_client(self):
401407
402408 self .is_mongos = (self .hello .get ('msg' ) == 'isdbgrid' )
403409 if self .is_mongos :
404- if self .serverless :
405- self .mongoses .append (self .client .address )
406- self .mongoses .extend (additional_serverless_mongoses )
407- else :
410+ address = self .client .address
411+ self .mongoses .append (address )
412+ if not self .serverless :
408413 # Check for another mongos on the next port.
409- address = self .client .address
410414 next_address = address [0 ], address [1 ] + 1
411- self .mongoses .append (address )
412415 mongos_client = self ._connect (
413416 * next_address , ** self .default_client_options )
414417 if mongos_client :
0 commit comments