async def run_user_queries(self, user: dict):
        """Run queries for a single user, with timeouts and error handling."""
        while self.running:
            # Login before query
            login_res = await self.safe_call(
                self.client.users.login(user["email"], user["password"]),
                timeout=LOGIN_TIMEOUT,
                operation_desc=f"login for querying {user['email']}",
            )
            if login_res is None:
                # Could not login, wait and try again
                await asyncio.sleep(1)
                continue

            # Perform random search
            query_1 = random.choice(QUERIES)
            query_2 = random.choice(QUERIES)
            query_3 = random.choice(QUERIES)
            query = f"{query_1} {query_2} {query_3}"

            start_time = time.time()

            search_res = await self.safe_call(
                self.client.retrieval.search(query),
                timeout=REQUEST_TIMEOUT,
                operation_desc=f"search '{query}' for {user['email']}",
            )

            end_time = time.time()
            duration_ms = (end_time - start_time) * 1000

            if search_res is not None:
                status = "success"
            else:
                status = "error"

            # Record metrics
            self.metrics.append(
                Metrics(
                    start_time=start_time,
                    end_time=end_time,
                    status=status,
                    duration_ms=duration_ms,
                ))

            # Wait according to queries per second rate
            await asyncio.sleep(max(0, 1 / QUERIES_PER_SECOND))
Run queries for a single user, with timeouts and error handling.
py/tests/scaling/loadTester.py