Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Save the number of successful, failed and total executions for Test Run (no-changelog) #12131

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
f5d3f0a
chore: Save the number of successful, failed and total executions for…
burivuhster Dec 6, 2024
af4b2f6
fix: tests
burivuhster Dec 10, 2024
513b6b0
fix: type error
burivuhster Dec 11, 2024
aa3d9ba
wip: add tests for pass/fail count
burivuhster Dec 11, 2024
665937a
wip: add tests for pass/fail count
burivuhster Dec 11, 2024
58cb56e
wip: Rewrite migrations to raw SQL, add column constraints
burivuhster Dec 18, 2024
a145733
wip: Change comments to JSDoc
burivuhster Dec 18, 2024
ebcdffe
wip: Report unexpected errors during the test run to Sentry
burivuhster Dec 18, 2024
a4af1e9
Merge branch 'master' into ai-505-backend-i-want-to-know-how-many-tes…
burivuhster Dec 18, 2024
4ec0032
wip: Fix tests
burivuhster Dec 18, 2024
c858eef
wip: Fix linter issue
burivuhster Dec 18, 2024
a13e5f7
wip: addressing PR feedback
burivuhster Dec 18, 2024
d0405de
wip: Add constraint for the stat columns in cancelled test run state
burivuhster Dec 19, 2024
52166c4
wip: Switch to ErrorReporter
burivuhster Dec 19, 2024
b400107
wip: Fix linter issue
burivuhster Dec 19, 2024
b6b19d7
wip: update check constraint for error state
burivuhster Dec 20, 2024
75a5a72
Merge branch 'master' into ai-505-backend-i-want-to-know-how-many-tes…
burivuhster Dec 20, 2024
e54dd55
chore: update migration timestamp after merge
burivuhster Dec 20, 2024
6c21fb3
Merge branch 'master' into ai-505-backend-i-want-to-know-how-many-tes…
burivuhster Jan 6, 2025
25dcbfb
wip: change db migration timestamp after merge
burivuhster Jan 6, 2025
9587e0e
Merge branch 'master' into ai-505-backend-i-want-to-know-how-many-tes…
burivuhster Jan 7, 2025
76565f7
wip: fix formatting issue
burivuhster Jan 7, 2025
9e2cb58
wip: fix lint issue
burivuhster Jan 7, 2025
446d46e
Merge branch 'master' into ai-505-backend-i-want-to-know-how-many-tes…
burivuhster Jan 7, 2025
c10da5b
wip: fix formatting issue
burivuhster Jan 7, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions packages/cli/src/databases/entities/test-run.ee.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,23 @@ export class TestRun extends WithTimestampsAndStringId {

@Column(jsonColumnType, { nullable: true })
metrics: AggregatedTestRunMetrics;

/**
* Total number of the test cases, matching the filter condition of the test definition (specified annotationTag)
*/
@Column('integer', { nullable: true })
totalCases: number;

/**
* Number of test cases that passed (evaluation workflow was executed successfully)
*/
@Column('integer', { nullable: true })
passedCases: number;

/**
* Number of failed test cases
* (any unexpected exception happened during the execution or evaluation workflow ended with an error)
*/
@Column('integer', { nullable: true })
failedCases: number;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import type { MigrationContext, ReversibleMigration } from '@/databases/types';

const columns = ['totalCases', 'passedCases', 'failedCases'] as const;

export class AddStatsColumnsToTestRun1736172058779 implements ReversibleMigration {
async up({ escape, runQuery }: MigrationContext) {
const tableName = escape.tableName('test_run');
const columnNames = columns.map((name) => escape.columnName(name));

// Values can be NULL only if the test run is new, otherwise they must be non-negative integers.
// Test run might be cancelled or interrupted by unexpected error at any moment, so values can be either NULL or non-negative integers.
for (const name of columnNames) {
await runQuery(`ALTER TABLE ${tableName} ADD COLUMN ${name} INT CHECK(
CASE
WHEN status = 'new' THEN ${name} IS NULL
WHEN status in ('cancelled', 'error') THEN ${name} IS NULL OR ${name} >= 0
ELSE ${name} >= 0
END
)`);
}
}

async down({ escape, runQuery }: MigrationContext) {
const tableName = escape.tableName('test_run');
const columnNames = columns.map((name) => escape.columnName(name));

for (const name of columnNames) {
await runQuery(`ALTER TABLE ${tableName} DROP COLUMN ${name}`);
}
}
}
2 changes: 2 additions & 0 deletions packages/cli/src/databases/migrations/mysqldb/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ import { CreateTestMetricTable1732271325258 } from '../common/1732271325258-Crea
import { CreateTestRun1732549866705 } from '../common/1732549866705-CreateTestRunTable';
import { AddMockedNodesColumnToTestDefinition1733133775640 } from '../common/1733133775640-AddMockedNodesColumnToTestDefinition';
import { AddManagedColumnToCredentialsTable1734479635324 } from '../common/1734479635324-AddManagedColumnToCredentialsTable';
import { AddStatsColumnsToTestRun1736172058779 } from '../common/1736172058779-AddStatsColumnsToTestRun';

export const mysqlMigrations: Migration[] = [
InitialMigration1588157391238,
Expand Down Expand Up @@ -154,4 +155,5 @@ export const mysqlMigrations: Migration[] = [
AddMockedNodesColumnToTestDefinition1733133775640,
AddManagedColumnToCredentialsTable1734479635324,
AddProjectIcons1729607673469,
AddStatsColumnsToTestRun1736172058779,
];
2 changes: 2 additions & 0 deletions packages/cli/src/databases/migrations/postgresdb/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ import { CreateTestMetricTable1732271325258 } from '../common/1732271325258-Crea
import { CreateTestRun1732549866705 } from '../common/1732549866705-CreateTestRunTable';
import { AddMockedNodesColumnToTestDefinition1733133775640 } from '../common/1733133775640-AddMockedNodesColumnToTestDefinition';
import { AddManagedColumnToCredentialsTable1734479635324 } from '../common/1734479635324-AddManagedColumnToCredentialsTable';
import { AddStatsColumnsToTestRun1736172058779 } from '../common/1736172058779-AddStatsColumnsToTestRun';

export const postgresMigrations: Migration[] = [
InitialMigration1587669153312,
Expand Down Expand Up @@ -154,4 +155,5 @@ export const postgresMigrations: Migration[] = [
AddMockedNodesColumnToTestDefinition1733133775640,
AddManagedColumnToCredentialsTable1734479635324,
AddProjectIcons1729607673469,
AddStatsColumnsToTestRun1736172058779,
];
2 changes: 2 additions & 0 deletions packages/cli/src/databases/migrations/sqlite/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ import { CreateTestMetricTable1732271325258 } from '../common/1732271325258-Crea
import { CreateTestRun1732549866705 } from '../common/1732549866705-CreateTestRunTable';
import { AddMockedNodesColumnToTestDefinition1733133775640 } from '../common/1733133775640-AddMockedNodesColumnToTestDefinition';
import { AddManagedColumnToCredentialsTable1734479635324 } from '../common/1734479635324-AddManagedColumnToCredentialsTable';
import { AddStatsColumnsToTestRun1736172058779 } from '../common/1736172058779-AddStatsColumnsToTestRun';

const sqliteMigrations: Migration[] = [
InitialMigration1588102412422,
Expand Down Expand Up @@ -148,6 +149,7 @@ const sqliteMigrations: Migration[] = [
AddMockedNodesColumnToTestDefinition1733133775640,
AddManagedColumnToCredentialsTable1734479635324,
AddProjectIcons1729607673469,
AddStatsColumnsToTestRun1736172058779,
];

export { sqliteMigrations };
18 changes: 16 additions & 2 deletions packages/cli/src/databases/repositories/test-run.repository.ee.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,28 @@ export class TestRunRepository extends Repository<TestRun> {
return await this.save(testRun);
}

async markAsRunning(id: string) {
return await this.update(id, { status: 'running', runAt: new Date() });
async markAsRunning(id: string, totalCases: number) {
return await this.update(id, {
status: 'running',
runAt: new Date(),
totalCases,
passedCases: 0,
failedCases: 0,
});
}

async markAsCompleted(id: string, metrics: AggregatedTestRunMetrics) {
return await this.update(id, { status: 'completed', completedAt: new Date(), metrics });
}

async incrementPassed(id: string) {
return await this.increment({ id }, 'passedCases', 1);
}

async incrementFailed(id: string) {
return await this.increment({ id }, 'failedCases', 1);
}

async getMany(testDefinitionId: string, options: ListQuery.Options) {
const findManyOptions: FindManyOptions<TestRun> = {
where: { testDefinition: { id: testDefinitionId } },
Expand Down
Loading
Loading