Best Python code snippet using lisa_python
test_pgtune.py
Source:test_pgtune.py
1# coding: utf-82"""3Test suite for PgTune.4"""5from unittest.mock import MagicMock, patch6import pytest7import smdba.postgresqlgate8class TestPgTune:9 """10 Test PgTune class.11 """12 def test_estimate(self):13 """14 Test estimation with 10 connection and 8GB RAM15 :return:16 """17 popen = MagicMock()18 popen().read = MagicMock(return_value="11.2")19 with patch("smdba.postgresqlgate.os.popen", popen):20 pgtune = smdba.postgresqlgate.PgTune(10)21 pgtune.get_total_memory = MagicMock(return_value=0x1e0384000)22 pgtune.estimate()23 assert pgtune.config['shared_buffers'] == '1920MB'24 assert pgtune.config['effective_cache_size'] == '5632MB'25 assert pgtune.config['work_mem'] == '192MB'26 assert pgtune.config['maintenance_work_mem'] == '480MB'27 assert pgtune.config['max_wal_size'] == '384MB'28 assert pgtune.config['checkpoint_completion_target'] == '0.7'29 assert pgtune.config['wal_buffers'] == '4MB'30 assert pgtune.config['constraint_exclusion'] == 'off'31 assert pgtune.config['max_connections'] == 1032 def test_estimate_high_values(self):33 """34 Test estimation with 400 connection and 32GB RAM35 :return:36 """37 popen = MagicMock()38 popen().read = MagicMock(return_value="11.2")39 with patch("smdba.postgresqlgate.os.popen", popen):40 pgtune = smdba.postgresqlgate.PgTune(400)41 pgtune.get_total_memory = MagicMock(return_value=0x773594000)42 pgtune.estimate()43 assert pgtune.config['shared_buffers'] == '7168MB'44 assert pgtune.config['effective_cache_size'] == '22528MB'45 assert pgtune.config['work_mem'] == '18MB'46 assert pgtune.config['maintenance_work_mem'] == '1024MB'47 assert pgtune.config['max_wal_size'] == '384MB'48 assert pgtune.config['checkpoint_completion_target'] == '0.7'49 assert pgtune.config['wal_buffers'] == '4MB'50 assert pgtune.config['constraint_exclusion'] == 'off'51 assert pgtune.config['max_connections'] == 40052 def test_estimate_low_memory(self):53 """54 Estimation should abort unsupported low memory systems.55 :return:56 """57 popen = MagicMock()58 popen().read = MagicMock(return_value="11.2")59 with patch("smdba.postgresqlgate.os.popen", popen):60 pgtune = smdba.postgresqlgate.PgTune(10)61 pgtune.get_total_memory = MagicMock(return_value=0xfefffff) # One byte less to 0xff00000 memory segment62 with pytest.raises(Exception) as exc:63 pgtune.estimate()...
get_concurrent_jobs.py
Source:get_concurrent_jobs.py
...23 for value in values:24 (k, v) = value.split('=', 1)25 sizes.append((k, parse_size(v)))26 setattr(args, self.dest, sizes)27def get_total_memory():28 if sys.platform.startswith('linux'):29 if os.path.exists("/proc/meminfo"):30 with open("/proc/meminfo") as meminfo:31 memtotal_re = re.compile(r'^MemTotal:\s*(\d*)\s*kB')32 for line in meminfo:33 match = memtotal_re.match(line)34 if match:35 return float(match.group(1)) * 2**1036 elif sys.platform == 'darwin':37 try:38 return int(subprocess.check_output(['sysctl', '-n', 'hw.memsize']))39 except Exception:40 return 041 else:42 return 043def main():44 parser = argparse.ArgumentParser()45 parser.add_argument("--memory-per-job", action=ParseSize, default=[], nargs='*')46 parser.add_argument("--reserve-memory", type=parse_size, default=0)47 args = parser.parse_args()48 mem_total_bytes = max(0, get_total_memory() - args.reserve_memory)49 try:50 cpu_cap = multiprocessing.cpu_count()51 except:52 cpu_cap = 153 concurrent_jobs = {}54 for job, memory_per_job in args.memory_per_job:55 num_concurrent_jobs = int(max(1, mem_total_bytes / memory_per_job))56 concurrent_jobs[job] = min(num_concurrent_jobs, cpu_cap)57 print json.dumps(concurrent_jobs)58 return 059if __name__ == '__main__':...
UtilsMethod.py
Source:UtilsMethod.py
...10 @classmethod11 def get_process_info(cls, pid):12 aa = {}13 mm = psutil.Process(pid)14 aa["process memory"] = round((mm.memory_percent()*cls.get_total_memory())/1024/1024/1024, 2)15 aa["process cpu"] = mm.cpu_percent(interval=1)16 return aa17 @classmethod18 def get_userd_memory(cls):19 used = m.used20 return used21 @classmethod22 def get_total_memory(cls):23 total = m.total24 return total25 @classmethod26 def get_used_memory_percent(cls):27 return round(float(cls.get_userd_memory())/float(cls.get_total_memory())*100, 2)28 @classmethod29 def get_all(cls):30 m = {}31 m["cpu使ç¨ç"] = cls.get_total_cpu_percent()32 m["å
å使ç¨ç"] = cls.get_used_memory_percent()33 return m34if __name__ == '__main__':35 while True:...
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!