@@ -244,11 +244,6 @@ async def test_invalid_database_id_configuration_error(self, request):
244244 with pytest .raises (ValueError , match = "database_id must be non-negative" ):
245245 await create_client (request , cluster_mode = False , database_id = - 1 )
246246
247- with pytest .raises (
248- ValueError , match = "database_id must be less than or equal to 15"
249- ):
250- await create_client (request , cluster_mode = False , database_id = 16 )
251-
252247 @pytest .mark .asyncio
253248 async def test_select_command_error_handling (self , request ):
254249 """Test error handling for SELECT command with invalid database numbers."""
@@ -326,3 +321,139 @@ async def test_explicit_database_zero_same_as_default(self, request):
326321 finally :
327322 await client_explicit .close ()
328323 await client_default .close ()
324+
325+
326+ class TestBroaderDatabaseIdRanges :
327+ """Test database_id functionality with broader ranges beyond typical 0-15."""
328+
329+ @pytest .mark .asyncio
330+ async def test_standalone_client_with_higher_database_ids (self , request ):
331+ """Test creating standalone client with database IDs beyond typical range."""
332+ # Test with database_id = 50
333+ try :
334+ client = await create_client (request , cluster_mode = False , database_id = 50 )
335+ try :
336+ # Try to set a value - this may fail if server doesn't support DB 50
337+ await client .set ("test_key_50" , "test_value_50" )
338+ result = await client .get ("test_key_50" )
339+ assert result == b"test_value_50"
340+ except RequestError as e :
341+ # Server-side validation should handle out-of-range database IDs
342+ assert "DB index is out of range" in str (
343+ e
344+ ) or "invalid DB index" in str (e )
345+ finally :
346+ await client .close ()
347+ except RequestError as e :
348+ # Connection-time error for invalid database
349+ assert "DB index is out of range" in str (e ) or "invalid DB index" in str (e )
350+
351+ @pytest .mark .asyncio
352+ async def test_standalone_client_with_very_high_database_ids (self , request ):
353+ """Test creating standalone client with very high database IDs."""
354+ # Test with database_id = 999
355+ try :
356+ client = await create_client (request , cluster_mode = False , database_id = 999 )
357+ try :
358+ # Try to set a value - this should fail with server-side validation
359+ await client .set ("test_key_999" , "test_value_999" )
360+ # If we get here, the server supports DB 999
361+ result = await client .get ("test_key_999" )
362+ assert result == b"test_value_999"
363+ except RequestError as e :
364+ # Expected: server-side validation should handle out-of-range database IDs
365+ assert "DB index is out of range" in str (
366+ e
367+ ) or "invalid DB index" in str (e )
368+ finally :
369+ await client .close ()
370+ except RequestError as e :
371+ # Connection-time error for invalid database
372+ assert "DB index is out of range" in str (e ) or "invalid DB index" in str (e )
373+
374+ @pytest .mark .asyncio
375+ async def test_cluster_client_with_higher_database_ids (self , request ):
376+ """Test creating cluster client with database IDs beyond typical range."""
377+ # Check if cluster supports multi-DB
378+ supports_multi_db , skip_reason = await check_cluster_multi_db_support (request )
379+ if not supports_multi_db :
380+ pytest .skip (skip_reason )
381+
382+ # Test with database_id = 100
383+ try :
384+ client = await create_client (request , cluster_mode = True , database_id = 100 )
385+ try :
386+ # Try to set a value - this may fail if server doesn't support DB 100
387+ await client .set ("test_key_100" , "test_value_100" )
388+ result = await client .get ("test_key_100" )
389+ assert result == b"test_value_100"
390+ except RequestError as e :
391+ # Server-side validation should handle out-of-range database IDs
392+ assert "DB index is out of range" in str (
393+ e
394+ ) or "invalid DB index" in str (e )
395+ finally :
396+ await client .close ()
397+ except RequestError as e :
398+ # Connection-time error for invalid database
399+ assert "DB index is out of range" in str (e ) or "invalid DB index" in str (e )
400+
401+
402+ class TestServerSideValidation :
403+ """Test that server-side validation is properly handled for out-of-range database IDs."""
404+
405+ @pytest .mark .asyncio
406+ async def test_server_side_validation_for_out_of_range_database_ids (self , request ):
407+ """Test that server-side validation errors are properly propagated."""
408+ # Try to connect with a database ID that's likely out of range
409+ very_high_db_id = 9999
410+
411+ try :
412+ client = await create_client (
413+ request , cluster_mode = False , database_id = very_high_db_id
414+ )
415+ try :
416+ # If connection succeeds, try an operation
417+ await client .set ("test_key" , "test_value" )
418+ # If this succeeds, the server supports this database ID
419+ result = await client .get ("test_key" )
420+ assert result == b"test_value"
421+ except RequestError as e :
422+ # Expected: server should reject operations on invalid database
423+ assert "DB index is out of range" in str (
424+ e
425+ ) or "invalid DB index" in str (e )
426+ finally :
427+ await client .close ()
428+ except RequestError as e :
429+ # Expected: server should reject connection to invalid database
430+ assert "DB index is out of range" in str (e ) or "invalid DB index" in str (e )
431+
432+ @pytest .mark .asyncio
433+ async def test_select_command_server_side_validation (self , request ):
434+ """Test that SELECT command with out-of-range database IDs is handled by server."""
435+ client = await create_client (request , cluster_mode = False , database_id = 0 )
436+
437+ try :
438+ # Try to select a database that's likely out of range
439+ with pytest .raises (RequestError , match = "DB index is out of range" ):
440+ await client .select (9999 )
441+ finally :
442+ await client .close ()
443+
444+ @pytest .mark .asyncio
445+ async def test_cluster_select_command_server_side_validation (self , request ):
446+ """Test that SELECT command in cluster mode with out-of-range database IDs is handled by server."""
447+ # Check if cluster supports multi-DB
448+ supports_multi_db , skip_reason = await check_cluster_multi_db_support (request )
449+ if not supports_multi_db :
450+ pytest .skip (skip_reason )
451+
452+ client = await create_client (request , cluster_mode = True , database_id = 0 )
453+
454+ try :
455+ # Try to select a database that's likely out of range
456+ with pytest .raises (RequestError , match = "DB index is out of range" ):
457+ await client .select (9999 , route = AllNodes ())
458+ finally :
459+ await client .close ()
0 commit comments