Skip to content

Commit

Permalink
Fix api server flaky tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nazarhussain committed Feb 6, 2024
1 parent 5841079 commit a73adb8
Show file tree
Hide file tree
Showing 10 changed files with 19 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {getRoutes} from "../../../../src/beacon/server/beacon.js";
import {runGenericServerTest} from "../../../utils/genericServerTest.js";
import {testData} from "../testData/beacon.js";

describe("beacon / beacon", () => {
describe.sequential("beacon / beacon", () => {
runGenericServerTest<Api, ReqTypes>(
// eslint-disable-next-line @typescript-eslint/naming-convention
createChainForkConfig({...defaultChainConfig, ALTAIR_FORK_EPOCH: 1, BELLATRIX_FORK_EPOCH: 2}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,8 @@ import {testData} from "../testData/config.js";

/* eslint-disable @typescript-eslint/naming-convention */

describe("beacon / config", () => {
describe("Run generic server test", () => {
runGenericServerTest<Api, ReqTypes>(config, getClient, getRoutes, testData);
});
describe.sequential("beacon / config", () => {
runGenericServerTest<Api, ReqTypes>(config, getClient, getRoutes, testData);

it("Serialize Partial Spec object", () => {
const returnTypes = getReturnTypes();
Expand Down
8 changes: 3 additions & 5 deletions packages/api/test/unit/beacon/genericServerTest/debug.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,10 @@ import {registerRoute} from "../../../../src/utils/server/registerRoute.js";
import {HttpClient} from "../../../../src/utils/client/httpClient.js";
import {testData} from "../testData/debug.js";

describe(
describe.sequential(
"beacon / debug",
function () {
describe("Run generic server test", () => {
runGenericServerTest<Api, ReqTypes>(config, getClient, getRoutes, testData);
});
() => {
runGenericServerTest<Api, ReqTypes>(config, getClient, getRoutes, testData);

// Get state by SSZ

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ import {getRoutes} from "../../../../src/beacon/server/lightclient.js";
import {runGenericServerTest} from "../../../utils/genericServerTest.js";
import {testData} from "../testData/lightclient.js";

describe("beacon / lightclient", () => {
describe.sequential("beacon / lightclient", () => {
runGenericServerTest<Api, ReqTypes>(config, getClient, getRoutes, testData);
});
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ import {getRoutes} from "../../../../src/beacon/server/node.js";
import {runGenericServerTest} from "../../../utils/genericServerTest.js";
import {testData} from "../testData/node.js";

describe("beacon / node", () => {
describe.sequential("beacon / node", () => {
runGenericServerTest<Api, ReqTypes>(config, getClient, getRoutes, testData);
});
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ import {getRoutes} from "../../../../src/beacon/server/proof.js";
import {runGenericServerTest} from "../../../utils/genericServerTest.js";
import {testData} from "../testData/proofs.js";

describe("beacon / proofs", () => {
describe.sequential("beacon / proofs", () => {
runGenericServerTest<Api, ReqTypes>(config, getClient, getRoutes, testData);
});
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {getRoutes} from "../../../../src/beacon/server/validator.js";
import {runGenericServerTest} from "../../../utils/genericServerTest.js";
import {testData} from "../testData/validator.js";

describe("beacon / validator", () => {
describe.sequential("beacon / validator", () => {
runGenericServerTest<Api, ReqTypes>(config, getClient, getRoutes, testData);

// TODO: Extra tests to implement maybe
Expand Down
2 changes: 1 addition & 1 deletion packages/api/test/unit/builder/builder.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {getRoutes} from "../../../src/builder/server/index.js";
import {runGenericServerTest} from "../../utils/genericServerTest.js";
import {testData} from "./testData.js";

describe("builder", () => {
describe.sequential("builder", () => {
runGenericServerTest<Api, ReqTypes>(
createChainForkConfig({
...defaultChainConfig,
Expand Down
2 changes: 1 addition & 1 deletion packages/api/test/unit/keymanager/keymanager.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ import {getRoutes} from "../../../src/keymanager/server/index.js";
import {runGenericServerTest} from "../../utils/genericServerTest.js";
import {testData} from "./testData.js";

describe("keymanager", () => {
describe.sequential("keymanager", () => {
runGenericServerTest<Api, ReqTypes>(config, getClient, getRoutes, testData);
});
14 changes: 7 additions & 7 deletions packages/api/test/utils/genericServerTest.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {it, expect, MockInstance} from "vitest";
import {it, expect, MockInstance, describe} from "vitest";
import {ChainForkConfig} from "@lodestar/config";
import {ReqGeneric, Resolves} from "../../src/utils/index.js";
import {FetchOpts, HttpClient, IHttpClient} from "../../src/utils/client/index.js";
Expand Down Expand Up @@ -37,17 +37,17 @@ export function runGenericServerTest<
registerRoute(server, route);
}

for (const key of Object.keys(testCases)) {
const routeId = key as keyof Api;
const testCase = testCases[routeId];
describe("run generic server tests", () => {
it.each(Object.keys(testCases))("%s", async (key) => {
const routeId = key as keyof Api;
const testCase = testCases[routeId];

it(routeId as string, async () => {
// Register mock data for this route
// TODO: Look for the type error
(mockApi[routeId] as MockInstance).mockResolvedValue(testCases[routeId].res);

// Do the call
const res = await (client[routeId] as APIClientHandler)(...(testCase.args as any[]));
const res = await client[routeId](...(testCase.args as any[]));

// Use spy to assert argument serialization
if (testCase.query) {
Expand All @@ -64,7 +64,7 @@ export function runGenericServerTest<
// Assert returned value is correct
expect(res.response).toEqual(testCase.res);
});
}
});
}

class HttpClientSpy extends HttpClient {
Expand Down

0 comments on commit a73adb8

Please sign in to comment.