Skip to content

Commit

Permalink
Define loadSmallPayload() for consistency
Browse files Browse the repository at this point in the history
Signed-off-by: Stefan Marr <[email protected]>
  • Loading branch information
smarr committed Mar 24, 2024
1 parent b071994 commit 5336ba4
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 30 deletions.
14 changes: 4 additions & 10 deletions tests/backend/db/db-setup.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import {
closeMainDb
} from './db-testing.js';
import { robustPath } from '../../../src/backend/util.js';
import { loadLargePayload } from '../../payload.js';
import { loadLargePayload, loadSmallPayload } from '../../payload.js';

const numTxStatements = 3;

Expand Down Expand Up @@ -71,9 +71,7 @@ describe('Recording a ReBench execution data fragments', () => {
beforeAll(async () => {
db = await createAndInitializeDB('db_setup');

basicTestData = JSON.parse(
readFileSync(robustPath('../tests/data/small-payload.json')).toString()
);
basicTestData = loadSmallPayload();
});

afterAll(async () => {
Expand Down Expand Up @@ -126,9 +124,7 @@ describe('Recording a ReBench execution data fragments', () => {
});

it('should accept trial denoise info', async () => {
const testData: BenchmarkData = JSON.parse(
readFileSync(robustPath('../tests/data/small-payload.json')).toString()
);
const testData = loadSmallPayload();

const e = testData.env;

Expand Down Expand Up @@ -183,9 +179,7 @@ describe('Recording a ReBench execution from payload files', () => {
// to access the database from R
db = await createAndInitializeDB('db_setup_timeline', 25, true, false);

smallTestData = JSON.parse(
readFileSync(robustPath('../tests/data/small-payload.json')).toString()
);
smallTestData = loadSmallPayload();
largeTestData = loadLargePayload();
profileTestData = JSON.parse(
readFileSync(robustPath('../tests/data/profile-payload.json')).toString()
Expand Down
13 changes: 3 additions & 10 deletions tests/backend/db/db.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import {
it,
jest
} from '@jest/globals';
import { readFileSync } from 'node:fs';
import { PoolConfig, QueryConfig, QueryResult, QueryResultRow } from 'pg';

import {
Expand All @@ -21,7 +20,6 @@ import {
TimelineRequest
} from '../../../src/shared/api.js';

import { robustPath } from '../../../src/backend/util.js';
import {
Experiment,
Environment,
Expand All @@ -30,6 +28,7 @@ import {
Criterion
} from '../../../src/backend/db/types.js';
import { Database } from '../../../src/backend/db/db.js';
import { loadSmallPayload } from '../../payload.js';

describe('Record Trial', () => {
let db: TestDatabase;
Expand All @@ -39,10 +38,7 @@ describe('Record Trial', () => {

beforeAll(async () => {
db = await createAndInitializeDB('db_record_trial', 0, false, false);
const data = readFileSync(
robustPath('../tests/data/small-payload.json')
).toString();
basicTestData = JSON.parse(data);
basicTestData = loadSmallPayload();

env = await db.recordEnvironment(basicTestData.env);
exp = await db.recordExperiment(basicTestData);
Expand Down Expand Up @@ -109,10 +105,7 @@ describe('Timeline-plot Queries', () => {
beforeAll(async () => {
db = await createAndInitializeDB('db_ts_basic', 25, true, false);

const data = readFileSync(
robustPath('../tests/data/small-payload.json')
).toString();
const basicTestData: BenchmarkData = JSON.parse(data);
const basicTestData = loadSmallPayload();
projectName = basicTestData.projectName;

baseBranch = basicTestData.source.branchOrTag = 'base-branch';
Expand Down
8 changes: 2 additions & 6 deletions tests/backend/main/with-data.test.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import { describe, expect, beforeAll, afterAll, it, jest } from '@jest/globals';
import { readFileSync } from 'fs';

import {
TestDatabase,
createAndInitializeDB,
closeMainDb
} from '../db/db-testing.js';

import type { BenchmarkData } from '../../../src/shared/api.js';
import { robustPath } from '../../../src/backend/util.js';
import {
getChanges,
Expand All @@ -20,6 +18,7 @@ import { prepareTemplate } from '../../../src/backend/templates.js';
import { initJestMatchers } from '../../helpers.js';
// eslint-disable-next-line max-len
import { getLatestBenchmarksForTimelineView } from '../../../src/backend/timeline/timeline.js';
import { loadSmallPayload } from '../../payload.js';

initJestMatchers();

Expand All @@ -39,10 +38,7 @@ describe('Test with basic test data loaded', () => {
beforeAll(async () => {
db = await createAndInitializeDB('main_with_data', 25, true, false);

const data = readFileSync(
robustPath('../tests/data/small-payload.json')
).toString();
const basicTestData: BenchmarkData = JSON.parse(data);
const basicTestData = loadSmallPayload();
projectName = basicTestData.projectName;

await db.recordAllData(basicTestData);
Expand Down
10 changes: 6 additions & 4 deletions tests/backend/rebench/api.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@ import { ValidateFunction } from 'ajv';
import { createValidator } from '../../../src/backend/rebench/api-validator.js';
import { robustPath } from '../../../src/backend/util.js';
import { assert, log } from '../../../src/backend/logging.js';
import { loadLargePayload, loadLargePayloadApiV1 } from '../../payload.js';
import {
loadLargePayload,
loadLargePayloadApiV1,
loadSmallPayload
} from '../../payload.js';
import type { BenchmarkData } from '../../../src/shared/api.js';
import type { DataPointV1 } from '../../../src/backend/common/api-v1.js';

Expand All @@ -17,9 +21,7 @@ describe('Ensure Test Payloads conform to API', () => {
});

it('should validate small-payload.json', () => {
const testData = JSON.parse(
readFileSync(robustPath('../tests/data/small-payload.json')).toString()
);
const testData = loadSmallPayload();

const result = validateFn(testData);
if (!result) {
Expand Down
6 changes: 6 additions & 0 deletions tests/payload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ import type {
} from '../src/backend/db/types.js';
import { assert } from '../src/backend/logging.js';

export function loadSmallPayload(): BenchmarkData {
return JSON.parse(
readFileSync(robustPath('../tests/data/small-payload.json')).toString()
);
}

export function loadLargePayload(): BenchmarkData {
const testData = JSON.parse(
readFileSync(robustPath('../tests/data/large-payload.json')).toString()
Expand Down

0 comments on commit 5336ba4

Please sign in to comment.