Skip to content

Commit

Permalink
Add test of timeout abort
Browse files Browse the repository at this point in the history
- Fix sending a signal so that it actually aborts
  • Loading branch information
rmeritz committed Jun 18, 2020
1 parent 554808a commit 0c90b8f
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/run_action.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,17 @@ function runAction(base, method, path, queryParams, bodyData, callback, numAttem
headers['User-Agent'] = userAgent;
}

var controller = new AbortController();
var options = {
method: method.toUpperCase(),
headers: headers,
signal: controller.signal,
};

if (bodyData !== null) {
options.body = JSON.stringify(bodyData);
}

var controller = new AbortController();
var timeout = setTimeout(function() {
controller.abort();
}, base._airtable.requestTimeout);
Expand Down
24 changes: 24 additions & 0 deletions test/find.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,4 +146,28 @@ describe('record retrival', function() {
expect(foundRecord.get('Name')).toBe('Rebecca');
});
});

it('can timeout if the servers are slow', function(done) {
var recordId = 'record1';

testExpressApp.set('handler override', function(req) {
expect(req.method).toBe('GET');
expect(req.url).toBe('/v0/app123/Table/record1?');
// Timeout before returning a response
});

return airtable
.base('app123')
.table('Table')
.find(recordId)
.then(
function() {
throw new Error('Promise unexpectedly fufilled.');
},
function(err) {
expect(err.message).toMatch(/aborted/);
done();
}
);
});
});
1 change: 1 addition & 0 deletions test/test_helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ function getMockEnvironmentAsync(options) {
airtable: new Airtable({
apiKey: 'key123',
endpointUrl: 'http://localhost:' + testServerPort,
requestTimeout: 100,
}),
teardownAsync: util.promisify(testServer.close.bind(testServer)),
testExpressApp: app,
Expand Down

0 comments on commit 0c90b8f

Please sign in to comment.