Skip to content

Commit

Permalink
✅ More attempts to get request agent tests working on github actions
Browse files Browse the repository at this point in the history
  • Loading branch information
skerit committed Feb 14, 2024
1 parent cc37212 commit 515cbb7
Showing 1 changed file with 59 additions and 0 deletions.
59 changes: 59 additions & 0 deletions test/request_agents.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,65 @@ function recreateAgentKeepAlive() {
}

describe('HttpAgent', function() {

let old_it = it;
it = function(title, fn) {

let is_async = fn.constructor.name != 'Function';
let wrapper;
let has_callback = fn.length > 0;

let retries = 0;

if (is_async) {
wrapper = async function() {
this.timeout(50000);

try {
await fn.call(this);
} catch (err) {
retries++;
if (retries < 3) {
console.log('Retrying test', title, 'due to error:', err);
return wrapper();
} else {
throw err;
}
}
};
} else {
wrapper = function(done) {
this.timeout(50000);

try {

fn.call(this, function finish(err, result) {

if (err) {
retries++;
if (retries < 3) {
console.log('Retrying test', title, 'due to error:', err);
return wrapper(done);
} else {
return finish(err);
}
}

done(null);
});

if (!has_callback) {
done();
}
} catch (err) {
done(err);
}
};
}

old_it(title, wrapper);
};

before(function(done) {
Blast = require('../index.js')();

Expand Down

0 comments on commit 515cbb7

Please sign in to comment.