Can't reach Locust WebInterface "ERR_CONNECTION_REFUSED" - python

I wanted to test Locust for my Project on Windows 10.
The Script seems to run properly (no Errors in CMD), but i can't connect to the web interface http://127.0.0.1:8089 (ERR_CONNECTION_REFUSED).
I am guessing, that this has to do with Browser/Windows config, but i can't find the problem. I have no Proxy set up in Lan settings, i get my ip from DNS, and i have no changes in my hosts file.
locustfile.py
from locust import HttpLocust, TaskSet, task
class UserBehavior(TaskSet):
def on_start(self):
""" on_start is called when a Locust start before any task is scheduled """
self.login()
def on_stop(self):
""" on_stop is called when the TaskSet is stopping """
self.logout()
def login(self):
self.client.post("/login", {"username":"tester", "password":"abcd1234"})
def logout(self):
self.client.post("/logout", {"username":"ellen_key", "password":"education"})
#task(2)
def index(self):
self.client.get("/")
#task(1)
def profile(self):
self.client.get("/profile")
class WebsiteUser(HttpLocust):
task_set = UserBehavior
min_wait = 5000
max_wait = 9000
host="http://google.com"
CMD
D:\workspace\WebTesting>locust
CMD result :
[2019-05-13 09:49:45,069] LB6-001-DTMH/INFO/locust.main: Starting web monitor at *:8089
[2019-05-13 09:49:45,070] LB6-001-DTMH/INFO/locust.main: Starting Locust 0.11.0
When i interrupt the script in the command line i get the "KeyboardInterrupt" message and some statistics without data
python -m http.server 8089 seems to work

Try going to http://localhost:8089/
I am not quite sure why, but I can't reach the Locust webinterface through http://127.0.0.1 either (other webservers run fine locally with this address), but going to localhost does work for me.

I faced a similar issue. Instead of using IP address, try using localhost.
http://localhost:portnumber -> http://localhost:8089. This solved the issue for me.

Related

How to use multiple hosts in multiple classes in Locust

I need to test some APIs having different addresses, I have created locustfile for Locust Tool as mentioned below, but only api1 is working, endpoints in api2 are not being called
from locust import HttpUser, task, between
class api1(HttpUser):
host = 'http://localhost:6001'
wait_time = between(2, 4)
#task()
def api1_ep1(self):
self.client.post('/ep1')
#task()
def api1_ep2(self):
self.client.post('/ep2')
class api2(HttpUser):
host = 'http://localhost:6002'
wait_time = between(2, 4)
#task()
def api2_ep1(self):
self.client.post('/ep1')
#task()
def api2_ep2(self):
self.client.post('/ep2')
I tried suggestions from issue: 150 and put full path as self.client.post('http://localhost:6001/ep1') but the same problem persists
I was spawning single user, spawning more users fixed the probem

Using mitmproxy inside a Python script to connect to upstream proxy (with user & password)

I am trying to use mitmproxy behind a company proxy that requires a user/password login.
The setup is:
Local PC's browser -> mitmproxy (on local PC) -> company proxy -> internet.
Based on this SO thread, this is how you use mitmproxy within a Python program. This example works fine when there's no proxy.
from mitmproxy.options import Options
from mitmproxy.proxy.config import ProxyConfig
from mitmproxy.proxy.server import ProxyServer
from mitmproxy.tools.dump import DumpMaster
class Addon(object):
def __init__(self):
pass
def request(self, flow):
# examine request here
pass
def response(self, flow):
# examine response here
pass
if __name__ == "__main__":
options = Options(listen_host='0.0.0.0', listen_port=8080, http2=True)
m = DumpMaster(options, with_termlog=False, with_dumper=False)
config = ProxyConfig(options)
m.server = ProxyServer(config)
m.addons.add(Addon())
try:
print('starting mitmproxy')
m.run()
except KeyboardInterrupt:
m.shutdown()
Assuming the company proxy is at IP "1.2.3.4" port 3128 and requires a
login USER and PASSWORD, how can I change this script to have mitproxy
use that proxy instead of going to the internet directly?
Addition info: I am not using mitmdump with the script-parameter to run this script.
The goal is to run this from Python 3.8 with a pip-installed mitmproxy

