Skip to content

Commit

Permalink
Extend the list of valid HTTP response codes for FastHttpLocust
Browse files Browse the repository at this point in the history
  • Loading branch information
heyman committed Nov 14, 2019
1 parent 274677f commit a6364bf
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
1 change: 1 addition & 0 deletions locust/contrib/fasthttp.py
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,7 @@ def raise_for_status(self):

class LocustUserAgent(UserAgent):
response_type = FastResponse
valid_response_codes = frozenset([200, 201, 202, 203, 204, 205, 206, 207, 208, 226, 301, 302, 303, 307])

def _urlopen(self, request):
"""Override _urlopen() in order to make it use the response_type attribute"""
Expand Down
8 changes: 8 additions & 0 deletions locust/test/test_fasthttp.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,14 @@ def test_404(self):
self.assertEqual(404, r.status_code)
self.assertEqual(1, global_stats.get("/does_not_exist", "GET").num_failures)

def test_204(self):
global_stats.clear_all()
s = FastHttpSession("http://127.0.0.1:%i" % self.port)
r = s.get("/status/204")
self.assertEqual(204, r.status_code)
self.assertEqual(1, global_stats.get("/status/204", "GET").num_requests)
self.assertEqual(0, global_stats.get("/status/204", "GET").num_failures)

def test_streaming_response(self):
"""
Test a request to an endpoint that returns a streaming response
Expand Down
4 changes: 4 additions & 0 deletions locust/test/testcases.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ def manipulate():
def failed_request():
return "This response failed", 500

@app.route("/status/204")
def status_204():
return "", 204

@app.route("/redirect", methods=["GET", "POST"])
def do_redirect():
delay = request.args.get("delay")
Expand Down

0 comments on commit a6364bf

Please sign in to comment.