How to use init_poolmanager method in locust

Best Python code snippet using locust

test_prototype.py

Source:test_prototype.py Github

copy

Full Screen

...10 '''Transport adapter" that allows us to use custom ssl_version.'''11 def __init__(self, ssl_version=None, **kwargs):12 self.ssl_version = ssl_version13 super().__init__(**kwargs)14 def init_poolmanager(self, connections, maxsize, block=False):15 self.poolmanager = PoolManager(16 num_pools=connections, maxsize=maxsize,17 block=block, ssl_version=self.ssl_version)18 s = Session()19 s.mount('https://', CustomHttpAdapter(ssl.PROTOCOL_SSLv23))20 url = 'https://' + hostname21 try:22 r = s.get(url)23 r.raise_for_status()24 except Exception as e:25 skip(repr(e))26@mark.parametrize('hostname', ['google.com', 'cbaccesscontrol.xdl.dk'])27def test_adapter_with_ssl_context(hostname):28 import ssl29 from urllib3.poolmanager import PoolManager30 from requests import Session31 from requests.adapters import HTTPAdapter32 assert HTTPAdapter.init_poolmanager33 class CustomHttpAdapter (HTTPAdapter):34 '''Transport adapter" that allows us to use custom ssl_context.'''35 def __init__(self, ssl_context=None, **kwargs):36 self.ssl_context = ssl_context37 super().__init__(**kwargs)38 def init_poolmanager(self, connections, maxsize, block=False):39 self.poolmanager = PoolManager(40 num_pools=connections, maxsize=maxsize,41 block=block, ssl_context=self.ssl_context)42 s = Session()43 ctx = ssl.create_default_context(ssl.Purpose.SERVER_AUTH)44 ctx.options &= ~ssl.OP_NO_SSLv345 ctx.options &= ~ssl.OP_NO_SSLv246 s.mount('https://', CustomHttpAdapter(ctx))47 url = 'https://' + hostname48 try:49 r = s.get(url)50 r.raise_for_status()51 except Exception as e:52 skip(repr(e))

Full Screen

Full Screen

adapters.py

Source:adapters.py Github

copy

Full Screen

...22class HTTPAdapter(BaseAdapter):23 """Built-In HTTP Adapter for Urllib3."""24 def __init__(self):25 super(HTTPAdapter, self).__init__()26 self.init_poolmanager()27 def init_poolmanager(self):28 self.poolmanager = PoolManager(29 num_pools=self.config.get('pool_connections'),30 maxsize=self.config.get('pool_maxsize')31 )32 def close(self):33 """Dispose of any internal state.34 Currently, this just closes the PoolManager, which closes pooled35 connections.36 """37 self.poolmanager.clear()38 def send(self, request):39 """Sends request object. Returns Response object."""...

Full Screen

Full Screen

tls_adapter.py

Source:tls_adapter.py Github

copy

Full Screen

...5from requests.adapters import HTTPAdapter6from mycroft.util.log import LOG7class TlsAdapter(HTTPAdapter):8 """"Transport adapter" that allows us to use SSLv3."""9 def init_poolmanager(self, connections, maxsize, block=False, **kwargs):10 LOG.info("TlsAdapter")11 self.poolmanager = PoolManager(12 num_pools=connections, maxsize=maxsize,13 block=block, ssl_version=ssl.PROTOCOL_TLSv1_2)14 # def init_poolmanager(self, *args, **kwargs):15 # ssl_context = ssl.create_default_context()16 # ssl_context.options &= ~ssl.PROTOCOL_TLSv1_217 # ssl_context.check_hostname = False18 # kwargs['ssl_context'] = ssl_context...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run locust automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful