-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #13 from seamapi/test-retry
- Loading branch information
Showing
5 changed files
with
137 additions
and
7 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import test from 'ava' | ||
import { AxiosError } from 'axios' | ||
import { getTestServer } from 'fixtures/seam/connect/api.js' | ||
|
||
import { SeamHttp } from '@seamapi/http/connect' | ||
|
||
test('SeamHttp: retries 503 status errors twice by default ', async (t) => { | ||
const { seed, endpoint, db } = await getTestServer(t) | ||
const expectedRetryCount = 2 | ||
|
||
db.simulateWorkspaceOutage(seed.seed_workspace_1, { | ||
routes: ['/devices/get'], | ||
}) | ||
|
||
t.plan(expectedRetryCount + 2) | ||
|
||
const seam = SeamHttp.fromApiKey(seed.seam_apikey1_token, { | ||
endpoint, | ||
axiosRetryOptions: { | ||
onRetry: (retryCount) => { | ||
t.true(retryCount <= expectedRetryCount) | ||
}, | ||
}, | ||
}) | ||
|
||
const err = await t.throwsAsync( | ||
async () => | ||
// UPSTREAM: This test should use seam.devices.get({ device_id: '...' }). | ||
// Only idempotent methods, e.g., GET not POST, are retried by default. | ||
// The SDK should use GET over POST once that method is supported upstream. | ||
// https://github.com/seamapi/nextlove/issues/117 | ||
await seam.client.get('/devices/get', { | ||
params: { | ||
device_id: seed.august_device_1, | ||
}, | ||
}), | ||
{ instanceOf: AxiosError }, | ||
) | ||
|
||
t.is(err?.response?.status, 503) | ||
}) |