From 80ce58208e2e8fa3bbc59123f77a8d2dbfea9f39 Mon Sep 17 00:00:00 2001 From: Ludek Novy <13610612+ludeknovy@users.noreply.github.com> Date: Fri, 1 Mar 2024 15:55:49 +0100 Subject: [PATCH] Minimum test duration setting for scenario (#301) --- migrations/1709293652942_min-test-duration.js | 9 +++++++++ src/server/controllers/item/create-item-controller.ts | 1 + src/server/controllers/item/get-item-controller.ts | 4 ++-- .../controllers/scenario/get-scenario-controller.ts | 1 + .../scenario/update-scenario-controller.spec.ts | 3 ++- .../controllers/scenario/update-scenario-controller.ts | 3 ++- src/server/queries/items.ts | 3 ++- src/server/queries/projects.ts | 2 +- src/server/queries/scenario.ts | 6 +++--- src/server/schema-validator/scenario-schema.ts | 2 ++ src/tests/integration/scenario.spec.ts | 2 ++ 11 files changed, 27 insertions(+), 9 deletions(-) create mode 100644 migrations/1709293652942_min-test-duration.js diff --git a/migrations/1709293652942_min-test-duration.js b/migrations/1709293652942_min-test-duration.js new file mode 100644 index 00000000..08b76d68 --- /dev/null +++ b/migrations/1709293652942_min-test-duration.js @@ -0,0 +1,9 @@ +exports.up = (pgm) => { + pgm.addColumn({ schema: "jtl", name: "scenario" }, { + min_test_duration: { + type: "smallint", + "default": 5, + notNull: true, + }, + }) +} diff --git a/src/server/controllers/item/create-item-controller.ts b/src/server/controllers/item/create-item-controller.ts index 7cae44dd..1aea7512 100644 --- a/src/server/controllers/item/create-item-controller.ts +++ b/src/server/controllers/item/create-item-controller.ts @@ -237,3 +237,4 @@ const handleError = async (itemId: string, kpiFilename: string, processingError: logger.error(`File ${kpiFilename} does not exist anymore`) } } + diff --git a/src/server/controllers/item/get-item-controller.ts b/src/server/controllers/item/get-item-controller.ts index a1769420..712dadfd 100644 --- a/src/server/controllers/item/get-item-controller.ts +++ b/src/server/controllers/item/get-item-controller.ts @@ -20,7 +20,7 @@ export const getItemController = async (req: IGetUserAuthInfoRequest, res: Respo // eslint-disable-next-line @typescript-eslint/naming-convention base_id, resourcesLink, status, hostname, reportStatus, thresholds, - analysisEnabled, zeroErrorToleranceEnabled, topMetricsSettings, name, apdexSettings, + analysisEnabled, zeroErrorToleranceEnabled, topMetricsSettings, name, apdexSettings, minTestDuration, } = await db.one(findItem(itemId, projectName, scenarioName)) const { stats: statistics, overview, sutOverview, errors } = await db.one(findItemStats(itemId)) @@ -43,7 +43,7 @@ export const getItemController = async (req: IGetUserAuthInfoRequest, res: Respo plot: Object.assign({}, plot, { scatterPlotData }), extraPlotData, note, environment, hostname, reportStatus, thresholds, analysisEnabled, baseId: base_id, isBase: base_id === itemId, zeroErrorToleranceEnabled, topMetricsSettings, - histogramPlotData, + histogramPlotData, minTestDuration, name, resourcesLink, monitoring: { cpu: { diff --git a/src/server/controllers/scenario/get-scenario-controller.ts b/src/server/controllers/scenario/get-scenario-controller.ts index bf0c7226..223802fb 100644 --- a/src/server/controllers/scenario/get-scenario-controller.ts +++ b/src/server/controllers/scenario/get-scenario-controller.ts @@ -28,6 +28,7 @@ export const getScenarioController = async (req: IGetUserAuthInfoRequest, res: R name: scenario.name, analysisEnabled: scenario.analysis_enabled, zeroErrorToleranceEnabled: scenario.zero_error_tolerance_enabled, + minTestDuration: scenario.min_test_duration, deleteSamples: scenario.delete_samples, keepTestRunsPeriod: scenario.keep_test_runs_period, generateShareToken: scenario.generate_share_token, diff --git a/src/server/controllers/scenario/update-scenario-controller.spec.ts b/src/server/controllers/scenario/update-scenario-controller.spec.ts index 1b2508ee..d64b95f7 100644 --- a/src/server/controllers/scenario/update-scenario-controller.spec.ts +++ b/src/server/controllers/scenario/update-scenario-controller.spec.ts @@ -22,6 +22,7 @@ describe("updateScenariosController", () => { }, analysisEnabled: true, scenarioName: "test-scenario", + minTestDuration: 3, deleteSamples: false, zeroErrorToleranceEnabled: false, keepTestRunsPeriod: 7, @@ -53,7 +54,7 @@ describe("updateScenariosController", () => { expect(querySpy).toBeCalledWith("project", "test-scenario", "test-scenario", body.analysisEnabled, body.thresholds, body.deleteSamples, body.zeroErrorToleranceEnabled, body.keepTestRunsPeriod, body.generateShareToken, JSON.stringify(body.labelFilterSettings), - JSON.stringify(body.labelTrendChartSettings), body.extraAggregations, body.apdexSettings) + JSON.stringify(body.labelTrendChartSettings), body.extraAggregations, body.apdexSettings, body.minTestDuration) expect(response.send).toHaveBeenCalledTimes(1) }) }) diff --git a/src/server/controllers/scenario/update-scenario-controller.ts b/src/server/controllers/scenario/update-scenario-controller.ts index a9da7791..d11ad0df 100644 --- a/src/server/controllers/scenario/update-scenario-controller.ts +++ b/src/server/controllers/scenario/update-scenario-controller.ts @@ -21,12 +21,13 @@ export const updateScenarioController = async (req: IGetUserAuthInfoRequest, res extraAggregations, userSettings, apdexSettings, + minTestDuration, } = req.body await db.none(updateScenario(projectName, scenarioName, name, analysisEnabled, thresholds, deleteSamples, zeroErrorToleranceEnabled, keepTestRunsPeriod, generateShareToken, JSON.stringify(labelFilterSettings), JSON.stringify(labelTrendChartSettings), - extraAggregations, apdexSettings)) + extraAggregations, apdexSettings, minTestDuration)) await db.none(updateUserScenarioSettings(projectName, scenarioName, userId, JSON.stringify(userSettings.requestStats))) diff --git a/src/server/queries/items.ts b/src/server/queries/items.ts index 224f6a58..b28cf983 100644 --- a/src/server/queries/items.ts +++ b/src/server/queries/items.ts @@ -30,9 +30,10 @@ export const findItem = (itemId, projectName, scenarioName) => { return { // eslint-disable-next-line max-len text: `SELECT charts.plot_data, charts.extra_plot_data, charts.histogram_plot_data, charts.scatter_plot_data, note, environment, status, hostname, s.analysis_enabled as "analysisEnabled", - s.zero_error_tolerance_enabled as "zeroErrorToleranceEnabled", threshold_result as "thresholds", + s.zero_error_tolerance_enabled as "zeroErrorToleranceEnabled", threshold_result as "thresholds", report_status as "reportStatus", p.item_top_statistics_settings as "topMetricsSettings", items.name, items.apdex_settings as "apdexSettings", items.resources_link as "resourcesLink", + s.min_test_duration as "minTestDuration", (SELECT items.id FROM jtl.items as items LEFT JOIN jtl.charts as charts ON charts.item_id = items.id LEFT JOIN jtl.scenario as s ON s.id = items.scenario_id diff --git a/src/server/queries/projects.ts b/src/server/queries/projects.ts index 41d642b7..9b64dfd9 100644 --- a/src/server/queries/projects.ts +++ b/src/server/queries/projects.ts @@ -38,7 +38,7 @@ export const findProjects = (userId) => { export const latestItems = (userId) => { return { - text: `SELECT i.id, s.name, environment, project_name as "projectName", stat.overview, status, s.zero_error_tolerance_enabled as "zeroErrorToleranceEnabled", i.threshold_result as "thresholdPassed" FROM jtl.items as i + text: `SELECT i.id, s.name, environment, project_name as "projectName", stat.overview, status, s.zero_error_tolerance_enabled as "zeroErrorToleranceEnabled", s.min_test_duration as "minTestDuration", i.threshold_result as "thresholdPassed" FROM jtl.items as i LEFT JOIN jtl.scenario as s ON s.id = i.scenario_id LEFT JOIN jtl.projects as p ON p.id = s.project_id LEFT JOIN jtl.item_stat as stat ON stat.item_id = i.id diff --git a/src/server/queries/scenario.ts b/src/server/queries/scenario.ts index 1c66d8e0..40f4d34c 100644 --- a/src/server/queries/scenario.ts +++ b/src/server/queries/scenario.ts @@ -42,14 +42,14 @@ export const scenarioGenerateToken = (projectName, scenarioName) => { } -export const updateScenario = (projectName, scenarioName, name, analysisEnabled, thresholds, deleteSamples, zeroErrorToleranceEnabled, keepTestRunPeriod, generateShareToken, labelFilterSettings, labelTrendChartSettings, extraAggregations, apdexSettings) => { +export const updateScenario = (projectName, scenarioName, name, analysisEnabled, thresholds, deleteSamples, zeroErrorToleranceEnabled, keepTestRunPeriod, generateShareToken, labelFilterSettings, labelTrendChartSettings, extraAggregations, apdexSettings, minTestDuration) => { return { text: ` UPDATE jtl.scenario as s - SET name = $3, analysis_enabled=$4, threshold_enabled = $5, threshold_percentile = $6, threshold_throughput = $7, threshold_error_rate = $8, delete_samples = $9, zero_error_tolerance_enabled = $10, keep_test_runs_period = $11, generate_share_token = $12, label_filter_settings = $13, label_trend_chart_settings = $14, extra_aggregations = $15, apdex_settings = $16 + SET name = $3, analysis_enabled=$4, threshold_enabled = $5, threshold_percentile = $6, threshold_throughput = $7, threshold_error_rate = $8, delete_samples = $9, zero_error_tolerance_enabled = $10, keep_test_runs_period = $11, generate_share_token = $12, label_filter_settings = $13, label_trend_chart_settings = $14, extra_aggregations = $15, apdex_settings = $16, min_test_duration = $17 WHERE s.name = $2 AND s.project_id = (SELECT id FROM jtl.projects WHERE project_name = $1)`, - values: [projectName, scenarioName, name, analysisEnabled, thresholds.enabled, thresholds.percentile, thresholds.throughput, thresholds.errorRate, deleteSamples, zeroErrorToleranceEnabled, keepTestRunPeriod, generateShareToken, labelFilterSettings, labelTrendChartSettings, extraAggregations, apdexSettings], + values: [projectName, scenarioName, name, analysisEnabled, thresholds.enabled, thresholds.percentile, thresholds.throughput, thresholds.errorRate, deleteSamples, zeroErrorToleranceEnabled, keepTestRunPeriod, generateShareToken, labelFilterSettings, labelTrendChartSettings, extraAggregations, apdexSettings, minTestDuration], } } diff --git a/src/server/schema-validator/scenario-schema.ts b/src/server/schema-validator/scenario-schema.ts index f0837977..d41afa10 100644 --- a/src/server/schema-validator/scenario-schema.ts +++ b/src/server/schema-validator/scenario-schema.ts @@ -5,6 +5,7 @@ import { ENVIRONMENT_MAX_LENGTH } from "../controllers/item/create-item-const" const MAX_NUMBER = 100 const URL_MAX_LENGTH = 400 const MAX_NOTE_LENGTH = 200 +const MAX_MIN_TEST_DURATION = 1000 export const paramsSchema = { projectName: Joi.string().required(), @@ -43,6 +44,7 @@ export const updateScenarioSchema = { ...scenarioSchema, analysisEnabled: Joi.boolean().required(), zeroErrorToleranceEnabled: Joi.boolean().required(), + minTestDuration: Joi.number().min(0).max(MAX_MIN_TEST_DURATION).required(), deleteSamples: Joi.boolean().required(), keepTestRunsPeriod: Joi.number().required(), generateShareToken: Joi.boolean().required(), diff --git a/src/tests/integration/scenario.spec.ts b/src/tests/integration/scenario.spec.ts index 442b5344..f774ff85 100644 --- a/src/tests/integration/scenario.spec.ts +++ b/src/tests/integration/scenario.spec.ts @@ -59,6 +59,7 @@ describe("Scenario", () => { zeroErrorToleranceEnabled: true, deleteSamples: false, keepTestRunsPeriod: 7, + minTestDuration: 5, generateShareToken: true, extraAggregations: false, thresholds: { @@ -115,6 +116,7 @@ describe("Scenario", () => { analysisEnabled: false, zeroErrorToleranceEnabled: true, deleteSamples: false, + minTestDuration: 5, keepTestRunsPeriod: 7, generateShareToken: true, extraAggregations: false,