Commit ffeade8e authored by Grant Young's avatar Grant Young

Merge branch 'gy-compare-test-fixes' into 'master'

Fix comparison tests against older versions

Closes #215

See merge request !138
parents d67bafe3 0873e217
......@@ -43,14 +43,14 @@ def generate_comparision_table(results)
results_comparision_data[test_result["name"]] ||= Hash[results_comparision_versions.collect { |version| [version, "-"] }]
last_test_result = results[result_num - 1]['test_results'].find { |res| res['name'] == test_result["name"] } unless result_num.zero?
if last_test_result
if last_test_result&.dig('ttfb_p90')
last_test_difference = test_result['ttfb_p90'].to_f - last_test_result['ttfb_p90'].to_f
last_test_diff_perc = (last_test_difference * 100 / last_test_result['ttfb_p90'].to_f).round(2)
last_test_difference_str = last_test_difference.positive? ? "_+#{last_test_diff_perc}%_" : "**#{last_test_diff_perc}%**"
results_comparision_data[test_result["name"]][result["version"].tr('.', '-')] = "#{test_result['ttfb_p90']}ms (#{last_test_difference_str})"
else
results_comparision_data[test_result["name"]][result["version"].tr('.', '-')] = "#{test_result['ttfb_p90']}ms (-)"
results_comparision_data[test_result["name"]][result["version"].tr('.', '-')] = test_result['ttfb_p90'] ? "#{test_result['ttfb_p90']}ms (-)" : '-'
end
end
end
......
......@@ -56,14 +56,13 @@ options_file = Dir.glob([opts[:options], "#{k6_dir}/#{opts[:options]}", "#{k6_di
raise "Options config file '#{opts[:options]}' not found as given or in default folder. Exiting..." unless File.file?(options_file.to_s)
env_vars = RunK6.setup_env_vars(env_file: env_file, options_file: options_file)
env_version = RunK6.get_env_version(env_vars: env_vars)
start_time = Time.now
tests = RunK6.get_tests(k6_dir: k6_dir, test_paths: opts[:tests], test_excludes: opts[:excludes], quarantined: opts[:quarantined], scenarios: opts[:scenarios], unsafe: opts[:unsafe], env_version: env_version['version'], env_vars: env_vars)
tests = RunK6.get_tests(k6_dir: k6_dir, test_paths: opts[:tests], test_excludes: opts[:excludes], quarantined: opts[:quarantined], scenarios: opts[:scenarios], unsafe: opts[:unsafe], env_version: env_vars['ENVIRONMENT_VERSION'], env_vars: env_vars)
RunK6.prepare_tests(tests: tests, env_vars: env_vars)
results_home = ENV['GPT_DOCKER_RESULTS_DIR'] || "#{k6_dir}/results"
results_file_prefix = "#{env_vars['ENVIRONMENT_NAME']}_#{env_version['version'].match?(/\d+\.\d+\.\d+.*/) ? "v#{env_version['version'].tr('.', '-')}_" : ''}#{start_time.strftime('%Y-%m-%d_%H%M%S')}"
results_file_prefix = "#{env_vars['ENVIRONMENT_NAME']}_#{env_vars['ENVIRONMENT_VERSION'].match?(/\d+\.\d+\.\d+.*/) ? "v#{env_vars['ENVIRONMENT_VERSION'].tr('.', '-')}_" : ''}#{start_time.strftime('%Y-%m-%d_%H%M%S')}"
results_dir = File.join(results_home, results_file_prefix)
puts "\nSaving all test results to #{results_dir}"
FileUtils.mkdir_p(results_dir)
......@@ -121,8 +120,8 @@ end
# JSON
results_json = {
"name" => env_vars['ENVIRONMENT_NAME'],
"version" => env_version['version'],
"revision" => env_version['revision'],
"version" => env_vars['ENVIRONMENT_VERSION'],
"revision" => env_vars['ENVIRONMENT_REVISION'],
"gpt_version" => gpt_version,
"option" => File.basename(options_file, '.json'),
"date" => start_time.strftime('%F'),
......
......@@ -113,9 +113,18 @@ export function prepareGitPushData(projects) {
export function updateProjectPipelinesSetting(project, state) {
let params = { headers: { "Accept": "application/json", "PRIVATE-TOKEN": `${__ENV.ACCESS_TOKEN}` } };
let formdata = { builds_access_level: state };
let formdata;
let ver_regex = /([0-9]+)/g;
let version = __ENV.ENVIRONMENT_VERSION.match(ver_regex);
if (parseInt(version[0]) > 12 || parseInt(version[0]) == 12 && parseInt(version[1]) >= 1) {
formdata = { builds_access_level: state ? "enabled" : "disabled" }
} else {
formdata = { jobs_enabled: state }
}
let res = http.put(`${__ENV.ENVIRONMENT_URL}/api/v4/projects/${project['group']}%2F${project['name']}`, formdata, params);
/20(0|1)/.test(res.status) ? console.log(`Project Pipelines setting was ${state}`) : (logError(res), fail(`Error with Project Pipelines setting update.`));
/20(0|1)/.test(res.status) ? console.log(`Project Pipelines setting changed to ${state}`) : (logError(res), fail(`Error occured when attempting to change Project Pipelines setting.`));
}
export function waitForGitSidekiqQueue() {
......
......@@ -49,7 +49,7 @@ export function setup() {
projects.forEach(project => {
checkCommitExists(project, project['git_push_data']['branch_current_head_sha']);
checkCommitExists(project, project['git_push_data']['branch_new_head_sha']);
updateProjectPipelinesSetting(project, "disabled");
updateProjectPipelinesSetting(project, false);
});
}
......@@ -88,6 +88,6 @@ export function teardown() {
};
http.post(`${authEnvUrl}/${project['group']}/${project['name']}.git/git-receive-pack`, project.data.branch_set_old_head, params);
// Reenable Pipelines in the Project
updateProjectPipelinesSetting(project, "enabled");
updateProjectPipelinesSetting(project, true);
});
}
......@@ -44,6 +44,12 @@ module RunK6
File.join(File.dirname(k6_archive.path), 'k6')
end
def get_env_version(env_url:)
headers = { 'PRIVATE-TOKEN': ENV['ACCESS_TOKEN'] }
res = GPTCommon.make_http_request(method: 'get', url: "#{env_url}/api/v4/version", headers: headers, fail_on_error: false)
res.status.success? ? JSON.parse(res.body.to_s) : { "version" => "-", "revision" => "-" }
end
def setup_env_vars(env_file:, options_file:)
env_vars = {}
env_file_vars = JSON.parse(File.read(env_file))
......@@ -54,6 +60,10 @@ module RunK6
env_vars['ENVIRONMENT_REPO_STORAGE'] = ENV['ENVIRONMENT_REPO_STORAGE'].dup || env_file_vars['environment'].dig('config', 'repo_storage')
env_vars['ENVIRONMENT_PROJECTS'] = env_file_vars['projects'].to_json
env_version = get_env_version(env_url: env_vars['ENVIRONMENT_URL'])
env_vars['ENVIRONMENT_VERSION'] = env_version['version']
env_vars['ENVIRONMENT_REVISION'] = env_version['revision']
options_file_vars = JSON.parse(File.read(options_file))
env_vars['OPTION_RPS'] = options_file_vars['rps'].to_s
env_vars['OPTION_RPS_COUNT'] ||= begin
......@@ -73,12 +83,6 @@ module RunK6
env_vars
end
def get_env_version(env_vars:)
headers = { 'PRIVATE-TOKEN': ENV['ACCESS_TOKEN'] }
res = GPTCommon.make_http_request(method: 'get', url: "#{env_vars['ENVIRONMENT_URL']}/api/v4/version", headers: headers, fail_on_error: false)
res.status.success? ? JSON.parse(res.body.to_s) : { "version" => "-", "revision" => "-" }
end
def prepare_tests(tests:, env_vars:)
# Prepare specific test data
GitTest.prepare_git_push_data(env_vars: env_vars) unless tests.grep(/git_push/).empty? || env_vars.empty?
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment