@@ -43,8 +43,32 @@ def setUpClass(cls):
43
43
["trl" , "vllm-serve" , "--model" , cls .model_id ], stdout = subprocess .PIPE , stderr = subprocess .PIPE , env = env
44
44
)
45
45
46
- # Initialize the client
47
- cls .client = VLLMClient (connection_timeout = 120 )
46
+ # Initialize the clients using both initialization methods
47
+ cls .client = VLLMClient (connection_timeout = 120 ) # Default host and port
48
+ cls .client_base_url = VLLMClient (base_url = "http://0.0.0.0:8000" , connection_timeout = 120 ) # Using base_url
49
+
50
+ def test_initialization_methods (self ):
51
+ """Test that both initialization methods work correctly."""
52
+ # Test generation with default client (host+port)
53
+ prompts = ["Test initialization 1" ]
54
+ outputs_default = self .client .generate (prompts )
55
+ self .assertIsInstance (outputs_default , list )
56
+ self .assertEqual (len (outputs_default ), len (prompts ))
57
+
58
+ # Test generation with base_url client
59
+ outputs_base_url = self .client_base_url .generate (prompts )
60
+ self .assertIsInstance (outputs_base_url , list )
61
+ self .assertEqual (len (outputs_base_url ), len (prompts ))
62
+
63
+ def test_base_url_attribute (self ):
64
+ """Test that both initialization methods set the base_url attribute correctly."""
65
+ # Both clients should have the same base_url
66
+ self .assertEqual (self .client .base_url , "http://0.0.0.0:8000" )
67
+ self .assertEqual (self .client_base_url .base_url , "http://0.0.0.0:8000" )
68
+
69
+ # Verify the client doesn't store host/port when base_url is provided
70
+ self .assertTrue (not hasattr (self .client_base_url , 'host' ) or self .client_base_url .host is None )
71
+ self .assertTrue (not hasattr (self .client_base_url , 'server_port' ) or self .client_base_url .server_port is None )
48
72
49
73
def test_generate (self ):
50
74
prompts = ["Hello, AI!" , "Tell me a joke" ]
@@ -90,8 +114,9 @@ def test_reset_prefix_cache(self):
90
114
def tearDownClass (cls ):
91
115
super ().tearDownClass ()
92
116
93
- # Close the client
117
+ # Close the clients
94
118
cls .client .close_communicator ()
119
+ cls .client_base_url .close_communicator ()
95
120
96
121
# vLLM x pytest (or Popen) seems not to handle process termination well. To avoid zombie processes, we need to
97
122
# kill the server process and its children explicitly.
@@ -122,8 +147,32 @@ def setUpClass(cls):
122
147
env = env ,
123
148
)
124
149
125
- # Initialize the client
126
- cls .client = VLLMClient (connection_timeout = 120 )
150
+ # Initialize the clients using both initialization methods
151
+ cls .client = VLLMClient (connection_timeout = 120 ) # Default host and port
152
+ cls .client_base_url = VLLMClient (base_url = "http://0.0.0.0:8000" , connection_timeout = 120 ) # Using base_url
153
+
154
+ def test_initialization_methods (self ):
155
+ """Test that both initialization methods work correctly with tensor parallelism enabled."""
156
+ # Test generation with default client (host+port)
157
+ prompts = ["Test TP initialization 1" ]
158
+ outputs_default = self .client .generate (prompts )
159
+ self .assertIsInstance (outputs_default , list )
160
+ self .assertEqual (len (outputs_default ), len (prompts ))
161
+
162
+ # Test generation with base_url client
163
+ outputs_base_url = self .client_base_url .generate (prompts )
164
+ self .assertIsInstance (outputs_base_url , list )
165
+ self .assertEqual (len (outputs_base_url ), len (prompts ))
166
+
167
+ def test_base_url_attribute (self ):
168
+ """Test that both initialization methods set the base_url attribute correctly."""
169
+ # Both clients should have the same base_url
170
+ self .assertEqual (self .client .base_url , "http://0.0.0.0:8000" )
171
+ self .assertEqual (self .client_base_url .base_url , "http://0.0.0.0:8000" )
172
+
173
+ # Verify the client doesn't store host/port when base_url is provided
174
+ self .assertTrue (not hasattr (self .client_base_url , 'host' ) or self .client_base_url .host is None )
175
+ self .assertTrue (not hasattr (self .client_base_url , 'server_port' ) or self .client_base_url .server_port is None )
127
176
128
177
def test_generate (self ):
129
178
prompts = ["Hello, AI!" , "Tell me a joke" ]
@@ -151,8 +200,9 @@ def test_reset_prefix_cache(self):
151
200
def tearDownClass (cls ):
152
201
super ().tearDownClass ()
153
202
154
- # Close the client
203
+ # Close the clients
155
204
cls .client .close_communicator ()
205
+ cls .client_base_url .close_communicator ()
156
206
157
207
# vLLM x pytest (or Popen) seems not to handle process termination well. To avoid zombie processes, we need to
158
208
# kill the server process and its children explicitly.
0 commit comments