-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add `PreauthorizationPollingModule` which will constantly loop over unfinalized subintents and get their status from gateway
- Loading branch information
1 parent
0458176
commit 510127a
Showing
20 changed files
with
514 additions
and
136 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
79 changes: 79 additions & 0 deletions
79
packages/dapp-toolkit/src/helpers/exponential-backoff.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
import { afterAll, describe, expect, it, vi } from 'vitest' | ||
import { ExponentialBackoff } from './exponential-backoff' | ||
import { delayAsync } from '../test-helpers/delay-async' | ||
import { Subscription } from 'rxjs' | ||
|
||
describe('exponential backoff', () => { | ||
const subscription = new Subscription() | ||
|
||
it('should emit withBackoff$ observable', async () => { | ||
const backoff = ExponentialBackoff({ | ||
maxDelayTime: 2000, | ||
multiplier: 2, | ||
interval: 1000, | ||
}) | ||
|
||
const spy = vi.fn() | ||
|
||
subscription.add( | ||
backoff.withBackoff$.subscribe(() => { | ||
spy() | ||
backoff.trigger.next() | ||
}), | ||
) | ||
|
||
await delayAsync(4500) | ||
|
||
expect(spy).toHaveBeenCalledTimes(3) | ||
}) | ||
|
||
it('should emit error after timeout', async () => { | ||
const backoff = ExponentialBackoff({ | ||
maxDelayTime: 2000, | ||
multiplier: 2, | ||
interval: 2000, | ||
timeout: new Date(Date.now() + 1000), | ||
}) | ||
const spy = vi.fn() | ||
|
||
subscription.add( | ||
backoff.withBackoff$.subscribe((res) => { | ||
spy(res.isOk() ? res.value : res.error) | ||
|
||
backoff.trigger.next() | ||
}), | ||
) | ||
|
||
await delayAsync(2000) | ||
|
||
expect(spy).toHaveBeenCalledWith(0) | ||
expect(spy).toHaveBeenCalledWith({ | ||
error: 'timeout', | ||
}) | ||
}) | ||
|
||
it('should emit error after stop', async () => { | ||
const backoff = ExponentialBackoff({}) | ||
const spy = vi.fn() | ||
|
||
subscription.add( | ||
backoff.withBackoff$.subscribe((res) => { | ||
spy(res.isOk() ? res.value : res.error) | ||
if (res.isOk()) { | ||
backoff.trigger.next() | ||
} | ||
}), | ||
) | ||
|
||
await delayAsync(2000) | ||
backoff.stop() | ||
expect(spy).toHaveBeenCalledWith(0) | ||
expect(spy).toHaveBeenCalledWith({ | ||
error: 'stopped', | ||
}) | ||
}) | ||
|
||
afterAll(() => { | ||
subscription.unsubscribe() | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.