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

Geventhttpclientmergeconflicts #838

Merged
merged 31 commits into from
Sep 27, 2019

Conversation

SpencerPinegar
Copy link

@SpencerPinegar SpencerPinegar commented Jul 9, 2018

Forked geventhttpclient #713 , created a new branch, merged master, fixed all merge conflicts (only 1 existed in docs).
Want to get this integrated to master so FastHttpClient can be easily used in master -- PR #713 has been checked and approved by 2 people and this small merge conflict was the final issue in getting this feature merged to master.

heyman and others added 29 commits December 19, 2017 15:22
…ests work without adding a dependency on having a working C compiler environment set up when installing Locust (since geventhttpclient package doesn't have wheels).
…. The text property function tries to decode the text in the same way as python-requests. This makes the API more similar to HttpSession.

Added more tests.
… requests with FastHttpSession, in order to manually control if a request should result in a success or failure
Improved documentation of arguments for FastHttpSession.request() method.
# Conflicts:
#	docs/writing-a-locustfile.rst
@codecov
Copy link

codecov bot commented Jul 9, 2018

Codecov Report

❗ No coverage uploaded for pull request base (master@8b17c28). Click here to learn what that means.
The diff coverage is 92.16%.

Impacted file tree graph

@@           Coverage Diff            @@
##             master    #838   +/-   ##
========================================
  Coverage          ?   69.2%           
========================================
  Files             ?      15           
  Lines             ?    1604           
  Branches          ?     245           
========================================
  Hits              ?    1110           
  Misses            ?     437           
  Partials          ?      57
Impacted Files Coverage Δ
locust/contrib/fasthttp.py 92.16% <92.16%> (ø)

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 8b17c28...72beb5b. Read the comment docs.

…the response was very quick (not a failure) and that 0.0 was a valid response time for a local server. Because of this i changes it to assertGreaterEqual.
@aldenpeterson-wf
Copy link
Contributor

The test failure was because of this change, btw - https://github.com/locustio/locust/pull/830/files#diff-cfaa22649621e474e8ebc0b0cac90d64R117

@aldenpeterson-wf
Copy link
Contributor

@heyman - thoughts on merging this?

if stream:
request_meta["content_size"] = int(response.headers.get("content-length") or 0)
else:
request_meta["content_size"] = len(response.content or "")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In my testing of this, I ran into an issue with a response's content not being saved properly.

When using FastHttpSession and making a request, if stream=False the response always returns with .content being bytearray(b''). If stream=True, the content is as expected. I'm not sure, but from what I can see the problem seems to stem from here where the content is read into the len() call which then causes the urllib response to release content.

I'm currently working around this by adding request_meta["content"] = response.content before this if stream check, but I'm sure there's a better way to retain content.

class FastHttpSession(object):
auth_header = None

def __init__(self, base_url):
Copy link
Contributor

@solowalker27 solowalker27 Mar 1, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
def __init__(self, base_url):
def __init__(self, base_url, **kwargs):

Allow configuration of UserAgent and HTTPClient by accepting and forwarding on **kwargs.

def __init__(self, base_url):
self.base_url = base_url
self.cookiejar = CookieJar()
self.client = LocustUserAgent(max_retries=1, cookiejar=self.cookiejar)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
self.client = LocustUserAgent(max_retries=1, cookiejar=self.cookiejar)
self.client = LocustUserAgent(max_retries=1, cookiejar=self.cookiejar, **kwargs)

Allow configuration of UserAgent and HTTPClient by accepting and forwarding on **kwargs.

@sj2208
Copy link

sj2208 commented Mar 26, 2019

@solowalker27
I have issues when i am using "catch_response" parameter. After passing catch_response=True while making a request, content field in response object is always appearing as None.

Below is sample locust file:

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

class BenchLocust(FastHttpLocust): # or HttpLocust
min_wait = 0
max_wait = 0
host = "https://docs.locust.io/en/stable"

class task_set(TaskSet):
@task
def index(self):
response = self.client.get("/", name="test" ,catch_response=True)
print response
if response.status_code == 200:
jsonBody = json.loads(response.content)
// Do some stuff here with jsonBody

Issues:

  1. When catch_response=True is passed, then issues appear in fetching the content from response.
    res = response.content

When catch_response is not passed, then we are able to easily execute the statement
"response.content" .

Can this be looked into ?

@cgoldberg
Copy link
Member

@SpencerPinegar can you take a look at the failed test and merge conflict?

FAIL: test_request_connection_error (locust.test.test_fasthttp.TestRequestStatsWithWebserver)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/travis/build/locustio/locust/locust/test/test_fasthttp.py", line 172, in test_request_connection_error
    self.assertEqual(0, global_stats.get("/", "GET").num_requests)
AssertionError: 0 != 1

The reason for this is that requests is a very well-maintained python package, that
provides a really nice API, that many python developers are familiar with. Therefore,
in many cases, we recommend that you use the default :py:class:`HttpLocust <locust.core.HttpLocust>`
which uses requests. However, if you're planning to run really large scale scale tests,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
which uses requests. However, if you're planning to run really large scale scale tests,
which uses requests. However, if you're planning to run really large scale tests,

response = locust.client.get("/", timeout=0.1)
self.assertEqual(response.status_code, 0)
self.assertEqual(1, global_stats.get("/", "GET").num_failures)
self.assertEqual(0, global_stats.get("/", "GET").num_requests)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since 0.10.0 (see #939), both successful and failed requests are counted in total number of requests.

Suggested change
self.assertEqual(0, global_stats.get("/", "GET").num_requests)
self.assertEqual(1, global_stats.get("/", "GET").num_requests)

I really don't mean to be rude, but can we get this merged any time soon? Are there any more issues that need to be solved, I'd be happy to take a look in that case.

Cheers!

@cgoldberg
Copy link
Member

Are there any more issues that need to be solved,
I'd be happy to take a look

there are merge conflicts.. have at them

@skivis skivis mentioned this pull request May 16, 2019
@sj2208
Copy link

sj2208 commented May 21, 2019

@solowalker27
I have issues when i am using "catch_response" parameter. After passing catch_response=True while making a request, content field in response object is always appearing as None.

Below is sample locust file:

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

class BenchLocust(FastHttpLocust): # or HttpLocust
min_wait = 0
max_wait = 0
host = "https://docs.locust.io/en/stable"

class task_set(TaskSet):
@task
def index(self):
response = self.client.get("/", name="test" ,catch_response=True)
print response
if response.status_code == 200:
jsonBody = json.loads(response.content)
// Do some stuff here with jsonBody

Issues:

  1. When catch_response=True is passed, then issues appear in fetching the content from response.
    res = response.content

When catch_response is not passed, then we are able to easily execute the statement
"response.content" .

Can this be looked into ?

@cgoldberg @solowalker27 -

@mbeacom mbeacom merged commit 72beb5b into locustio:master Sep 27, 2019
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.

8 participants