Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: pick ephemeral port once per agent #846

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ module.exports = function(app, options = {}) {
'supertest: this version of Node.js does not support http2'
);
}
app = http2.createServer(app); // eslint-disable-line no-param-reassign
app = http2.createServer(app).listen(0); // eslint-disable-line no-param-reassign
} else {
app = http.createServer(app); // eslint-disable-line no-param-reassign
app = http.createServer(app).listen(0); // eslint-disable-line no-param-reassign
}
}

Expand Down
4 changes: 2 additions & 2 deletions lib/agent.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ function TestAgent(app, options = {}) {
'supertest: this version of Node.js does not support http2'
);
}
app = http2.createServer(app); // eslint-disable-line no-param-reassign
app = http2.createServer(app).listen(0); // eslint-disable-line no-param-reassign
} else {
app = http.createServer(app); // eslint-disable-line no-param-reassign
app = http.createServer(app).listen(0); // eslint-disable-line no-param-reassign
}
}
this.app = app;
Expand Down
15 changes: 9 additions & 6 deletions test/supertest.js
Original file line number Diff line number Diff line change
Expand Up @@ -1390,13 +1390,16 @@ describeHttp2('http2', function() {
res.end('hey');
};

it('should fire up the app on an ephemeral port', function (done) {
api(app, { http2: true })
it('should fire up the app on a single ephemeral port', function (done) {
const agent = api(app, { http2: true });
agent
.get('/')
.end(function (err, res) {
res.status.should.equal(200);
res.text.should.equal('hey');
done();
.end(function (err1, res1) {
res1.request.url.should.match(/^http:\/\/127.0.0.1:(\d+)\/$/);
agent.get('/').end(function (err2, res2) {
res2.request.url.should.equal(res1.request.url);
done();
});
});
});

Expand Down