locust 2.29.2.dev15__py3-none-any.whl → 2.29.2.dev32__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.dev15'
16
- __version_tuple__ = version_tuple = (2, 29, 2, 'dev15')
15
+ __version__ = version = '2.29.2.dev32'
16
+ __version_tuple__ = version_tuple = (2, 29, 2, 'dev32')
@@ -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)