better exception handling, logging improvements

This commit is contained in:
Timur Torubarov 2016-07-11 18:43:38 +03:00
parent 4f2a8e9e91
commit e9ac707dff
2 changed files with 30 additions and 12 deletions

View File

@ -62,6 +62,10 @@ class JMeterPlugin(AbstractPlugin):
self.original_jmx, self.jtl_file, self._get_variables())
self.core.add_artifact_file(self.jmx)
jmeter_stderr_file = self.core.mkstemp(".log", "jmeter_stdout_stderr_")
self.core.add_artifact_file(jmeter_stderr_file)
self.jmeter_stderr = open(jmeter_stderr_file, 'w')
def prepare_test(self):
self.args = [self.jmeter_path, "-n", "-t", self.jmx, '-j',
self.jmeter_log,
@ -94,11 +98,17 @@ class JMeterPlugin(AbstractPlugin):
def start_test(self):
logger.info("Starting %s with arguments: %s", self.jmeter_path,
self.args)
self.jmeter_process = subprocess.Popen(
self.args,
executable=self.jmeter_path,
preexec_fn=os.setsid,
close_fds=True) # stderr=subprocess.PIPE, stdout=subprocess.PIPE,
try:
self.jmeter_process = subprocess.Popen(
self.args,
executable=self.jmeter_path,
preexec_fn=os.setsid,
close_fds=True,
stdout=self.jmeter_stderr,
stderr=self.jmeter_stderr
)
except OSError:
logger.error("Unable to start jmeter process. Args: %s, Executable: %s", self.args, self.jmeter_path, exc_info=True)
self.start_time = time.time()
def is_test_finished(self):
@ -118,7 +128,8 @@ class JMeterPlugin(AbstractPlugin):
except OSError, exc:
logger.debug("Seems JMeter exited itself: %s", exc)
# Utils.log_stdout_stderr(logger, self.jmeter_process.stdout, self.jmeter_process.stderr, "jmeter")
if self.jmeter_stderr:
self.jmeter_stderr.close()
self.core.add_artifact_file(self.jmeter_log)
return retcode

View File

@ -34,6 +34,8 @@ KNOWN_EXC = {
def _exc_to_net(param1):
""" translate http code to net code """
if len(param1) <= 3:
# FIXME: we're unable to use better logic here, because we should support non-http codes
# but, we should look for core.util.HTTP or some other common logic here
return 0
exc = param1.split(' ')[-1]
@ -41,21 +43,26 @@ def _exc_to_net(param1):
return KNOWN_EXC[exc]
else:
logger.warning(
"Not known Java exception, consider adding it to dictionary: %s",
param1)
return 1
"Unknown Java exception, consider adding it to dictionary: %s", param1
)
return 41
def _exc_to_http(param1):
""" translate exception str to http code"""
if len(param1) <= 3:
return int(param1)
try:
int(param1)
except:
logger.error("JMeter wrote some strange data into codes column: %s", param1)
else:
return int(param1)
exc = param1.split(' ')[-1]
if exc in KNOWN_EXC.keys():
return 0
else:
return 500
logger.warning("Unknown Java exception, %s", param1)
return 0
exc_to_net = np.vectorize(_exc_to_net)