@@ -95,6 +95,43 @@ def test_tp2(self, num_reqs):
9595 assert similar (tokenizer .decode (result .outputs [0 ].token_ids ),
9696 'E F G H I J K L' )
9797
98+ def test_hmac_key_generation (self ):
99+ """Test that HMAC key is automatically generated and properly propagated."""
100+ tokenizer = TransformersTokenizer .from_pretrained (model_path )
101+ prompt = "A B C D"
102+ prompt_token_ids = tokenizer .encode (prompt )
103+ max_tokens = 8
104+
105+ with self .create_proxy (tp_size = 1 ) as proxy :
106+ assert proxy .hmac_key is not None , "HMAC key should be generated"
107+ assert len (
108+ proxy .hmac_key
109+ ) == 32 , f"HMAC key should be 32 bytes, got { len (proxy .hmac_key )} "
110+
111+ # Verify key is properly stored in worker_kwargs
112+ assert 'hmac_key' in proxy .worker_kwargs , "HMAC key should be in worker_kwargs"
113+ assert proxy .worker_kwargs [
114+ 'hmac_key' ] is not None , "HMAC key in worker_kwargs should not be None"
115+
116+ # Verify both references point to the same key object
117+ assert proxy .hmac_key is proxy .worker_kwargs ['hmac_key' ], \
118+ "HMAC key should be the same object in both locations"
119+
120+ logger_debug (
121+ f"[Test] HMAC key verified: length={ len (proxy .hmac_key )} bytes" ,
122+ color = "green" )
123+
124+ # Verify RPC communication works with the generated key
125+ sampling_params = SamplingParams (max_tokens = max_tokens )
126+ result = proxy .generate (prompt_token_ids , sampling_params )
127+ assert similar (
128+ tokenizer .decode (result .outputs [0 ].token_ids ), 'E F G H I J K L'
129+ ), "Generation should work with auto-generated HMAC key"
130+
131+ logger_debug (
132+ f"[Test] HMAC key test passed: RPC communication successful" ,
133+ color = "green" )
134+
98135
99136if __name__ == "__main__" :
100137 TestRpcProxy ().test_tp1 (20 )
0 commit comments