Savepoint
This commit is contained in:
parent
7db1a3456b
commit
02c483950c
45 changed files with 5136 additions and 256 deletions
|
@ -1,32 +1,34 @@
|
|||
CREATE SEQUENCE test_results_id_seq;
|
||||
CREATE TABLE test_results (
|
||||
id bigint NOT NULL DEFAULT nextval('test_results_seq') PRIMARY KEY,
|
||||
test_name varchar(255) DEFAULT NULL,
|
||||
test_class varchar(255) DEFAULT NULL,
|
||||
test_method varchar(255) DEFAULT NULL,
|
||||
test_path varchar(255) DEFAULT NULL,
|
||||
test_type varchar(32) DEFAULT NULL,
|
||||
test_timestamp timestamptz NOT NULL DEFAULT now(),
|
||||
test_retry BOOLEAN DEFAULT FALSE,
|
||||
origin varchar(255) DEFAULT NULL,
|
||||
failed BOOLEAN DEFAULT FALSE,
|
||||
failed_message varchar(2047) DEFAULT NULL,
|
||||
screenshot_url varchar(255) DEFAULT NULL,
|
||||
weblog_url varchar(255) DEFAULT NULL,
|
||||
id bigint NOT NULL DEFAULT nextval('test_results_seq') PRIMARY KEY,
|
||||
test_name varchar(255) DEFAULT NULL,
|
||||
test_class varchar(255) DEFAULT NULL,
|
||||
test_method varchar(255) DEFAULT NULL,
|
||||
test_path varchar(255) DEFAULT NULL,
|
||||
test_type varchar(32) DEFAULT NULL,
|
||||
test_timestamp timestamptz NOT NULL DEFAULT now(),
|
||||
test_retry BOOLEAN DEFAULT FALSE,
|
||||
origin varchar(255) DEFAULT NULL,
|
||||
failed BOOLEAN DEFAULT FALSE,
|
||||
failed_message varchar(2047) DEFAULT NULL,
|
||||
screenshot_url varchar(255) DEFAULT NULL,
|
||||
weblog_url varchar(255) DEFAULT NULL,
|
||||
);
|
||||
ALTER SEQUENCE test_results_id_seq OWNED BY test_results.id;
|
||||
|
||||
# Tables
|
||||
|
||||
PG Database Tables Mapped Out
|
||||
|
||||
## ```test_results```
|
||||
## `test_results`
|
||||
|
||||
| id | test_name | test_class | test_method | test_path | test_type | test_timestamp | test_retry | origin | failed | failed_message | screenshot_url | weblog_url |
|
||||
| int | string | string | string | string | string | timestamp | boolean | string | boolean | string | string | string |
|
||||
| 1 | My Test | My Test Class | My Failing Test Method | My Test Class Path | API | Date.now() | false | Test Suite A | true | Some Failure Messsage | screenshotUrl | weblogUrl |
|
||||
|
||||
- id Automatically Generated
|
||||
- test_name\* Name of test
|
||||
- test_class\* Name of class
|
||||
- test_class\* Name of class
|
||||
- test_method Name of failed method if failed else null
|
||||
- test_path Path to test class
|
||||
- test_type API/UI/Mobile
|
||||
|
@ -35,8 +37,5 @@ PG Database Tables Mapped Out
|
|||
- origin Test Suite test belongs to
|
||||
- failed Indicates if the test failed or not
|
||||
- failed_message Failure Message of test or null
|
||||
- screenshot_url Screenshot of failure
|
||||
- screenshot_url Screenshot of failure
|
||||
- weblog_url Log from the web console
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -1,19 +1,14 @@
|
|||
CREATE SEQUENCE test_results_id_seq;
|
||||
CREATE TABLE test_results (
|
||||
id bigint NOT NULL DEFAULT nextval('test_results_seq') PRIMARY KEY,
|
||||
test_name varchar(255) DEFAULT NULL,
|
||||
test_class varchar(255) DEFAULT NULL,
|
||||
test_method varchar(255) DEFAULT NULL,
|
||||
test_path varchar(255) DEFAULT NULL,
|
||||
test_type varchar(32) DEFAULT NULL,
|
||||
test_timestamp timestamptz NOT NULL DEFAULT now(),
|
||||
test_retry BOOLEAN DEFAULT FALSE,
|
||||
origin varchar(255) DEFAULT NULL,
|
||||
id bigint NOT NULL DEFAULT nextval('test_results_id_seq') PRIMARY KEY,
|
||||
name varchar(255) DEFAULT NULL,
|
||||
"method" varchar(255) DEFAULT NULL,
|
||||
env varchar(31) DEFAULT NULL,
|
||||
"timestamp" TIMESTAMP NOT NULL DEFAULT now(),
|
||||
retry BOOLEAN DEFAULT FALSE,
|
||||
failed BOOLEAN DEFAULT FALSE,
|
||||
failed_message varchar(2047) DEFAULT NULL,
|
||||
screenshot_url varchar(255) DEFAULT NULL,
|
||||
weblog_url varchar(255) DEFAULT NULL,
|
||||
screenshot varchar(255) DEFAULT NULL,
|
||||
weblog varchar(255) DEFAULT NULL
|
||||
);
|
||||
ALTER SEQUENCE test_results_id_seq OWNED BY test_results.id;
|
||||
|
||||
|
||||
ALTER SEQUENCE test_results_id_seq OWNED BY test_results.id;
|
18
lib/database/migrations/2_create_catalog_table.sql
Normal file
18
lib/database/migrations/2_create_catalog_table.sql
Normal file
|
@ -0,0 +1,18 @@
|
|||
CREATE SEQUENCE test_catalog_id_seq;
|
||||
CREATE TABLE test_catalog (
|
||||
id bigint NOT NULL DEFAULT nextval('test_catalog_id_seq') PRIMARY KEY,
|
||||
name varchar(255) DEFAULT NULL,
|
||||
class varchar(255) DEFAULT NULL,
|
||||
compound BOOLEAN DEFAULT FALSE,
|
||||
type varchar(31) DEFAULT NULL,
|
||||
markers varchar(255)[] DEFAULT NULL,
|
||||
ignored BOOLEAN DEFAULT FALSE,
|
||||
comment varchar(1023) DEFAULT NULL,
|
||||
coverage varchar(255)[] DEFAULT NULL,
|
||||
env varchar(31)[] DEFAULT NULL,
|
||||
"path" varchar(255) DEFAULT NULL,
|
||||
regions varchar(15)[] DEFAULT NULL,
|
||||
origin varchar(255) DEFAULT NULL,
|
||||
cron varchar(127) DEFAULT NULL
|
||||
);
|
||||
ALTER SEQUENCE test_catalog_id_seq OWNED BY test_catalog.id;
|
|
@ -2,7 +2,7 @@
|
|||
import { migrate } from "postgres-migrations";
|
||||
import createPgp from "pg-promise";
|
||||
import moment from "moment";
|
||||
import { WARN } from "../util/logging.js";
|
||||
import { INFO, WARN } from "../util/logging.js";
|
||||
// Environment Variables
|
||||
const {
|
||||
POSTGRES_DATABASE: database,
|
||||
|
|
|
@ -12,4 +12,3 @@ export const getSilencedTests = () => {
|
|||
const query = `SELECT * from ${table}`;
|
||||
return pg.query(query);
|
||||
};
|
||||
|
|
@ -12,4 +12,3 @@ export const getTests = () => {
|
|||
const query = `SELECT * from ${table}`;
|
||||
return pg.query(query);
|
||||
};
|
||||
|
64
lib/database/queries/results.js
Normal file
64
lib/database/queries/results.js
Normal file
|
@ -0,0 +1,64 @@
|
|||
import pg from "../postgres.js";
|
||||
// Imports
|
||||
import {
|
||||
insertQuery,
|
||||
selectWhereAnyQuery,
|
||||
selectWhereAllQuery,
|
||||
updateWhereAnyQuery,
|
||||
} from "../pg-query.js";
|
||||
// Constants
|
||||
const table = "test_results";
|
||||
// Queries
|
||||
export const insertTestResult = (testResult) => {
|
||||
const {
|
||||
test_name,
|
||||
test_class,
|
||||
test_method,
|
||||
test_path,
|
||||
test_type,
|
||||
test_timestamp,
|
||||
test_retry,
|
||||
origin,
|
||||
failed,
|
||||
failed_message,
|
||||
screenshot_url,
|
||||
expected_screenshot_url,
|
||||
weblog_url,
|
||||
} = testResult;
|
||||
|
||||
var query = insertQuery(table, {
|
||||
test_name,
|
||||
test_class,
|
||||
test_method,
|
||||
test_path,
|
||||
test_type,
|
||||
test_timestamp,
|
||||
test_retry,
|
||||
origin,
|
||||
failed,
|
||||
failed_message,
|
||||
screenshot_url,
|
||||
expected_screenshot_url,
|
||||
weblog_url,
|
||||
});
|
||||
|
||||
query += "\n RETURNING *";
|
||||
return pg.query(query);
|
||||
};
|
||||
|
||||
export const getCurrentlyFailing = () => {
|
||||
const query = `WITH recent as (SELECT * FROM test_results WHERE (timestamp BETWEEN NOW() - INTERVAL '24 HOURS' AND NOW()) AND NOT(failed AND retry)) SELECT * FROM recent WHERE timestamp = (SELECT MAX(timestamp) FROM recent r2 WHERE recent.name = r2.name) AND failed;
|
||||
`;
|
||||
return pg.query(query);
|
||||
|
||||
/*SELECT * FROM test_results WHERE "timestamp" BETWEEN NOW() - INTERVAL '24 HOURS' AND NOW(); <-- Last 24 hours all runs*/
|
||||
|
||||
/* SELECT * FROM test_results tr1 WHERE timestamp BETWEEN NOW() - INTERVAL '24 HOURS' AND NOW() AND timestamp = (SELECT MAX(timestamp) FROM test_results tr2 WHERE tr1.name = tr2.name); <-- Last 24 hours only most recent
|
||||
*/
|
||||
};
|
||||
|
||||
export const getCurrentlyFailingFull = (env) => {
|
||||
const query = `WITH recent AS (SELECT * FROM test_results WHERE (timestamp BETWEEN NOW() - INTERVAL '24 HOURS' AND NOW()) AND NOT(failed AND retry) AND env='prod') SELECT * FROM recent INNER JOIN test_catalog USING(name) WHERE timestamp = (SELECT MAX(timestamp) FROM recent r2 WHERE recent.name = r2.name) AND failed;
|
||||
;`;
|
||||
return pg.query(query);
|
||||
};
|
|
@ -1,51 +0,0 @@
|
|||
import pg from "../postgres.js";
|
||||
// Imports
|
||||
import {
|
||||
insertQuery,
|
||||
selectWhereAnyQuery,
|
||||
updateWhereAnyQuery,
|
||||
} from "../pg-query.js";
|
||||
// Constants
|
||||
const table = "test_results";
|
||||
// Queries
|
||||
export const insertTestResult = (testResult) => {
|
||||
const {
|
||||
test_name,
|
||||
test_class,
|
||||
test_method,
|
||||
test_path,
|
||||
test_type,
|
||||
test_timestamp,
|
||||
test_retry,
|
||||
origin,
|
||||
failed,
|
||||
failed_message,
|
||||
screenshot_url,
|
||||
expected_screenshot_url,
|
||||
weblog_url,
|
||||
} = testResult;
|
||||
|
||||
var query = insertQuery(table, {
|
||||
test_name,
|
||||
test_class,
|
||||
test_method,
|
||||
test_path,
|
||||
test_type,
|
||||
test_timestamp,
|
||||
test_retry,
|
||||
origin,
|
||||
failed,
|
||||
failed_message,
|
||||
screenshot_url,
|
||||
expected_screenshot_url,
|
||||
weblog_url,
|
||||
});
|
||||
|
||||
query += "\n RETURNING *";
|
||||
return pg.query(query);
|
||||
};
|
||||
|
||||
export const getCurrentlyFailing = () => {
|
||||
const query = "SELECT *";
|
||||
return pg.query(query);
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue