def __run_test(self, test, benchmark_log): ''' Runs the given test, verifies that the webapp is accepting requests, optionally benchmarks the webapp, and ultimately stops all services started for this test. ''' log_prefix = "%s: " % test.name # If the test is in the excludes list, we skip it if self.config.exclude != None and test.name in self.config.exclude: message = "Test {name} has been added to the excludes list. Skipping.".format( name=test.name) self.results.write_intermediate(test.name, message) log(message, prefix=log_prefix, file=benchmark_log) return False database_container = None try: if self.__is_port_bound(test.port): time.sleep(60) if self.__is_port_bound(test.port): # We gave it our all message = "Error: Port %s is not available, cannot start %s" % ( test.port, test.name) self.results.write_intermediate(test.name, message) log(message, prefix=log_prefix, file=benchmark_log, color=Fore.RED) return False # Start database container if test.database.lower() != "none": database_container = docker_helper.start_database( self.config, test, test.database.lower()) if database_container is None: message = "ERROR: Problem building/running database container" self.results.write_intermediate(test.name, message) log(message, prefix=log_prefix, file=benchmark_log, color=Fore.RED) return False # Start webapp container = test.start() if container is None: docker_helper.stop(self.config, container, database_container, test) message = "ERROR: Problem starting {name}".format( name=test.name) self.results.write_intermediate(test.name, message) log(message, prefix=log_prefix, file=benchmark_log, color=Fore.RED) return False slept = 0 max_sleep = 60 accepting_requests = False while not accepting_requests and slept < max_sleep: accepting_requests = test.is_accepting_requests() time.sleep(1) slept += 1 if not accepting_requests: docker_helper.stop(self.config, container, database_container, test) message = "ERROR: Framework is not accepting requests from client machine" self.results.write_intermediate(test.name, message) log(message, prefix=log_prefix, file=benchmark_log, color=Fore.RED) return False # Debug mode blocks execution here until ctrl+c if self.config.mode == "debug": log("Entering debug mode. Server has started. CTRL-c to stop.", prefix=log_prefix, file=benchmark_log, color=Fore.YELLOW) while True: time.sleep(1) # Verify URLs log("Verifying framework URLs", prefix=log_prefix) passed_verify = test.verify_urls() # Benchmark this test if self.config.mode == "benchmark": log("Benchmarking %s" % test.name, file=benchmark_log, border='-') self.__benchmark(test, benchmark_log) # Stop this test docker_helper.stop(self.config, container, database_container, test) # Save results thus far into the latest results directory self.results.write_intermediate( test.name, time.strftime("%Y%m%d%H%M%S", time.localtime())) # Upload the results thus far to another server (optional) self.results.upload() if self.config.mode == "verify" and not passed_verify: log("Failed verify!", prefix=log_prefix, file=benchmark_log, color=Fore.RED) return False except (OSError, IOError, subprocess.CalledProcessError) as e: tb = traceback.format_exc() self.results.write_intermediate(test.name, "error during test: " + str(e)) log("Subprocess Error %s" % test.name, file=benchmark_log, border='-', color=Fore.RED) log(tb, prefix=log_prefix, file=benchmark_log) return False return True
def __stop(signal, frame): log("Shutting down (may take a moment)") docker_helper.stop(config) sys.exit(0)