locust 2.40.2.dev7__py3-none-any.whl → 2.40.2.dev15__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
locust/_version.py CHANGED
@@ -28,7 +28,7 @@ version_tuple: VERSION_TUPLE
28
28
  commit_id: COMMIT_ID
29
29
  __commit_id__: COMMIT_ID
30
30
 
31
- __version__ = version = '2.40.2.dev7'
32
- __version_tuple__ = version_tuple = (2, 40, 2, 'dev7')
31
+ __version__ = version = '2.40.2.dev15'
32
+ __version_tuple__ = version_tuple = (2, 40, 2, 'dev15')
33
33
 
34
34
  __commit_id__ = commit_id = None
@@ -1,63 +1,34 @@
1
1
  from locust import User
2
+ from locust.event import EventHook
3
+
4
+ from typing import Any
2
5
 
3
6
  import gevent
4
7
  import socketio
5
8
 
6
9
 
7
- class SocketIOUser(User):
8
- """
9
- SocketIOUser wraps an instance of :class:`socketio.Client` to log requests.
10
- See example in :gh:`examples/socketio/socketio_ex.py`.
11
- """
12
-
13
- abstract = True
14
- options: dict = {}
15
- """socketio.Client options, e.g. `{"reconnection_attempts": 1, "reconnection_delay": 2}`"""
16
- client: socketio.Client
17
- """The underlying :class:`socketio.Client` instance. Can be useful to call directly if you want to skip logging a requests."""
18
-
19
- def __init__(self, *args, **kwargs):
10
+ class SocketIOClient(socketio.Client):
11
+ def __init__(self, request_event: EventHook, *args, **kwargs):
20
12
  super().__init__(*args, **kwargs)
21
- self.client = socketio.Client(**self.options)
22
- self.ws_greenlet = gevent.spawn(self.client.wait)
23
- self.client.on("*", self.on_message)
24
-
25
- #
26
- def on_message(self, event: str, data: str) -> None:
27
- """
28
- This is the default handler for events. You can override it for custom behavior,
29
- or even register separate handlers using self.client.on(event, handler)
30
-
31
- Measuring response_time isn't obvious for for WebSockets. Sometimes a response time
32
- can be inferred from the event data (if it contains a timestamp) or related to
33
- a message that you sent. Override this method in your User class to do that.
34
- """
35
- self.environment.events.request.fire(
36
- request_type="WSR",
37
- name=event,
38
- response_time=0,
39
- response_length=len(data or []),
40
- exception=None,
41
- context={},
42
- )
13
+ self.request_event = request_event
43
14
 
44
15
  def connect(self, *args, **kwargs):
45
16
  """
46
17
  Wraps :meth:`socketio.Client.connect`.
47
18
  """
48
- with self.environment.events.request.measure("WS", "connect") as _:
49
- self.client.connect(*args, **kwargs)
19
+ with self.request_event.measure("WS", "connect") as _:
20
+ super().connect(*args, **kwargs)
50
21
 
51
- def send(self, name, data=None, namespace=None) -> None:
22
+ def send(self, data, namespace=None, callback=None, name="Unnamed") -> None:
52
23
  """
53
24
  Wraps :meth:`socketio.Client.send`.
54
25
  """
55
26
  exception = None
56
27
  try:
57
- self.client.send(data, namespace)
28
+ super().send(data, namespace, callback)
58
29
  except Exception as e:
59
30
  exception = e
