Skip to content

Commit

Permalink
Minimum test duration setting for scenario (#301)
Browse files Browse the repository at this point in the history
  • Loading branch information
ludeknovy authored Mar 1, 2024
1 parent 62d9852 commit 80ce582
Show file tree
Hide file tree
Showing 11 changed files with 27 additions and 9 deletions.
9 changes: 9 additions & 0 deletions migrations/1709293652942_min-test-duration.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
exports.up = (pgm) => {
pgm.addColumn({ schema: "jtl", name: "scenario" }, {
min_test_duration: {
type: "smallint",
"default": 5,
notNull: true,
},
})
}
1 change: 1 addition & 0 deletions src/server/controllers/item/create-item-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -237,3 +237,4 @@ const handleError = async (itemId: string, kpiFilename: string, processingError:
logger.error(`File ${kpiFilename} does not exist anymore`)
}
}

4 changes: 2 additions & 2 deletions src/server/controllers/item/get-item-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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))

Expand All @@ -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: {
Expand Down
1 change: 1 addition & 0 deletions src/server/controllers/scenario/get-scenario-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ describe("updateScenariosController", () => {
},
analysisEnabled: true,
scenarioName: "test-scenario",
minTestDuration: 3,
deleteSamples: false,
zeroErrorToleranceEnabled: false,
keepTestRunsPeriod: 7,
Expand Down Expand Up @@ -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)
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
Expand Down
3 changes: 2 additions & 1 deletion src/server/queries/items.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/server/queries/projects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions src/server/queries/scenario.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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],
}
}

Expand Down
2 changes: 2 additions & 0 deletions src/server/schema-validator/scenario-schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down Expand Up @@ -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(),
Expand Down
2 changes: 2 additions & 0 deletions src/tests/integration/scenario.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ describe("Scenario", () => {
zeroErrorToleranceEnabled: true,
deleteSamples: false,
keepTestRunsPeriod: 7,
minTestDuration: 5,
generateShareToken: true,
extraAggregations: false,
thresholds: {
Expand Down Expand Up @@ -115,6 +116,7 @@ describe("Scenario", () => {
analysisEnabled: false,
zeroErrorToleranceEnabled: true,
deleteSamples: false,
minTestDuration: 5,
keepTestRunsPeriod: 7,
generateShareToken: true,
extraAggregations: false,
Expand Down

0 comments on commit 80ce582

Please sign in to comment.