-
Notifications
You must be signed in to change notification settings - Fork 8.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: Add test run entity (no-changelog) (#11832)
- Loading branch information
1 parent
2c34bf4
commit 11f9212
Showing
9 changed files
with
138 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { Column, Entity, Index, ManyToOne, RelationId } from '@n8n/typeorm'; | ||
|
||
import { | ||
datetimeColumnType, | ||
jsonColumnType, | ||
WithTimestampsAndStringId, | ||
} from '@/databases/entities/abstract-entity'; | ||
import { TestDefinition } from '@/databases/entities/test-definition.ee'; | ||
|
||
type TestRunStatus = 'new' | 'running' | 'completed' | 'error'; | ||
|
||
export type AggregatedTestRunMetrics = Record<string, number | boolean>; | ||
|
||
/** | ||
* Entity representing a Test Run. | ||
* It stores info about a specific run of a test, combining the test definition with the status and collected metrics | ||
*/ | ||
@Entity() | ||
@Index(['testDefinition']) | ||
export class TestRun extends WithTimestampsAndStringId { | ||
@ManyToOne('TestDefinition', 'runs') | ||
testDefinition: TestDefinition; | ||
|
||
@RelationId((testRun: TestRun) => testRun.testDefinition) | ||
testDefinitionId: string; | ||
|
||
@Column('varchar') | ||
status: TestRunStatus; | ||
|
||
@Column({ type: datetimeColumnType, nullable: true }) | ||
runAt: Date | null; | ||
|
||
@Column({ type: datetimeColumnType, nullable: true }) | ||
completedAt: Date | null; | ||
|
||
@Column(jsonColumnType, { nullable: true }) | ||
metrics: AggregatedTestRunMetrics; | ||
} |
27 changes: 27 additions & 0 deletions
27
packages/cli/src/databases/migrations/common/1732549866705-CreateTestRunTable.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import type { MigrationContext, ReversibleMigration } from '@/databases/types'; | ||
|
||
const testRunTableName = 'test_run'; | ||
|
||
export class CreateTestRun1732549866705 implements ReversibleMigration { | ||
async up({ schemaBuilder: { createTable, column } }: MigrationContext) { | ||
await createTable(testRunTableName) | ||
.withColumns( | ||
column('id').varchar(36).primary.notNull, | ||
column('testDefinitionId').varchar(36).notNull, | ||
column('status').varchar().notNull, | ||
column('runAt').timestamp(), | ||
column('completedAt').timestamp(), | ||
column('metrics').json, | ||
) | ||
.withIndexOn('testDefinitionId') | ||
.withForeignKey('testDefinitionId', { | ||
tableName: 'test_definition', | ||
columnName: 'id', | ||
onDelete: 'CASCADE', | ||
}).withTimestamps; | ||
} | ||
|
||
async down({ schemaBuilder: { dropTable } }: MigrationContext) { | ||
await dropTable(testRunTableName); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
packages/cli/src/databases/repositories/test-run.repository.ee.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { DataSource, Repository } from '@n8n/typeorm'; | ||
import { Service } from 'typedi'; | ||
|
||
import type { AggregatedTestRunMetrics } from '@/databases/entities/test-run.ee'; | ||
import { TestRun } from '@/databases/entities/test-run.ee'; | ||
|
||
@Service() | ||
export class TestRunRepository extends Repository<TestRun> { | ||
constructor(dataSource: DataSource) { | ||
super(TestRun, dataSource.manager); | ||
} | ||
|
||
public async createTestRun(testDefinitionId: string) { | ||
const testRun = this.create({ | ||
status: 'new', | ||
testDefinition: { id: testDefinitionId }, | ||
}); | ||
|
||
return await this.save(testRun); | ||
} | ||
|
||
public async markAsRunning(id: string) { | ||
return await this.update(id, { status: 'running', runAt: new Date() }); | ||
} | ||
|
||
public async markAsCompleted(id: string, metrics: AggregatedTestRunMetrics) { | ||
return await this.update(id, { status: 'completed', completedAt: new Date(), metrics }); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters