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

Refactored `test-http-allow-req-after-204-res` file to use countdown #17211

Closed
wants to merge 1 commit into
base: master
from

Conversation

Projects
None yet
9 participants
@mithunsasidharan
Contributor

mithunsasidharan commented Nov 22, 2017

Refactored the test case test-http-allow-req-after-204-res to use countdown, as per issue #17169

Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • tests and/or benchmarks are included
  • commit message follows commit guidelines
Affected core subsystem(s)

test

@aqrln

Hi and thanks a lot for your contribution! I left a couple of comments.

Show outdated Hide outdated test/parallel/test-http-allow-req-after-204-res.js Outdated
Show outdated Hide outdated test/parallel/test-http-allow-req-after-204-res.js Outdated
@mithunsasidharan

This comment has been minimized.

Show comment
Hide comment
@mithunsasidharan

mithunsasidharan Nov 22, 2017

Contributor

@aqrln : Thanks for the feedback. I've updated the PR with changes. I accidentally closed the PR...apologies for that. Kindly review!

Contributor

mithunsasidharan commented Nov 22, 2017

@aqrln : Thanks for the feedback. I've updated the PR with changes. I accidentally closed the PR...apologies for that. Kindly review!

@aqrln

aqrln approved these changes Nov 22, 2017

@aqrln

This comment has been minimized.

Show comment
Hide comment
@jasnell

This comment has been minimized.

Show comment
Hide comment
@jasnell

jasnell Nov 22, 2017

Member

CI is failing on this.

Member

jasnell commented Nov 22, 2017

CI is failing on this.

@thefourtheye

This comment has been minimized.

Show comment
Hide comment
@thefourtheye

thefourtheye Nov 26, 2017

Contributor

This patch works

diff --git a/test/common/countdown.js b/test/common/countdown.js
index 6a22be0a07..93bdbbfb16 100644
--- a/test/common/countdown.js
+++ b/test/common/countdown.js
@@ -17,6 +17,7 @@ class Countdown {
     assert(this[kLimit] > 0, 'Countdown expired');
     if (--this[kLimit] === 0)
       this[kCallback]();
+    return this[kLimit];
   }

   get remaining() {
diff --git a/test/parallel/test-http-allow-req-after-204-res.js b/test/parallel/test-http-allow-req-after-204-res.js
index cd55a4f17c..53237f6677 100644
--- a/test/parallel/test-http-allow-req-after-204-res.js
+++ b/test/parallel/test-http-allow-req-after-204-res.js
@@ -23,12 +23,12 @@
 const common = require('../common');
 const http = require('http');
 const assert = require('assert');
+const Countdown = require('../common/countdown');

 // first 204 or 304 works, subsequent anything fails
 const codes = [204, 200];

-// Methods don't really matter, but we put in something realistic.
-const methods = ['DELETE', 'DELETE'];
+const countdown = new Countdown(codes.length, () => server.close());

 const server = http.createServer(common.mustCall((req, res) => {
   const code = codes.shift();
@@ -39,17 +39,13 @@ const server = http.createServer(common.mustCall((req, res) => {
 }, codes.length));

 function nextRequest() {
-  const method = methods.shift();
-
-  const request = http.request({
+  const request = http.get({
     port: server.address().port,
-    method: method,
     path: '/'
   }, common.mustCall((response) => {
     response.on('end', common.mustCall(() => {
-      if (methods.length === 0) {
-        server.close();
-      } else {
+      if (countdown.dec()) {
         // throws error:
         nextRequest();
         // works just fine:
Contributor

thefourtheye commented Nov 26, 2017

This patch works

diff --git a/test/common/countdown.js b/test/common/countdown.js
index 6a22be0a07..93bdbbfb16 100644
--- a/test/common/countdown.js
+++ b/test/common/countdown.js
@@ -17,6 +17,7 @@ class Countdown {
     assert(this[kLimit] > 0, 'Countdown expired');
     if (--this[kLimit] === 0)
       this[kCallback]();
+    return this[kLimit];
   }

   get remaining() {
diff --git a/test/parallel/test-http-allow-req-after-204-res.js b/test/parallel/test-http-allow-req-after-204-res.js
index cd55a4f17c..53237f6677 100644
--- a/test/parallel/test-http-allow-req-after-204-res.js
+++ b/test/parallel/test-http-allow-req-after-204-res.js
@@ -23,12 +23,12 @@
 const common = require('../common');
 const http = require('http');
 const assert = require('assert');
+const Countdown = require('../common/countdown');

 // first 204 or 304 works, subsequent anything fails
 const codes = [204, 200];

-// Methods don't really matter, but we put in something realistic.
-const methods = ['DELETE', 'DELETE'];
+const countdown = new Countdown(codes.length, () => server.close());

 const server = http.createServer(common.mustCall((req, res) => {
   const code = codes.shift();
@@ -39,17 +39,13 @@ const server = http.createServer(common.mustCall((req, res) => {
 }, codes.length));

 function nextRequest() {
-  const method = methods.shift();
-
-  const request = http.request({
+  const request = http.get({
     port: server.address().port,
-    method: method,
     path: '/'
   }, common.mustCall((response) => {
     response.on('end', common.mustCall(() => {
-      if (methods.length === 0) {
-        server.close();
-      } else {
+      if (countdown.dec()) {
         // throws error:
         nextRequest();
         // works just fine:
@mithunsasidharan

This comment has been minimized.

Show comment
Hide comment
@mithunsasidharan

mithunsasidharan Nov 27, 2017

Contributor

@thefourtheye : Thanks for suggesting the correction. I've update the PR. Kindly review!

Contributor

mithunsasidharan commented Nov 27, 2017

@thefourtheye : Thanks for suggesting the correction. I've update the PR. Kindly review!

@mithunsasidharan

This comment has been minimized.

Show comment
Hide comment
@mithunsasidharan

mithunsasidharan Nov 27, 2017

Contributor

@maclover7 : Kindly run the CI for this PR too. Thanks !

Contributor

mithunsasidharan commented Nov 27, 2017

@maclover7 : Kindly run the CI for this PR too. Thanks !

@aqrln

This comment has been minimized.

Show comment
Hide comment
if (methods.length === 0) {
server.close();
} else {
if (countdown.dec()) {

This comment has been minimized.

@aqrln

aqrln Nov 28, 2017

Member

No strong opinion, but instead of modifying common/countdown.js, you can just use the existing API and do something like

countdown.dec();
if (countdown.remaining > 0) {
  ...
}
@aqrln

aqrln Nov 28, 2017

Member

No strong opinion, but instead of modifying common/countdown.js, you can just use the existing API and do something like

countdown.dec();
if (countdown.remaining > 0) {
  ...
}

This comment has been minimized.

@mithunsasidharan

mithunsasidharan Nov 28, 2017

Contributor

@aqrln : I feel making the change in countdown.jswill be better as it makes the test case condition more readable and save an extra line! Kindly suggest. Also, could you please run the CI. I've fixed the lint issues. Thanks.

@mithunsasidharan

mithunsasidharan Nov 28, 2017

Contributor

@aqrln : I feel making the change in countdown.jswill be better as it makes the test case condition more readable and save an extra line! Kindly suggest. Also, could you please run the CI. I've fixed the lint issues. Thanks.

This comment has been minimized.

@aqrln

aqrln Nov 28, 2017

Member

@mithunsasidharan sure, no problem. In the future, please run make -j4 test locally before pushing to the PR branch to save your time and the number of review iterations. Thanks!

@aqrln

aqrln Nov 28, 2017

Member

@mithunsasidharan sure, no problem. In the future, please run make -j4 test locally before pushing to the PR branch to save your time and the number of review iterations. Thanks!

@aqrln

This comment has been minimized.

Show comment
Hide comment
@mithunsasidharan

This comment has been minimized.

Show comment
Hide comment
@mithunsasidharan
Contributor

mithunsasidharan commented Nov 29, 2017

@addaleax @aqrln : Thanks !

@addaleax

This comment has been minimized.

Show comment
Hide comment
@addaleax

addaleax Dec 1, 2017

Member

Landed in f6926d5

Thanks for the contribution! 🎉

Member

addaleax commented Dec 1, 2017

Landed in f6926d5

Thanks for the contribution! 🎉

@addaleax addaleax closed this Dec 1, 2017

@addaleax addaleax removed the author ready label Dec 1, 2017

addaleax added a commit that referenced this pull request Dec 1, 2017

test: refactored test-http-allow-req-after-204-res to countdown
PR-URL: #17211
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Alexey Orlenko <eaglexrlnk@gmail.com>
Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>

MylesBorins added a commit that referenced this pull request Dec 12, 2017

test: refactored test-http-allow-req-after-204-res to countdown
PR-URL: #17211
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Alexey Orlenko <eaglexrlnk@gmail.com>
Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>

MylesBorins added a commit that referenced this pull request Dec 12, 2017

test: refactored test-http-allow-req-after-204-res to countdown
PR-URL: #17211
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Alexey Orlenko <eaglexrlnk@gmail.com>
Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>

@MylesBorins MylesBorins referenced this pull request Dec 12, 2017

Merged

v9.3.0 proposal #17631

gibfahn added a commit that referenced this pull request Dec 20, 2017

test: refactored test-http-allow-req-after-204-res to countdown
PR-URL: #17211
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Alexey Orlenko <eaglexrlnk@gmail.com>
Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>

gibfahn added a commit that referenced this pull request Dec 20, 2017

test: refactored test-http-allow-req-after-204-res to countdown
PR-URL: #17211
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Alexey Orlenko <eaglexrlnk@gmail.com>
Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>

gibfahn added a commit that referenced this pull request Dec 20, 2017

test: refactored test-http-allow-req-after-204-res to countdown
PR-URL: #17211
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Alexey Orlenko <eaglexrlnk@gmail.com>
Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>

@gibfahn gibfahn referenced this pull request Dec 20, 2017

Closed

v8.9.4 proposal #17772

gibfahn added a commit that referenced this pull request Dec 20, 2017

test: refactored test-http-allow-req-after-204-res to countdown
PR-URL: #17211
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Alexey Orlenko <eaglexrlnk@gmail.com>
Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>

@gibfahn gibfahn referenced this pull request Dec 20, 2017

Merged

v8.9.4 proposal #17774

@MylesBorins MylesBorins referenced this pull request Dec 20, 2017

Merged

v6.12.3 proposal #17776

msoechting added a commit to hpicgs/node that referenced this pull request Feb 5, 2018

test: refactored test-http-allow-req-after-204-res to countdown
PR-URL: nodejs#17211
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Alexey Orlenko <eaglexrlnk@gmail.com>
Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>

msoechting added a commit to hpicgs/node that referenced this pull request Feb 7, 2018

test: refactored test-http-allow-req-after-204-res to countdown
PR-URL: nodejs#17211
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Alexey Orlenko <eaglexrlnk@gmail.com>
Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment