Locust.io, ¿cómo podría usar diferentes usuarios en locust.io sin que el sistema falle cuando inicio/detengo para una nueva ejecución?
Tengo este código que funciona bien para la primera ejecución en un servidor implementado de locust.io, pero cuando inicio/detengo para realizar una nueva ejecución, recibo varios errores con respecto a la lista. ¿Me podrían ayudar a poder ciclarlo?
from locust import HttpUser, task, between, SequentialTaskSet, events
import uuid
import json
import csv
import logging, sys, random, os
with open('somecsv.csv', 'r') as f:
reader = csv.reader(f)
user= list(reader)
#print(user)
class somethingclass(SequentialTaskSet):
def on_start(self):
if len(user) > 0:
self.id= str(user.pop()).strip("][''")
@task
def someting(self):
do something with self.id request
@task
def someting2(self):
do something with self.id request
class Main(HttpUser):
wait_time = between(5, 10)
tasks = [somethingclass]
def _init_(self, *args, **kwargs):
super(Main, self)._init_(*args, **kwargs)
los errores son:
[2020-08-18 23:06:50,899] PC/ERROR/locust.user.task: el objeto 'algoclase' no tiene atributo 'id' Rastreo (última llamada más reciente): Archivo "c:\windows\system32\src \locust\locust\user\task.py", línea 284, en run self.execute_next_task() Archivo "c:\windows\system32\src\locust\locust\user\task.py", línea 309, en execute_next_task self .execute_task(self._task_queue.pop(0)) Archivo "c:\windows\system32\src\locust\locust\user\task.py", línea 321, en execute_task task(self) Archivo "C:\Users\ usuario\Escritorio\Trabajo\Chipico Chip Transfer\chiptransfer_load.py", línea 44, en algo "uuid": '%s' % self.id, AttributeError: el objeto 'algoclase' no tiene atributo 'id'
Respuestas
Puede usar los eventos test_start y test_stop para restablecer sus user
datos.
from locust import User, task, constant, TaskSet, events
from logging import getLogger
import uuid
logger = getLogger("test")
user = []
@events.test_start.add_listener
def start_something(**kwargs):
logger.info("Starting test...")
user.append(uuid.uuid4())
class somethingclass(TaskSet):
@task
def do_something(self):
logger.info(f"User: {user}")
class Main(User):
wait_time = constant(2)
tasks = [somethingclass]
Esto me da el siguiente resultado con múltiples paradas y arranques de pruebas.
[2020-08-18 16:14:12,549] INFO/locust.main: Starting web interface at http://:8089
[2020-08-18 16:14:12,557] INFO/locust.main: Starting Locust 1.1.1
[2020-08-18 16:14:15,759] INFO/test: Starting test...
[2020-08-18 16:14:15,759] INFO/locust.runners: Hatching and swarming 1 users at the rate 1 users/s (0 users already running)...
[2020-08-18 16:14:15,759] INFO/locust.runners: All users hatched: Main: 1 (0 already running)
[2020-08-18 16:14:15,760] INFO/test: User: [UUID('f4e9d580-af4a-4fb7-804a-372faa8fcacd')]
[2020-08-18 16:14:17,764] INFO/test: User: [UUID('f4e9d580-af4a-4fb7-804a-372faa8fcacd')]
[2020-08-18 16:14:19,765] INFO/test: User: [UUID('f4e9d580-af4a-4fb7-804a-372faa8fcacd')]
[2020-08-18 16:14:21,767] INFO/test: User: [UUID('f4e9d580-af4a-4fb7-804a-372faa8fcacd')]
[2020-08-18 16:14:28,674] INFO/test: Starting test...
[2020-08-18 16:14:28,675] INFO/locust.runners: Hatching and swarming 1 users at the rate 1 users/s (0 users already running)...
[2020-08-18 16:14:28,675] INFO/locust.runners: All users hatched: Main: 1 (0 already running)
[2020-08-18 16:14:28,675] INFO/test: User: [UUID('f4e9d580-af4a-4fb7-804a-372faa8fcacd'), UUID('c061117e-f585-4da6-8188-59a0e1ff8acb')]
[2020-08-18 16:14:30,679] INFO/test: User: [UUID('f4e9d580-af4a-4fb7-804a-372faa8fcacd'), UUID('c061117e-f585-4da6-8188-59a0e1ff8acb')]
[2020-08-18 16:14:32,682] INFO/test: User: [UUID('f4e9d580-af4a-4fb7-804a-372faa8fcacd'), UUID('c061117e-f585-4da6-8188-59a0e1ff8acb')]
[2020-08-18 16:14:34,688] INFO/test: User: [UUID('f4e9d580-af4a-4fb7-804a-372faa8fcacd'), UUID('c061117e-f585-4da6-8188-59a0e1ff8acb')]
[2020-08-18 16:14:38,426] INFO/test: Starting test...
[2020-08-18 16:14:38,427] INFO/locust.runners: Hatching and swarming 1 users at the rate 1 users/s (0 users already running)...
[2020-08-18 16:14:38,427] INFO/locust.runners: All users hatched: Main: 1 (0 already running)
[2020-08-18 16:14:38,428] INFO/test: User: [UUID('f4e9d580-af4a-4fb7-804a-372faa8fcacd'), UUID('c061117e-f585-4da6-8188-59a0e1ff8acb'), UUID('cfd2a456-87d4-4cb2-b7d2-939bb1dfc560')]
[2020-08-18 16:14:40,433] INFO/test: User: [UUID('f4e9d580-af4a-4fb7-804a-372faa8fcacd'), UUID('c061117e-f585-4da6-8188-59a0e1ff8acb'), UUID('cfd2a456-87d4-4cb2-b7d2-939bb1dfc560')]
from locust import Usuario, tarea, constante, TaskSet, eventos del registro import getLogger import uuid
registrador = getLogger("prueba") usuario = []
@events.test_start.add_listener def start_something(**kwargs): logger.info("Iniciando prueba...") user.append(uuid.uuid4())
class somethingclass(TaskSet): @task def do_something(self): logger.info(f"User: {user}")
class Principal (Usuario): wait_time = constante (2) tareas = [algoclase]
es la respuesta correcta