locust 2.29.2.dev26__py3-none-any.whl → 2.29.2.dev34__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
@@ -12,5 +12,5 @@ __version__: str
12
12
  __version_tuple__: VERSION_TUPLE
13
13
  version_tuple: VERSION_TUPLE
14
14
 
15
- __version__ = version = '2.29.2.dev26'
16
- __version_tuple__ = version_tuple = (2, 29, 2, 'dev26')
15
+ __version__ = version = '2.29.2.dev34'
16
+ __version_tuple__ = version_tuple = (2, 29, 2, 'dev34')
locust/stats.py CHANGED
@@ -9,25 +9,12 @@ import signal
9
9
  import time
10
10
  from abc import abstractmethod
11
11
  from collections import OrderedDict, defaultdict, namedtuple
12
- from collections import (
13
- OrderedDict as OrderedDictType,
14
- )
15
12
  from collections.abc import Iterable
16
13
  from copy import copy
17
14
  from html import escape
18
15
  from itertools import chain
19
- from tempfile import NamedTemporaryFile
20
16
  from types import FrameType
21
- from typing import (
22
- TYPE_CHECKING,
23
- Any,
24
- Callable,
25
- NoReturn,
26
- Protocol,
27
- TypedDict,
28
- TypeVar,
29
- cast,
30
- )
17
+ from typing import TYPE_CHECKING, Any, Callable, NoReturn, Protocol, TypedDict, TypeVar, cast
31
18
 
32
19
  import gevent
33
20
 
@@ -319,12 +306,12 @@ class StatsEntry:
319
306
  A {response_time => count} dict that holds the response time distribution of all
320
307
  the requests.
321
308
 
322
- The keys (the response time in ms) are rounded to store 1, 2, ... 9, 10, 20. .. 90,
323
- 100, 200 .. 900, 1000, 2000 ... 9000, in order to save memory.
309
+ The keys (the response time in ms) are rounded to store 1, 2, ... 98, 99, 100, 110, 120, ... 980, 990, 1000,
310
+ 1100, 1200, ... 9800, 9900, 10_000, 11_000, 12_000 ... in order to save memory.
324
311
 
325
312
  This dict is used to calculate the median and percentile response times.
326
313
  """
327
- self.response_times_cache: OrderedDictType[int, CachedResponseTimes] | None = None
314
+ self.response_times_cache: OrderedDict[int, CachedResponseTimes] | None = None
328
315
  """
329
316
  If use_response_times_cache is set to True, this will be a {timestamp => CachedResponseTimes()}
330
317
  OrderedDict that holds a copy of the response_times dict for each of the last 20 seconds.
@@ -34,6 +34,26 @@ class TestTaskSet(LocustTestCase):
34
34
  self.assertRaises(RescheduleTask, lambda: l.run())
35
35
  self.assertEqual([1, 2, 3], log)
36
36
 
37
+ def test_task_sequence_with_dictionary(self):
38
+ log = []
39
+
40
+ def t1(self):
41
+ log.append(1)
42
+
43
+ def t2(self):
44
+ log.append(2)
45
+
46
+ def t3(self):
47
+ log.append(3)
48
+ self.interrupt(reschedule=False)
49
+
50
+ class MyTaskSequence(SequentialTaskSet):
51
+ tasks = {t1: 3, t2: 2, t3: 1}
52
+
53
+ l = MyTaskSequence(self.locust)
54
+ self.assertRaises(RescheduleTask, lambda: l.run())
55
+ self.assertEqual([1, 1, 1, 2, 2, 3], log)
56
+
37
57
  def test_task_sequence_with_methods(self):
38
58
  log = []
39
59
 
@@ -1,6 +1,6 @@
1
1
  from locust.exception import LocustError
2
2
 
3
- import logging
3
+ from itertools import cycle
4
4
 
5
5
  from .task import TaskSet, TaskSetMeta
6
6
 
@@ -26,8 +26,12 @@ class SequentialTaskSetMeta(TaskSetMeta):
26
26
  # compared to methods declared with @task
27
27
  if isinstance(value, list):
28
28
  new_tasks.extend(value)
29
+ elif isinstance(value, dict):
30
+ for task, weight in value.items():
31
+ for _ in range(weight):
32
+ new_tasks.append(task)
29
33
  else:
30
- raise ValueError("On SequentialTaskSet the task attribute can only be set to a list")
34
+ raise ValueError("The 'tasks' attribute can only be set to list or dict")
31
35
 
32
36
  if "locust_task_weight" in dir(value):
33
37
  # method decorated with @task
@@ -52,13 +56,11 @@ class SequentialTaskSet(TaskSet, metaclass=SequentialTaskSetMeta):
52
56
 
53
57
  def __init__(self, *args, **kwargs):
54
58
  super().__init__(*args, **kwargs)
55
- self._task_index = 0
59
+ self._task_cycle = cycle(self.tasks)
56
60
 
57
61
  def get_next_task(self):
58
62
  if not self.tasks:
59
63
  raise LocustError(
60
64
  "No tasks defined. Use the @task decorator or set the 'tasks' attribute of the SequentialTaskSet"
61
65
  )
62
- task = self.tasks[self._task_index % len(self.tasks)]
63
- self._task_index += 1
64
- return task
66
+ return next(self._task_cycle)