Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for tests that use multiple hosts #150

Closed
jpotter opened this issue May 8, 2014 · 6 comments
Closed

Support for tests that use multiple hosts #150

jpotter opened this issue May 8, 2014 · 6 comments

Comments

@jpotter
Copy link

jpotter commented May 8, 2014

Our system runs two different hostnames (one for web, one for api requests), and it's not clear to me how to write a locust that would handle this. The --host option being passed to locust only allows passing one hostname (and assumes that the host resolves to the IP in question -- in a testing setup, the Host: header in the request to the web server might not resolve, as in testing during a build).

Suggestions?

Thanks,
Jeff

@heyman
Copy link
Member

heyman commented May 9, 2014

You can actually make requests to different hosts, simply by specifying a full URL, however the hostname will not appear in the statistics entry, so requests to different hosts, but with the same path, will appear as a single stats entry:

self.client.get("/some/path")
self.client.get("http://other.host/some/path")

If you want them to be separate stats entries, you could override the entry name using the name parameter:

self.client.get("http://other.host/some/path", name="http://other.host/some/path")

If you could live with that, you could then specify a second host using an environment variable. Perhaps something like this:

import os

from locust import HttpLocust
from locust.clients import HttpSession

class MultipleHostsLocust(HttpLocust):
    abstract = True

    def __init__(self, *args, **kwargs):
        super(MultipleHostsLocust, self).__init__(*args, **kwargs)
        self.api_client = HttpSession(base_url=os.environ["API_HOST"])

@jpotter
Copy link
Author

jpotter commented May 9, 2014

Hi Jonatan,

Thanks! I was able to get this working this way, and it makes sense. Locust looks like a really great tool for running these sorts of tests, and looking forward to getting it used as part of our production system!

best,
Jeff

@jpotter jpotter closed this as completed May 9, 2014
@heyman
Copy link
Member

heyman commented May 11, 2014

Glad to hear that :)!

You could also expand on my suggestion above, to make the api_client automatically set the name parameter, by subclassing the HttpSession class.

@andrewmichaelsmith
Copy link

This also solved my problem. It would however be quite nice if I could leave "host" as blank totally. For cases where I write tests that always pass a full URL.

@IProkopenko
Copy link

thank you guys, super useful

@ashsepra
Copy link

it's working on me, thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants