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

URL requests containing “/#/” are all seen as “/” then failing when running on Locust.io #768

Closed
pawlaguna opened this issue Mar 29, 2018 · 4 comments

Comments

@pawlaguna
Copy link

The requests containing "/#/" are all seen as "/". Then I'll get a ton of "fails".

from locust import HttpLocust, TaskSet, task
class UserBehavior(TaskSet):

@task(2)
def login_page(self):
    self.client.get("/")

@task(1)
def dashboard_page(self):
    self.client.get("/#/bubblesu")

@task(1)
def parents_page(self):
    self.client.get("/#/pages/parents")

class WebsiteUser(HttpLocust):
    task_set = UserBehavior

This is the result
image

There's no cmd errors in the prompt.

Then I tried to convince locust to name (and use) the proper ones. However naming worked, but it looks like the request are still made against "/". So in result I'm not able to load test each request.

My developer says "The hash sign is there because it's a single page application the path after that is just for routing via javascript. if you remove it the browser would try and find the page"

Here's the script

from locust import HttpLocust, TaskSet, task

class UserBehavior(TaskSet):

    @task(2)
    def login_page(self):
        self.client.get("/")

    @task(1)
    def dashboard_page(self):
        self.client.get("/#/bubblesu", name='dashboard')

    @task(1)
    def parents_page(self):
        self.client.get("/#/pages/parents", name='parents')

class WebsiteUser(HttpLocust):
    task_set = UserBehavior

Executing with this from cmd.
locust -f locustfile2.py --host=https://www.bubblesu.com

This is the URL to the login page.
https://bubblesu.com/#/bubblesu

This is what Locust shows.
image

cmd has no errors displayed.

Using Windows 10, Pycharm

@karol-brejna-i
Copy link
Contributor

karol-brejna-i commented Mar 29, 2018

Another way of stating the problem.

Let's assume you have the locustfile described above.

Run this Flask mini-app to determine where the request really go (it just echoes URLs it receives):

from flask import Flask
app = Flask(__name__)

@app.route('/', defaults={'path': ''})
@app.route('/<path:path>')
def catch_all(path):
    return('You want path: %s' % path)

if __name__ == '__main__':
    app.run()    

Run the app:

FLASK_APP=echo.py flask run

And run locust against this app: locust -f locustfile.py --host=http://localhost:5000/

It turns out, that Locust cuts the requested URL just after '#'. This way /#/bubblesu becomes /, etc.

On the other hand, it may be some "pythonic requests/flask issue".

If you do curl localhost:5000/#/test you will also notice, that on flask side the URL is truncated (after #).
Maybe it is some kind of a clue... ;-)

@karol-brejna-i
Copy link
Contributor

Looks the problem was noticed before: #187

On the other hand, it's worth considering if testing single page applications this way (described in the issue) is really a way to go...

@cgoldberg
Copy link
Member

I think Locust (well, actually Requests library) is handling this properly.

in the URL "http://foo/bar#baz", you have a network resource (URI) named "http://foo.bar/bar#" followed by a Fragment.

hash sign ("#") is the Fragment Identifier. The actual URI is everything up to and including the hash sign. Everything after the hash is the optional Fragment, which is not sent in HTTP requests.

From Wikipedia:

"Fragments depend on the document MIME type and are evaluated by the client (Web browser). Clients are not supposed to send URI-fragments to servers when they retrieve a document"

"When an agent (such as a Web browser) requests a web resource from a Web server, the agent sends the URI to the server, but does not send the fragment. Instead, the agent waits for the server to send the resource, and then the agent processes the resource according to the document type and fragment value."


@pawlaguna
Copy link
Author

Thanks for the resourses @cgoldberg and @karol-brejna-i.

Just for the heck of it I tried adding percent-encode and it didn't bite.

Thanks for the quick responses. I'll close the issue.

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

3 participants