Skip to content

Commit

Permalink
more cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
krpeacock committed Apr 30, 2024
1 parent 62badfc commit c149638
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 19 deletions.
7 changes: 5 additions & 2 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,18 @@

## [Unreleased]

## [1.2.1] - 2024-04-25

### Changed

* fix: retry logic now includes delays with exponential backoff. Retries should no longer happen too quickly for the replica to catch up.

### Added

* new `HttpAgent` option: `backoffStrategy` - allows you to set a custom delay strategy for retries. The default is a newly exported `exponentialBackoff`, but you can pass your own function to customize the delay between retries.

## [1.2.1] - 2024-04-25

### Added

- feat: make `IdbStorage` `get/set` methods generic
- chore: add context to errors thrown when failing to decode CBOR values.
- chore: replaces globle npm install with setup-node for size-limit action
Expand Down
1 change: 0 additions & 1 deletion e2e/node/basic/mainnet.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ const createWhoamiActor = async (identity: Identity) => {
};

describe('certified query', () => {
vi.useRealTimers();
it('should verify a query certificate', async () => {
const actor = await createWhoamiActor(new AnonymousIdentity());
const result = await actor.whoami();
Expand Down
2 changes: 0 additions & 2 deletions e2e/node/basic/watermark.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ test('replay queries only', async () => {
}, 10_000);

test('replay attack', async () => {
vi.useRealTimers();
const fetchProxy = new FetchProxy();
global.fetch;

Expand All @@ -92,7 +91,6 @@ test('replay attack', async () => {
backoffStrategy: () => ({
next: () => 0,
}),
retryTimes: 3,
});

const agent = Actor.agentOf(actor) as HttpAgent;
Expand Down
17 changes: 4 additions & 13 deletions packages/agent/src/actor.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { CallRequest, SubmitRequestType, UnSigned } from './agent/http/types';
import * as cbor from './cbor';
import { requestIdOf } from './request_id';
import * as pollingImport from './polling';
import { Actor, ActorConfig } from './actor';
import { ActorConfig } from './actor';

const importActor = async (mockUpdatePolling?: () => void) => {
jest.dontMock('./polling');
Expand All @@ -24,8 +24,6 @@ afterEach(() => {
global.Date.now = originalDateNowFn;
});


jest.setTimeout(30000);
describe('makeActor', () => {
// TODO: update tests to be compatible with changes to Certificate
it.skip('should encode calls', async () => {
Expand Down Expand Up @@ -135,7 +133,7 @@ describe('makeActor', () => {

const expectedCallRequestId = await requestIdOf(expectedCallRequest.content);

const httpAgent = new HttpAgent({ fetch: mockFetch, retryTimes: 0 });
const httpAgent = new HttpAgent({ fetch: mockFetch });

const actor = Actor.createActor(actorInterface, { canisterId, agent: httpAgent });
const reply = await actor.greet(argValue);
Expand Down Expand Up @@ -230,7 +228,6 @@ describe('makeActor', () => {
});
});
it('should enrich actor interface with httpDetails', async () => {
jest.useRealTimers();
const canisterDecodedReturnValue = 'Hello, World!';
const expectedReplyArg = IDL.encode([IDL.Text], [canisterDecodedReturnValue]);
const { Actor } = await importActor(() =>
Expand Down Expand Up @@ -277,12 +274,6 @@ describe('makeActor', () => {
fetch: mockFetch,
host: 'http://127.0.0.1',
verifyQuerySignatures: false,
backoffStrategy: () => {
return {
next: () => 0,
};
},
retryTimes: 0,
});
const canisterId = Principal.fromText('2chl6-4hpzw-vqaaa-aaaaa-c');
const actor = Actor.createActor(actorInterface, { canisterId, agent: httpAgent });
Expand Down Expand Up @@ -322,7 +313,7 @@ describe('makeActor', () => {
greet: IDL.Func([IDL.Text], [IDL.Text]),
});
};
const httpAgent = new HttpAgent({ fetch: mockFetch, host: 'http://127.0.0.1', retryTimes: 0 });
const httpAgent = new HttpAgent({ fetch: mockFetch, host: 'http://127.0.0.1' });
const canisterId = Principal.fromText('2chl6-4hpzw-vqaaa-aaaaa-c');
const actor = Actor.createActor(actorInterface, { canisterId, agent: httpAgent });

Expand All @@ -337,7 +328,7 @@ describe('makeActor', () => {
}
});
it('should throw a helpful error if the canisterId is not set', async () => {
const httpAgent = new HttpAgent({ host: 'http://127.0.0.1', retryTimes: 0 });
const httpAgent = new HttpAgent({ host: 'http://127.0.0.1' });
const actorInterface = () => {
return IDL.Service({
greet: IDL.Func([IDL.Text], [IDL.Text]),
Expand Down
1 change: 0 additions & 1 deletion packages/agent/src/agent/http/http.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -789,7 +789,6 @@ test('retry requests that fail due to a network failure', async () => {
const agent = new HttpAgent({
host: HTTP_AGENT_HOST,
fetch: mockFetch,
retryTimes: 3,
});

try {
Expand Down

0 comments on commit c149638

Please sign in to comment.