Get the correct port number from LiveServerTestCase in Django 2.0

When trying to test the admin login using the following code, I found the self.live_server_url returns something like http://localhost:39346, where the port number is different on each running.
from django.test import LiveServerTestCase
from selenium import webdriver
class AdminLoginTests(LiveServerTestCase):
def setUp(self):
self.selenium = webdriver.Firefox()
super(AdminLoginTests, self).setUp()
def tearDown(self):
self.selenium.quit()
super(AdminLoginTests, self).tearDown()
def test_admin_login(self):
# ...
print('url: %s' %self.live_server_url)
How do I get the correct port number 8000 of the running server? Suppose I run the server through python manage.py runserver 0.0.0.0:8000. Thanks!
LiveServerTestCase spawns a new instance with that port on purpose. That way you can test a production environment without having to shutdown the production server (which by default runs on 8000).
However if you want to change the port that the debug is running on you can initialize to a different port number.
class TempTest(LiveServerTestCase):
def __init__(self):
super(TempTest, self).__init__()
self.port = 8910
def setUp(self)
# ....
This is what works for me under Django version 1.11.26
class TempTest(LiveServerTestCase):
port = 8888
host = "0.0.0.0" # If you want your test server to be public

Python Locust - herror: [Errno 1] Unknown host

I'm trying to test my application using python Locust, but I can't get a basic version to work. My locustfile.py file:
from locust import HttpLocust, TaskSet, task
class UserBehavior(TaskSet):
#task(1)
def test_get(self):
self.client.get("/")
class WebsiteUser(HttpLocust):
task_set = UserBehavior
min_wait=5000
max_wait=9000
I ran
locust --host=http://example.com
And got this error:
[2015-08-04 23:10:11,734] my-macbook-pro.local/ERROR/stderr: herror: [Errno 1] Unknown host
Wondering if it's just me putting in the wrong host, I tried facebook, google, and other hosts with no success either.
What am I doing wrong here?
You need to give -f locustfile.py parameters for running a file: locust -f locustfile.py --host=http://www.example.com
Alternatively, you can also declerate the host in locust class like in the below and run it locust -f locustfile.py:
from locust import HttpLocust, TaskSet, task
class UserBehavior(TaskSet):
#task(1)
def test_get(self):
self.client.get("/")
class WebsiteUser(HttpLocust):
task_set = UserBehavior
host = "http://www.example.com"
min_wait=5000
max_wait=9000

Fabric - Run a command locally before and after all tasks complete

I'm attempting to announce deployment start and end in my fabric script. Feels like this should be easy, but for the life of me I can't figure out how to do it.
env.hosts = ['www1', 'www2', 'www3', 'www4']
def announce_start():
# code to connect to irc server and announce deployment begins
pass
def announce_finish():
# code to connect to irc server and announce deployment finishes
pass
def deploy():
# actual deployment code here
pass
Here's what I've tried:
If I make my deploy task contain 'announce_start' and 'announce_finish'. It will attempt to run all those tasks on each server.
def deploy():
announce_start()
# actual deployment code here
announce_finish()
If I decorate announce_start() and announce_end() with #hosts('localhost'), it runs it on localhost, but still four times. One for each host.
As I was typing this, I finally got it to work by using the decorator #hosts('localhost') on announce_start/end and the fab command:
fab announce_start deploy announce_end
But this seems a bit hacky. I'd like it all wrapped in a single deploy command. Is there a way to do this?
You can use fabric.api.execute, e.g.
def announce_start():
# code to connect to irc server and announce deployment begins
pass
def announce_finish():
# code to connect to irc server and announce deployment finishes
pass
#hosts(...)
def deploy_machine1():
pass
#hosts(...)
def deploy_machine2():
pass
def deploy():
announce_start()
execute(deploy_machine1)
execute(deploy_machine2)
announce_finish()
and then just invoke fab deploy

Categories

Resources