60
- self.environment.events.request.fire(
31
+ self.request_event.fire(
61
32
  request_type="WSS",
62
33
  name=name,
63
34
  response_time=0,
@@ -66,18 +37,18 @@ class SocketIOUser(User):
66
37
  context={},
67
38
  )
68
39
 
69
- def emit(self, name, data=None, namespace=None, callback=None) -> None:
40
+ def emit(self, event, data=None, namespace=None, callback=None) -> None:
70
41
  """
71
42
  Wraps :meth:`socketio.Client.emit`.
72
43
  """
73
44
  exception = None
74
45
  try:
75
- self.client.emit(name, data, namespace, callback)
46
+ super().emit(event, data, namespace, callback)
76
47
  except Exception as e:
77
48
  exception = e
78
- self.environment.events.request.fire(
49
+ self.request_event.fire(
79
50
  request_type="WSE",
80
- name=name,
51
+ name=str(event),
81
52
  response_time=0,
82
53
  response_length=len(data or []),
83
54
  exception=exception,
@@ -88,8 +59,41 @@ class SocketIOUser(User):
88
59
  """
89
60
  Wraps :meth:`socketio.Client.call`.
90
61
  """
91
- with self.environment.events.request.measure("WSC", event) as _:
92
- return self.client.call(event, data, *args, **kwargs)
62
+ with self.request_event.measure("WSC", event) as _:
63
+ return super().call(event, data, *args, **kwargs)
93
64
 
94
- def on_stop(self):
95
- self.client.disconnect()
65
+ def on_message(self, event: str, data: str) -> None:
66
+ """
67
+ This is the default handler for events received.
68
+ You can register separate handlers using self.sio.on(event, handler)
69
+
70
+ Measuring response_time isn't obvious for for WebSockets/SocketIO so we set them to 0.
71
+ Sometimes response time can be inferred from the event data (if it contains a timestamp)
72
+ or related to a message that you sent. Override this method in your User class to do that.
73
+ """
74
+ self.request_event.fire(
75
+ request_type="WSR",
76
+ name=event,
77
+ response_time=0,
78
+ response_length=len(data or []),
79
+ exception=None,
80
+ context={},
81
+ )
82
+
83
+
84
+ class SocketIOUser(User):
85
+ """
86
+ SocketIOUser creates an instance of :class:`socketio.Client` to log requests.
87
+ See example in :gh:`examples/socketio/socketio_ex.py`.
88
+ """
89
+
90
+ abstract = True
91
+ options: dict[str, Any] = {}
92
+ """socketio.Client options, e.g. `{"reconnection_attempts": 1, "reconnection_delay": 2, "logger": True, "engineio_logger": True}`"""
93
+ sio: SocketIOClient
94
+
95
+ def __init__(self, *args, **kwargs):
96
+ super().__init__(*args, **kwargs)
97
+ self.sio = SocketIOClient(self.environment.events.request, **self.options)
98
+ self.sio_greenlet = gevent.spawn(self.sio.wait)
99
+ self.sio.on("*", self.sio.on_message)
@@ -101,7 +101,13 @@ def load_locustfile_pytest(path) -> dict[str, type[User]]:
101
101
  """
102
102
  user_classes: dict[str, type[PytestUser]] = {}
103
103
  # collect tests and set up fixture manager
104
- config = Config.fromdictargs({}, [path])
104
+ config = Config.fromdictargs(
105
+ {},
106
+ [
107
+ "-q", # suppress pytest loggings about "test session starts" and "collected 0 items" etc
108
+ path,
109
+ ],
110
+ )
105
111
  config._do_configure()
106
112
  session = pytest.Session.from_config(config)
107
113
  config.hook.pytest_sessionstart(session=session)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: locust
3
- Version: 2.40.2.dev7
3
+ Version: 2.40.2.dev15
4
4
  Summary: Developer-friendly load testing framework
5
5
  Project-URL: homepage, https://locust.io/
6
6
  Project-URL: repository, https://github.com/locustio/locust
@@ -1,6 +1,6 @@
1
1
  locust/__init__.py,sha256=HadpgGidiyCDPSKwkxrk1Qw6eB7dTmftNJVftuJzAiw,1876
2
2
  locust/__main__.py,sha256=vBQ82334kX06ImDbFlPFgiBRiLIinwNk3z8Khs6hd74,31
3
- locust/_version.py,sha256=k9dvWv0Lh6WMhqFmyxRYpc6BOML0ptyyGa_0bn7pVOw,719
3
+ locust/_version.py,sha256=1lUD_y3GdgwY5ZP5Qi49KZlF9bRAYb_27xyeCkXcsGk,721
4
4
  locust/argument_parser.py,sha256=t6mAoK9u13DxC9UH-alVqS6fFABFTyNWSJG89yQ4QQQ,33056
5
5
  locust/clients.py,sha256=Gj1rD73_G7G7f6bi0plDiN-GIDPTBng8pBY21cFozQc,20219
6
6
  locust/debug.py,sha256=7CCm8bIg44uGH2wqBlo1rXBzV2VzwPicLxLewz8r5CQ,5099
@@ -23,7 +23,7 @@ locust/contrib/milvus.py,sha256=YabgLd0lImzWupJFCm0OZAW-Nxeibwn91ldWpZ2irDo,1281
23
23
  locust/contrib/mongodb.py,sha256=1seUYgJOaNKwybYOP9PUEVhgl8hGy-G33f8lFj3R8W8,1246
24
24
  locust/contrib/oai.py,sha256=Ot3T8lp31ThckGbNps86oVvq6Vn845Eec0mxhDmONDE,2684
25
25
  locust/contrib/postgres.py,sha256=OuMWnGYN10K65Tq2axVESEW25Y0g5gJb0rK90jkcCJg,1230
26
- locust/contrib/socketio.py,sha256=PpXKHFTlQgFNNkdwU3N3AvJ18XERoQtxxTmOira0Lyo,3152
26
+ locust/contrib/socketio.py,sha256=iznaDtXx7ytd60-_oJAb6tc9T26tJ-NcL6vLeTh-AtQ,3236
27
27
  locust/rpc/__init__.py,sha256=5YOu-58XSnt-oWWNATgXLTNdYoDkkngwHNXprxkWKSM,99
28
28
  locust/rpc/protocol.py,sha256=n-rb3GZQcAlldYDj4E4GuFGylYj_26GSS5U29meft5Y,1282
29
29
  locust/rpc/zmqrpc.py,sha256=tMeLQiLII8QP29lAHGZsj5Pf5FsTL-X4wM0DrtR3ALw,3214
@@ -40,7 +40,7 @@ locust/util/date.py,sha256=2uZAY-fkJq7llUcVywTDTbe-_2IYumCv18n3Vrc75gw,833
40
40
  locust/util/deprecation.py,sha256=4my4IcFpbM6yEKr569GMUKMsS0ywp0N4JPhhwm3J1-w,2026
41
41
  locust/util/directory.py,sha256=2EeuVIIFEErm0OpNXdsEgQLx49jAXq-PvMj2uY0Mr8o,326
42
42
  locust/util/exception_handler.py,sha256=jTMyBq2a0O07fRjmqGkheyaPj58tUgnbbcjoesKGPws,797
43
- locust/util/load_locustfile.py,sha256=KzrLXeLDhWo7ia9hxACkuES7xykgaBlIt8yJQkHYs8U,4929
43
+ locust/util/load_locustfile.py,sha256=eZsH-gRkKSAk8hI5CRS72w1-DaKRvrd2udOddslWMMU,5077
44
44
  locust/util/rounding.py,sha256=5haxR8mKhATqag6WvPby-MSRRgIw5Ob6thbyvMYZM7o,92
45
45
  locust/util/timespan.py,sha256=Y0LtnhUq2Mq19p04u0XtBlYQ_-S2cRvwRdgru8W9WhA,986
46
46
  locust/util/url.py,sha256=s_W2PCxvxTWxWX0yUvp-8VBuQm881KwI5X9iifogZG4,321
@@ -56,8 +56,8 @@ locust/webui/dist/assets/terminal.gif,sha256=iw80LO2u0dnf4wpGfFJZauBeKTcSpw9iUfI
56
56
  locust/webui/dist/assets/testruns-dark.png,sha256=G4p2VZSBuuqF4neqUaPSshIp5OKQJ_Bvb69Luj6XuVs,125231
57
57
  locust/webui/dist/assets/testruns-light.png,sha256=JinGDiiBPOkhpfF-XCbmQqhRInqItrjrBTLKt5MlqVI,130301
58
58
  pytest_locust/plugin.py,sha256=WAyiRHLynXegbbX2DxIutPKO4PQRT6JdBFA7zbbaJgM,1469
59
- locust-2.40.2.dev7.dist-info/METADATA,sha256=WJA_0s4iY2M5xJZInyaJLnwCHyX8qaI0xYzBRGvq9oo,9598
60
- locust-2.40.2.dev7.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
61
- locust-2.40.2.dev7.dist-info/entry_points.txt,sha256=0uIHcQ71R1qaWhM_sd8uBUCCJgp7gJfGHUVMnJeZfcY,86
62
- locust-2.40.2.dev7.dist-info/licenses/LICENSE,sha256=5hnz-Vpj0Z3kSCQl0LzV2hT1TLc4LHcbpBp3Cy-EuyM,1110
63
- locust-2.40.2.dev7.dist-info/RECORD,,
59
+ locust-2.40.2.dev15.dist-info/METADATA,sha256=Twi0mcXhfvVh7tKWHwHemQTdyVoDofdcAHnIYFD8JE0,9599
60
+ locust-2.40.2.dev15.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
61
+ locust-2.40.2.dev15.dist-info/entry_points.txt,sha256=0uIHcQ71R1qaWhM_sd8uBUCCJgp7gJfGHUVMnJeZfcY,86
62
+ locust-2.40.2.dev15.dist-info/licenses/LICENSE,sha256=5hnz-Vpj0Z3kSCQl0LzV2hT1TLc4LHcbpBp3Cy-EuyM,1110
63
+ locust-2.40.2.dev15.dist-info/RECORD,,