How to use end_session method in Molotov

Best Python code snippet using molotov_python

test_collectors.py

Source:test_collectors.py Github

copy

Full Screen

...10 c = collectors.LinkLoadCollector(view, req_size=req_size, content_size=cont_size)11 c.start_session(3.0, 1, 4)12 c.request_hop(1, 2)13 c.content_hop(2, 1)14 c.end_session()15 c.start_session(5.0, 1, 4)16 c.request_hop(1, 2)17 c.request_hop(2, 3)18 c.content_hop(3, 2)19 c.content_hop(2, 1)20 c.end_session()21 res = c.results()22 int_load = res['PER_LINK_INTERNAL']23 ext_load = res['PER_LINK_EXTERNAL']24 assert 2 * req_size / 2 == int_load[(1, 2)]25 assert 2 * cont_size / 2 == int_load[(2, 1)]26 assert req_size / 2 == ext_load[(2, 3)]27 assert cont_size / 2 == ext_load[(3, 2)]28 mean_int = res['MEAN_INTERNAL']29 mean_ext = res['MEAN_EXTERNAL']30 assert (req_size + cont_size) / 2 == mean_int31 assert (req_size + cont_size) / 4 == mean_ext32 def test_internal_links_only(self):33 req_size = 50034 cont_size = 70035 link_type = {(1, 2): 'internal', (2, 3): 'internal',36 (2, 1): 'internal', (3, 2): 'internal'}37 view = type('MockNetworkView', (), {'link_type': lambda s, u, v: link_type[(u, v)]})()38 c = collectors.LinkLoadCollector(view, req_size=req_size, content_size=cont_size)39 c.start_session(3.0, 1, 4)40 c.request_hop(1, 2)41 c.content_hop(2, 1)42 c.end_session()43 c.start_session(5.0, 1, 4)44 c.request_hop(1, 2)45 c.request_hop(2, 3)46 c.content_hop(3, 2)47 c.content_hop(2, 1)48 c.end_session()49 res = c.results()50 mean_ext = res['MEAN_EXTERNAL']51 ext_load = res['PER_LINK_EXTERNAL']52 assert 0 == mean_ext53 assert 0 == len(ext_load)54 def test_external_links_only(self):55 req_size = 50056 cont_size = 70057 link_type = {(1, 2): 'external', (2, 3): 'external',58 (2, 1): 'external', (3, 2): 'external'}59 view = type('MockNetworkView', (), {'link_type': lambda s, u, v: link_type[(u, v)]})()60 c = collectors.LinkLoadCollector(view, req_size=req_size, content_size=cont_size)61 c.start_session(3.0, 1, 'CONTENT')62 c.request_hop(1, 2)63 c.content_hop(2, 1)64 c.end_session()65 c.start_session(5.0, 1, 'CONTENT')66 c.request_hop(1, 2)67 c.request_hop(2, 3)68 c.content_hop(3, 2)69 c.content_hop(2, 1)70 c.end_session()71 res = c.results()72 mean_ext = res['MEAN_INTERNAL']73 ext_load = res['PER_LINK_INTERNAL']74 assert 0 == mean_ext75 assert 0 == len(ext_load)76class TestLatencyCollector(object):77 def test_base(self):78 link_delay = {(1, 2): 2, (2, 3): 10,79 (2, 1): 4, (3, 2): 20}80 view = type('MockNetworkView', (), {'link_delay': lambda s, u, v: link_delay[(u, v)]})()81 c = collectors.LatencyCollector(view)82 c.start_session(3.0, 1, 'CONTENT')83 c.request_hop(1, 2)84 c.content_hop(2, 1)85 c.end_session()86 c.start_session(5.0, 1, 'CONTENT')87 c.request_hop(1, 2)88 c.request_hop(2, 3)89 c.content_hop(3, 2)90 c.content_hop(2, 1)91 c.end_session()92 res = c.results()93 assert (10 + 20 + 2 * (2 + 4)) / 2 == res['MEAN']94 def test_main_path(self):95 link_delay = {(1, 2): 2, (2, 3): 10,96 (2, 1): 4, (3, 2): 20}97 view = type('MockNetworkView', (), {'link_delay': lambda s, u, v: link_delay[(u, v)]})()98 c = collectors.LatencyCollector(view)99 c.start_session(3.0, 1, 'CONTENT')100 c.request_hop(1, 2)101 c.content_hop(2, 1)102 c.end_session()103 c.start_session(5.0, 1, 'CONTENT')104 c.request_hop(1, 2)105 c.request_hop(2, 3)106 c.request_hop(2, 1, main_path=False)107 c.content_hop(3, 2)108 c.content_hop(2, 1)109 c.content_hop(2, 3, main_path=False)110 c.end_session()111 res = c.results()112 assert (10 + 20 + 2 * (2 + 4)) / 2 == res['MEAN']113class TestCacheHitRatioCollector(object):114 def test_base(self):115 view = type('MockNetworkView', (), {})()116 c = collectors.CacheHitRatioCollector(view)117 c.start_session(3.0, 1, 'CONTENT')118 c.cache_hit(1)119 c.end_session()120 c.start_session(4.0, 1, 'CONTENT')121 c.server_hit(2)122 c.end_session()123 res = c.results()124 assert 0.5 == res['MEAN']125 def test_per_node(self):126 view = type('MockNetworkView', (), {})()127 c = collectors.CacheHitRatioCollector(view, per_node=True)128 c.start_session(3.0, 1, 'CONTENT')129 c.cache_hit(1)130 c.end_session()131 c.start_session(4.0, 1, 'CONTENT')132 c.cache_hit(1)133 c.end_session()134 c.start_session(5.0, 1, 'CONTENT')135 c.cache_hit(2)136 c.end_session()137 c.start_session(6.0, 1, 'CONTENT')138 c.cache_hit(3)139 c.end_session()140 c.start_session(7.0, 1, 'CONTENT')141 c.server_hit(4)142 c.end_session()143 res = c.results()144 assert {1: 0.4, 2: 0.2, 3: 0.2} == res['PER_NODE_CACHE_HIT_RATIO']145 assert {4: 0.2} == res['PER_NODE_SERVER_HIT_RATIO']146 def test_per_content(self):147 view = type('MockNetworkView', (), {})()148 c = collectors.CacheHitRatioCollector(view, content_hits=True)149 c.start_session(3.0, 'RECV', 1)150 c.cache_hit(1)151 c.end_session()152 c.start_session(4.0, 'RECV', 1)153 c.server_hit(2)154 c.end_session()155 c.start_session(5.0, 'RECV', 2)156 c.cache_hit(3)157 c.end_session()158 c.start_session(6.0, 'RECV', 2)159 c.server_hit(4)160 c.end_session()161 c.start_session(7.0, 'RECV', 2)162 c.server_hit(5)163 c.end_session()164 c.start_session(8.0, 'RECV', 2)165 c.server_hit(5)166 c.end_session()167 res = c.results()...

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 Molotov 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