File "/media/jawahar/jon1/new_project/bm/testDev/lib/python3.6/site-packages/locust/core.py", line 268, in run
self.schedule_task(self.get_next_task())
File "/media/jawahar/jon1/new_project/bm/testDev/lib/python3.6/site-packages/locust/core.py", line 329, in get_next_task
return random.choice(self.tasks)
File "/media/jawahar/jon1/new_project/bm/testDev/lib/python3.6/random.py", line 258, in choice
raise IndexError('Cannot choose from an empty sequence') from None
IndexError: Cannot choose from an empty sequence
Repeately i am getting this error after Start swarming number of users.
No Error related to this.
Traceback showed about
Run some api and you will get this error
IndexError: Cannot choose from an empty sequence
@jawahar273,
That exception gets raised when there are no tasks defined. Can you verify you actually declared some tasks in your locustfile? (either use the @tasks decorator or define a class that inherits from TaskSet)
for Locust devs,
A nice enhancement would be to catch the IndexError in /locust/core.py and raise a RuntimeError instead.. It should display an intuitive message like "No tasks defined in locustfile", and then exit.
ah.. we should check for this in code.
import logging
from locust import TaskSet, task
logger = logging.getLogger(__name__)
class UserBehavior(TaskSet):
def __init__(self, parent):
super().__init__(parent=parent)
self.token_key = "Token "
def base_url(self):
return "/api/"
def packages_url(self):
return self.base_url() + "package/"
def user_details(self):
return {"username": "demo", "password": "demobmmb"}
def on_start(self):
""" on_start is called
when a Locust start before
any task is scheduled
"""
self.login()
def login(self):
# self.token_key = 'Token '
logger.info("login user")
response = self.client.post(
self.base_url() + "rest-auth/login/", data=self.user_details()
)
self.token_key = self.token_key + response.text
logger.debug("response from host" + str(response))
print("Response status code:", response.status_code)
print("Response content:", response.text)
@task(1)
def currency_details(self):
currency = self.client.get(
self.packages_url() + "currency/",
headers={"authentication": self.token_key},
)
if currency.status_code >= 300:
logger.debug("response from host for currency" + currency.text)
else:
logger.info("success in currency", currency.status_code)
This is the actual code.
what are the items in "Addtion feedback" about?
Leave it.
Did you get the error that I was trying to show.
Did you get the error that I was trying to show
no
Yes i got the error after removing the @task(1) and if you run the code with @task(1) there is no error in running the locust.
Is this a series issue or not.
if you write an invalid locustfile and don't declare tasks, expect things to break. As I said previously, the error message could be improved.
Most helpful comment
@jawahar273,
That exception gets raised when there are no tasks defined. Can you verify you actually declared some tasks in your locustfile? (either use the
@tasksdecorator or define a class that inherits fromTaskSet)for Locust devs,
A nice enhancement would be to catch the
IndexErrorin/locust/core.pyand raise aRuntimeErrorinstead.. It should display an intuitive message like "No tasks defined in locustfile", and then exit.