Skip to content

Commit

Permalink
request id in Testdata* messages
Browse files Browse the repository at this point in the history
  • Loading branch information
mgor committed Nov 18, 2024
1 parent f3f0211 commit 85042f0
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
2 changes: 1 addition & 1 deletion grizzly/scenarios/iterator.py
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ def pace(self) -> None:
debug_logger.debug('scenario %s slept %d milliseconds to keep pace', self.logger.name, pace_correction * 1000)
response_length = 1
else:
self.logger.error('pace falling behind, currently at %d milliseconds expecting %f milliseconds', abs(pace_correction * 1000), value)
self.logger.error('pace falling behind, currently at %d milliseconds expecting %.2f milliseconds', abs(pace_correction * 1000), value)
message = f'pace falling behind, iteration takes longer than {value} milliseconds'
raise RuntimeError(message)
except Exception as e:
Expand Down
7 changes: 5 additions & 2 deletions grizzly/testdata/communication.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from pathlib import Path
from time import perf_counter
from typing import TYPE_CHECKING, Any, ClassVar, Optional, cast
from uuid import uuid4

from gevent import sleep as gsleep
from gevent.event import AsyncResult
Expand Down Expand Up @@ -244,12 +245,13 @@ def _keystore_request(self, *, request: dict[str, Any]) -> dict[str, Any] | None
def _request(self, request: dict[str, str]) -> dict[str, Any] | None:
with self.semaphore:
uid = id(self.scenario.user)
request_id = str(uuid4())

if uid in self._responses:
self.logger.warning('greenlet %d is already waiting for testdata', uid)

self._responses.update({uid: AsyncResult()})
self.runner.send_message('produce_testdata', {'uid': uid, 'cid': self.runner.client_id, 'request': request})
self.runner.send_message('produce_testdata', {'uid': uid, 'cid': self.runner.client_id, 'id': request_id, 'request': request})

# waits for async result
try:
Expand Down Expand Up @@ -504,6 +506,7 @@ def handle_request(self, environment: Environment, msg: Message, **_kwargs: Any)
uid = msg.data['uid']
cid = msg.data['cid']
request = msg.data['request']
request_id = msg.data['id']

if request['message'] == 'keystore':
response = self._handle_request_keystore(request=request)
Expand All @@ -513,4 +516,4 @@ def handle_request(self, environment: Environment, msg: Message, **_kwargs: Any)
self.logger.error('received unknown message "%s"', request['message'])
response = {}

self.runner.send_message('consume_testdata', {'uid': uid, 'response': response}, client_id=cid)
self.runner.send_message('consume_testdata', {'uid': uid, 'id': request_id, 'response': response}, client_id=cid)
2 changes: 1 addition & 1 deletion grizzly_extras/async_message/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def async_message_request(client: ztypes.Socket, request: AsyncMessageRequest) -
break

delta = perf_counter() - start
logger.debug('async_message_request::recv_json took %f seconds for request_id %s, after %d retries', delta, request['request_id'], count)
logger.debug('async_message_request::recv_json: took %f seconds for request_id %s, after %d retries', delta, request['request_id'], count)

if response is None:
msg = 'no response'
Expand Down

0 comments on commit 85042f0

Please sign in to comment.