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

Fix empty bytearray(b'') returned when using catch_response=True #1105

Merged
merged 4 commits into from
Oct 18, 2019
Merged

Fix empty bytearray(b'') returned when using catch_response=True #1105

merged 4 commits into from
Oct 18, 2019

Conversation

skivis
Copy link
Contributor

@skivis skivis commented Oct 3, 2019

This is a potential fix for a bug that causes the content to be "dropped" when passing catch_response=True in combination with FastHttpLocust.

To recreate, run following locust-file with locust v0.12.0:

from locust import TaskSet, task
from locust.contrib.fasthttp import FastHttpLocust


class ExamplePage(TaskSet):
    @task
    def index(self):
        with self.client.get("/", catch_response=True) as r:
            print(r.content)


class AwesomeUser(FastHttpLocust):
    task_set = ExamplePage
    host = "http://example.com"

Inside ResponseContextManager.__init__ the responses __dict__ is copied over, but for some reason the content doesn't tag along...

To be honest, I'm still not entirely sure why it gets dropped, might even be something in geventhttpclient but this fixes the issue and seems unobtrusive enough.

Please have a look, if anyone has a better solution, I'm all ears :)

@codecov
Copy link

codecov bot commented Oct 4, 2019

Codecov Report

Merging #1105 into master will increase coverage by 0.19%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1105      +/-   ##
==========================================
+ Coverage   72.29%   72.48%   +0.19%     
==========================================
  Files          17       17              
  Lines        1700     1701       +1     
  Branches      253      253              
==========================================
+ Hits         1229     1233       +4     
+ Misses        408      406       -2     
+ Partials       63       62       -1
Impacted Files Coverage Δ
locust/contrib/fasthttp.py 92.21% <100%> (+0.04%) ⬆️
locust/core.py 86.3% <0%> (+1.36%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update d5d28e6...dabc1b8. Read the comment docs.

@heyman heyman merged commit 2a0d18a into locustio:master Oct 18, 2019
@heyman
Copy link
Member

heyman commented Oct 18, 2019

Nice catch (pun intended) :)!

@tovalepo
Copy link

I'm using locust V1.3.1, where this solution is already implementd. However I'm still getting an empty bytearray (b") when calling a GET endpoint.
I tested the REST via Postman, and the response returns as required.
Any clue?

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

Successfully merging this pull request may close these issues.

3 participants