2828 timeout = 3600 ,
2929)
3030
31- FIELD_NAMES = ["Iteration" , "New request sessions" , "Sessions created time" , "Sessions failed to create" , "New pods scaled up" , "Total running sessions" , "Total running pods" , "Max sessions per pod" , "Gaps" , "Sessions closed" ]
31+ FIELD_NAMES = [
32+ "Iteration" ,
33+ "New request sessions" ,
34+ "Sessions created time" ,
35+ "Sessions failed to create" ,
36+ "New pods scaled up" ,
37+ "Total running sessions" ,
38+ "Total running pods" ,
39+ "Max sessions per pod" ,
40+ "Gaps" ,
41+ "Sessions closed" ,
42+ ]
43+
3244
3345def get_pod_count ():
3446 result = subprocess .run (["kubectl" , "get" , "pods" , "-A" , "--no-headers" ], capture_output = True , text = True )
3547 return len ([line for line in result .stdout .splitlines () if "selenium-node-" in line and "Running" in line ])
3648
49+
3750def create_session (browser_name ):
3851 options = BROWSER [browser_name ]
3952 options .set_capability ("platformName" , "Linux" )
40- return webdriver .Remote (command_executor = CLIENT_CONFIG .remote_server_addr , options = options , client_config = CLIENT_CONFIG )
53+ return webdriver .Remote (
54+ command_executor = CLIENT_CONFIG .remote_server_addr , options = options , client_config = CLIENT_CONFIG
55+ )
56+
4157
4258def wait_for_count_matches (sessions , timeout = 10 , interval = 5 ):
4359 elapsed = 0
@@ -49,20 +65,26 @@ def wait_for_count_matches(sessions, timeout=10, interval=5):
4965 time .sleep (interval )
5066 elapsed += interval
5167 if pod_count != len (sessions ):
52- print (f"WARN: Mismatch between pod count and session count after { timeout } seconds. Gaps: { pod_count - len (sessions )} " )
68+ print (
69+ f"WARN: Mismatch between pod count and session count after { timeout } seconds. Gaps: { pod_count - len (sessions )} "
70+ )
5371 else :
5472 print (f"PASS: Pod count matches session count after { elapsed } seconds." )
5573
74+
5675def close_all_sessions (sessions ):
5776 for session in sessions :
5877 session .quit ()
5978 sessions .clear ()
6079 return sessions
6180
81+
6282def create_sessions_in_parallel (new_request_sessions ):
6383 failed_jobs = 0
6484 with concurrent .futures .ThreadPoolExecutor () as executor :
65- futures = [executor .submit (create_session , random .choice (list (BROWSER .keys ()))) for _ in range (new_request_sessions )]
85+ futures = [
86+ executor .submit (create_session , random .choice (list (BROWSER .keys ()))) for _ in range (new_request_sessions )
87+ ]
6688 sessions = []
6789 for future in concurrent .futures .as_completed (futures ):
6890 try :
@@ -73,6 +95,7 @@ def create_sessions_in_parallel(new_request_sessions):
7395 print (f"Total failed jobs: { failed_jobs } " )
7496 return sessions
7597
98+
7699def randomly_quit_sessions (sessions , sublist_size ):
77100 if sessions :
78101 sessions_to_quit = random .sample (sessions , min (sublist_size , len (sessions )))
@@ -83,15 +106,18 @@ def randomly_quit_sessions(sessions, sublist_size):
83106 return len (sessions_to_quit )
84107 return 0
85108
109+
86110def get_result_file_name ():
87111 return f"tests/autoscaling_results"
88112
113+
89114def export_results_to_csv (output_file , field_names , results ):
90115 with open (output_file , mode = "w" ) as csvfile :
91116 writer = csv .DictWriter (csvfile , fieldnames = field_names )
92117 writer .writeheader ()
93118 writer .writerows (results )
94119
120+
95121def export_results_csv_to_md (csv_file , md_file ):
96122 with open (csv_file ) as f :
97123 table = Table .parse_csv (f )
0 commit comments