@daiso-tech/core
Version:
The library offers flexible, framework-agnostic solutions for modern web applications, built on adaptable components that integrate seamlessly with popular frameworks like Next Js.
81 lines (80 loc) • 3.23 kB
TypeScript
/**
* @module CircuitBreaker
*/
import { type TestAPI, type SuiteAPI, type ExpectStatic, type beforeEach } from "vitest";
import { type ConstantBackoffSettingsEnum } from "../../../backoff-policies/implementations/_module.js";
import { type ICircuitBreakerAdapter } from "../../../circuit-breaker/contracts/_module.js";
import { type CountBreakerSettingsEnum } from "../../../circuit-breaker/implementations/policies/_module.js";
import { type IReadableContext } from "../../../execution-context/contracts/_module.js";
import { type ITimeSpan } from "../../../time-span/contracts/_module.js";
import { type Promisable } from "../../../utilities/_module.js";
/**
* IMPORT_PATH: `"@daiso-tech/core/circuit-breaker/test-utilities"`
* @group TestUtilities
*/
export type CountBreakerTestSuiteSettings = {
expect: ExpectStatic;
test: TestAPI;
describe: SuiteAPI;
beforeEach: typeof beforeEach;
createAdapter: () => Promisable<ICircuitBreakerAdapter>;
/**
* @default
* ```ts
* import { TimeSpan } from "@daiso-tech/core/time-span";
*
* TimeSpan.fromMilliseconds(10)
* ```
*/
delayBuffer?: ITimeSpan;
/**
* @default
* ```ts
* import { ExecutionContext } from "@daiso-tech/core/execution-context"
* import { NoOpExecutionContextAdapter } from "@daiso-tech/core/execution-context/no-op-execution-context-adapter"
*
* new ExecutionContext(new NoOpExecutionContextAdapter())
* ```
*/
context?: IReadableContext;
};
/**
* IMPORT_PATH: `"@daiso-tech/core/circuit-breaker/test-utilities"`
* @group TestUtilities
*
* @example
* ```ts
* import { beforeEach, describe, expect, test } from "vitest";
* import { DatabaseCircuitBreakerAdapter } from "@daiso-tech/core/circuit-breaker/database-circuit-breaker-adapter";
* import { CountBreaker } from "@daiso-tech/core/circuit-breaker/policies";
* import { countBreakerTestSuite } from "@daiso-tech/core/circuit-breaker/test-utilities";
* import { constantBackoff } from "@daiso-tech/core/backoff-policies";
* import { MemoryCircuitBreakerStorageAdapter } from "@daiso-tech/core/circuit-breaker/memory-circuit-breaker-storage-adapter";
*
* describe("count-breaker class: DatabaseCircuitBreakerAdapter", () => {
* countBreakerTestSuite({
* createAdapter: () => {
* const adapter = new DatabaseCircuitBreakerAdapter({
* adapter: new MemoryCircuitBreakerStorageAdapter(),
* backoffPolicy: constantBackoff(
* countBreakerTestSuite.backoffPolicySettings,
* ),
* circuitBreakerPolicy: new CountBreaker(
* countBreakerTestSuite.circuitBreakerPolicySettings,
* ),
* });
* return adapter;
* },
* beforeEach,
* describe,
* expect,
* test,
* });
* });
* ```
*/
export declare function countBreakerTestSuite(settings: CountBreakerTestSuiteSettings): void;
export declare namespace countBreakerTestSuite {
var circuitBreakerPolicySettings: Required<CountBreakerSettingsEnum>;
var backoffPolicySettings: Required<ConstantBackoffSettingsEnum>;
}