Search code examples
pythonrestlocust

How to use multiple hosts in multiple classes in Locust


I need to test some APIs having different addresses, I have created locustfile for Locust Tool as mentioned below, but only api1 is working, endpoints in api2 are not being called

from locust import HttpUser, task, between

class api1(HttpUser):

    host = 'http://localhost:6001'
    wait_time = between(2, 4)

    @task()
    def api1_ep1(self):
        self.client.post('/ep1')
        
    @task()
    def api1_ep2(self):
        self.client.post('/ep2')
        
class api2(HttpUser):

    host = 'http://localhost:6002'
    wait_time = between(2, 4)

    @task()
    def api2_ep1(self):
        self.client.post('/ep1')

    @task()
    def api2_ep2(self):
        self.client.post('/ep2')

I tried suggestions from issue: 150 and put full path as self.client.post('http://localhost:6001/ep1') but the same problem persists


Solution

  • I was spawning single user, spawning more users fixed the probem