Skip to content

Commit 8fee805

Browse files
authored
feat(cicero-core): add timeout option to HTTPArchiveLoader (#831)
Signed-off-by: Aadityavardhan Singh <singhrashmi018@gmail.com>
1 parent 837b192 commit 8fee805

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

packages/cicero-core/src/loaders/httparchiveloader.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@ class HTTPArchiveLoader {
5757
request.url = requestUrl;
5858
request.method = 'get';
5959
request.responseType = 'arraybuffer'; // Necessary for binary archives
60-
request.timeout = 5000;
60+
// Use the user's timeout, or default to 5000ms
61+
request.timeout = options.timeout || 5000;
6162
if (options.httpAuthHeader) {
6263
request.headers = {
6364
authorization: options.httpAuthHeader,

packages/cicero-core/test/httparchiveloader.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,5 +77,23 @@ describe('HTTPArchiveLoader', () => {
7777

7878
mock.stop('axios');
7979
});
80+
81+
it('should load an archive with a custom timeout', async function() {
82+
mock('axios', (params) => {
83+
axiosParams = params;
84+
return Promise.resolve({ data: 'data' });
85+
});
86+
HTTPArchiveLoader = mock.reRequire('../src/loaders/httparchiveloader');
87+
const loader = new HTTPArchiveLoader();
88+
89+
// ACT: We ask for a 10-second timeout (10000ms)
90+
await loader.load('https://templates.accordproject.org/archives/ip-payment@0.13.0.cta', { timeout: 10000 });
91+
92+
// ASSERT: We check if Axios actually received that number
93+
expect(axiosParams.timeout).to.equal(10000);
94+
95+
mock.stop('axios');
96+
});
97+
8098
});
8199
});

0 commit comments

Comments
 (0)