MCPcopy Create free account
hub / github.com/nlweb-ai/NLWeb / LoadTestClient

Class LoadTestClient

tests/performance/test_load.py:140–229  ·  view source on GitHub ↗

Simulated client for load testing.

Source from the content-addressed store, hash-verified

138
139
140class LoadTestClient:
141 """Simulated client for load testing."""
142
143 def __init__(self, client_id: str, http_client: httpx.AsyncClient):
144 self.client_id = client_id
145 self.http_client = http_client
146 self.conversation_id = None
147 self.messages_sent = 0
148 self.messages_received = 0
149 self.errors = 0
150
151 async def create_conversation(self, participant_count: int = 1):
152 """Create a conversation for load testing."""
153 try:
154 start_time = time.perf_counter()
155
156 participants = [
157 {"participantId": f"{self.client_id}_user_{i}", "displayName": f"User {i}"}
158 for i in range(participant_count)
159 ]
160
161 response = await self.http_client.post(
162 "/chat/create",
163 json={
164 "title": f"Load Test {self.client_id}",
165 "sites": ["example.com"],
166 "mode": "list",
167 "participant": participants[0],
168 "additional_participants": participants[1:] if len(participants) > 1 else []
169 },
170 headers={"Authorization": f"Bearer token_{self.client_id}"}
171 )
172
173 if response.status_code == 201:
174 data = response.json()
175 self.conversation_id = data["id"]
176
177 end_time = time.perf_counter()
178 return end_time - start_time
179
180 except Exception as e:
181 self.errors += 1
182 return None
183
184 async def send_message(self, content: str):
185 """Send a message in the conversation."""
186 if not self.conversation_id:
187 return None
188
189 try:
190 start_time = time.perf_counter()
191
192 response = await self.http_client.post(
193 f"/chat/{self.conversation_id}/message",
194 json={"content": content},
195 headers={"Authorization": f"Bearer token_{self.client_id}"}
196 )
197

Calls

no outgoing calls