From 10bdc5fc7749ad5614793069bea35d3c00c029fc Mon Sep 17 00:00:00 2001 From: Dnomd343 Date: Fri, 25 Feb 2022 15:56:05 +0800 Subject: [PATCH] refactor: some edits --- Checker.py => Check.py | 0 Run.py | 2 +- Test.py | 2 +- test.py | 76 ------------------------------------------ 4 files changed, 2 insertions(+), 78 deletions(-) rename Checker.py => Check.py (100%) delete mode 100644 test.py diff --git a/Checker.py b/Check.py similarity index 100% rename from Checker.py rename to Check.py diff --git a/Run.py b/Run.py index ac0829e..108e1ab 100644 --- a/Run.py +++ b/Run.py @@ -3,7 +3,7 @@ import json import redis -import Checker +import Check as Checker redisPort = 6379 redisHost = 'localhost' diff --git a/Test.py b/Test.py index f09afdd..b82bcb3 100644 --- a/Test.py +++ b/Test.py @@ -6,7 +6,7 @@ import sys import time import subprocess -import Checker +import Check as Checker import ProxyTester as Tester testConfig = { diff --git a/test.py b/test.py deleted file mode 100644 index f09afdd..0000000 --- a/test.py +++ /dev/null @@ -1,76 +0,0 @@ -#!/usr/bin/python -# -*- coding:utf-8 -*- - -import os -import sys -import time -import subprocess - -import Checker -import ProxyTester as Tester - -testConfig = { - 'port': 12345, - 'passwd': 'dnomd343', - 'host': 'dns.343.re', - 'cert': '/etc/ssl/certs/dns.343.re/certificate.crt', - 'key': '/etc/ssl/certs/dns.343.re/private.key' -} - -def testBuild(config: dict): # load file and start process - if config['filePath'] is not None: - with open(config['filePath'], 'w') as fileObject: # save file - fileObject.write(config['fileContent']) - return subprocess.Popen( # start process - config['startCommand'], - env = config['envVar'], - stdout = subprocess.DEVNULL, - stderr = subprocess.DEVNULL - ) - -def testDestroy(config: dict, process): # remove file and kill process - if process.poll() is None: # still alive - while process.poll() is None: # wait for exit - process.terminate() # SIGTERM - time.sleep(0.2) - if config['filePath'] is not None: - os.remove(config['filePath']) # remove file - -def testObject(option: dict) -> None: # test target object - aiderProcess = None - serverProcess = testBuild(option['server']) # start server process - if option['aider'] is not None: - aiderProcess = testBuild(option['aider']) # start aider process - - checkResult = Checker.proxyTest({ # http check - 'check': ['http'], - 'info': option['proxy'] - }) - print(option['caption'], end=' -> ') - if not checkResult['success']: # client build error - print('\n----------------------------------------------------------------') - print(option) - print('----------------------------------------------------------------\n') - raise Exception('check error') - delay = checkResult['check']['http']['delay'] # get http delay - print(str(delay) + 'ms') - - testDestroy(option['server'], serverProcess) # destroy server process - if option['aider'] is not None: - testDestroy(option['aider'], aiderProcess) # destroy aider process - -if len(sys.argv) == 1: # no param - print('Unknown test type') - sys.exit(1) -testList = Tester.test(sys.argv[1], testConfig) # get test list - -if len(sys.argv) == 2: # test all - for i in range(0, len(testList)): - print(str(i), end = ': ') - testObject(testList[i]) - sys.exit(0) - -if len(sys.argv) == 3: # test target index - testObject(testList[int(sys.argv[2])]) -else: - print('Too many options')