UNPKG

postchain-client

Version:

Client library for accessing a Postchain node through REST.

60 lines 2.84 kB
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; import { Method } from "../../src/blockchainClient/enums"; import { FailoverStrategy } from "../../src/blockchainClient/enums"; import { createNodeManager } from "../../src/blockchainClient/nodeManager"; import { handleRequest } from "../../src/blockchainClient/httpUtil"; import { requestWithFailoverStrategy } from "../../src/blockchainClient/requestWithFailoverStrategy"; import { MERKLE_HASH_VERSIONS } from "../../src/utils/constants"; jest.mock("../../src/blockchainClient/httpUtil", () => ({ handleRequest: jest.fn(), })); const mockHandleRequest = handleRequest; describe("retry functionality with attempts per endpoint set to three", () => { const nodeUrls = [ "http://localhost1:7740", "http://localhost2:7740", "http://localhost3:7740", ]; beforeEach(() => { jest.clearAllMocks(); }); it("retries request three times on each of the three endpoints, in total 9 attempts", () => __awaiter(void 0, void 0, void 0, function* () { yield requestWithFailoverStrategy(Method.GET, "query/8049DB98305FDB7C7360428FB779E7858C76BBEEF4A9D7F1C2B7AA0911AC2836/?type=hello_world", { endpointPool: [ { url: nodeUrls[0], whenAvailable: 0 }, { url: nodeUrls[1], whenAvailable: 0 }, { url: nodeUrls[2], whenAvailable: 0 }, ], nodeManager: createNodeManager({ nodeUrls: nodeUrls, }), merkleHashVersion: MERKLE_HASH_VERSIONS.ONE, dappStatusPolling: { interval: 500, count: 20, }, clusterAnchoringStatusPolling: { interval: 500, count: 20, }, systemAnchoringStatusPolling: { interval: 500, count: 20, }, failoverStrategy: FailoverStrategy.AbortOnError, attemptsPerEndpoint: 3, attemptInterval: 100, unreachableDuration: 100, }, Buffer.from("")); expect(mockHandleRequest).toHaveBeenCalledTimes(9); })); }); //# sourceMappingURL=httpUtil.test.js.map