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

test: add tests for clearBuffer state machine #9922

Closed

Conversation

captainsafia
Copy link
Contributor

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

stream, test

Description of change

This checks to see that clearBuffer appropriately decrements the
correct values in _writableState when clearBuffer is invoked in
end.

Closes #8687.

@nodejs-github-bot nodejs-github-bot added the test Issues and PRs related to the tests. label Dec 1, 2016
@mscdex mscdex added the stream Issues and PRs related to the stream subsystem. label Dec 1, 2016
@imyller imyller added the code-and-learn Issues related to the Code-and-Learn events and PRs submitted during the events. label Dec 1, 2016
Copy link
Member

@bnoordhuis bnoordhuis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Someone from @nodejs/streams should do the final sign-off but LGTM insofar I'm able to judge that.

CI: https://ci.nodejs.org/job/node-test-pull-request/5077/

'use strict';

const common = require('../common');

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tiny nit: no blank line here.

@captainsafia
Copy link
Contributor Author

@bnoordhuis: Good catch on the blank line! Updated the code!

};

writable._writableState.corked = 1;
writable._writableState.bufferedRequestCount = 1;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you please trigger the corked and bufferedRequestCount things using the normal API?

@captainsafia
Copy link
Contributor Author

@mcollina: Thanks for the comment! I've tried to address your review.

I set corked use the cork function but I'm having a little bit of trouble setting the bufferedRequestCount using the API. From what I can say, it is incremented in writeOrBuffer which is called in write if the chunk provided is a valid chunk. For some strange reason, this bit of code doesn't produce the desired effect (incrementing bufferedRequestCount by 1 as done in writeOrBuffer).

writable.write('some-stuff', 'utf8', common.mustCall(() => {
    assert.strictEqual(writable._writableState.bufferedRequestCount, 1);
}));

I'm trying to trace what's going on but before I invest too much time I figured I might ask you and see if I am missing an obvious way to do this.

@mcollina
Copy link
Member

mcollina commented Dec 2, 2016

@captainsafia you need to have an async _write, and have write() being issued. Another alternative is to use cork() and uncork(). Let me know if you have any more questions, happy to chat on IRC if needed.

@captainsafia
Copy link
Contributor Author

@mcollina: Thanks for the guidance! I'll try pursuing it on my own for a bit next week and get in touch with you on IRC if I'm not getting anywhere.

@Trott
Copy link
Member

Trott commented Dec 11, 2016

Bump! @captainsafia Are you still working on this?

@captainsafia
Copy link
Contributor Author

Yep! I did some tinkering with it yesterday but I don't think I have anything commit worthy. I'll see if I can get something tomorrow or Monday. Sorry for leaving this hanging!

@captainsafia
Copy link
Contributor Author

@mcollina: Couldn't catch you on IRC so here goes.

@captainsafia you need to have an async _write, and have write() being issued.

I've got a barebones _write = (chunk, encoding, cb) implemented in the tests here. Should write be issue inside that function...or?

Another alternative is to use cork() and uncork().

I'm using cork to update the corked state right now but from what I can tell it doesn't change bufferedRequestCount so it's seems like not a complete alternative.


const writable = new stream.Writable();

writable._write = (chunk, encoding, cb) => {
Copy link
Contributor

@Fishrock123 Fishrock123 Dec 13, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should consider using a regular function here, as we make no guarentees that apply() or call() may not be called on this internally in the future.

(Assigning arrow functions as prototype functions is generally bad practice because those do not work.)

@mcollina
Copy link
Member

mcollina commented Dec 14, 2016

bufferedRequestCount is incremented when a write is in progress, or if the stream is corked:

if (state.writing || state.corked) {
var last = state.lastBufferedRequest;
state.lastBufferedRequest = new WriteReq(chunk, encoding, cb);
if (last) {
last.next = state.lastBufferedRequest;
} else {
state.bufferedRequest = state.lastBufferedRequest;
}
state.bufferedRequestCount += 1;
.

You should issue multiple writes synchronously after cork(), check bufferedRequestCount and then uncork().

Note that bufferedRequestCount makes most sense if _writev is implemented, see

var l = state.bufferedRequestCount;
. You should probably double the checks, one for a stream just with _write, and one with a stream with _writev.

@Trott
Copy link
Member

Trott commented Dec 21, 2016

Ping @captainsafia! Still working on this? (No rush; I'm just making sure it's not stalled.)

@captainsafia
Copy link
Contributor Author

Sorry for staying delayed on this. I'd love to see this own through but I think it is a tad bit above my pay grade at the moment so I'll close it and give someone else the opportunity to tackle it with some of the insights provided above.

@mcollina
Copy link
Member

@captainsafia may I build upon your commit?

@captainsafia
Copy link
Contributor Author

@mcollina: Sure! I've added you as a collaborator on my fork.

@mcollina
Copy link
Member

mcollina commented Jan 2, 2017

@captainsafia I force pushed this. Let me know if you are ok with the content.

This checks to see that clearBuffer appropriately decrements the
correct values in _writableState when clearBuffer is invoked in
end.

Fixes: nodejs#8687
PR-URL: nodejs#9922
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
@mcollina
Copy link
Member

mcollina commented Jan 2, 2017

@italoacasas should be addressed.

@italoacasas
Copy link
Contributor

@Trott
Copy link
Member

Trott commented Jan 2, 2017

CI failures on AIX and FreeBSD seem unrelated. I just terminated some stalled tests on those machines--probably a previous test run had a bug that caused cluster tests to hang and not free ports, causing subsequent runs like this one to also fail.

Re-running CI: https://ci.nodejs.org/job/node-test-pull-request/5665/

@italoacasas
Copy link
Contributor

Landed 275362a

@italoacasas italoacasas closed this Jan 3, 2017
@captainsafia
Copy link
Contributor Author

Thanks for getting this through the finish line, everyone! ❤️

evanlucas pushed a commit that referenced this pull request Jan 4, 2017
This checks to see that clearBuffer appropriately decrements the
correct values in _writableState when clearBuffer is invoked in
end.

Fixes: #8687
PR-URL: #9922
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Italo A. Casas <me@italoacasas.com>
MylesBorins pushed a commit that referenced this pull request Jan 23, 2017
This checks to see that clearBuffer appropriately decrements the
correct values in _writableState when clearBuffer is invoked in
end.

Fixes: #8687
PR-URL: #9922
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Italo A. Casas <me@italoacasas.com>
MylesBorins pushed a commit that referenced this pull request Jan 23, 2017
This checks to see that clearBuffer appropriately decrements the
correct values in _writableState when clearBuffer is invoked in
end.

Fixes: #8687
PR-URL: #9922
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Italo A. Casas <me@italoacasas.com>
MylesBorins pushed a commit that referenced this pull request Jan 23, 2017
This checks to see that clearBuffer appropriately decrements the
correct values in _writableState when clearBuffer is invoked in
end.

Fixes: #8687
PR-URL: #9922
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Italo A. Casas <me@italoacasas.com>
MylesBorins pushed a commit that referenced this pull request Jan 24, 2017
This checks to see that clearBuffer appropriately decrements the
correct values in _writableState when clearBuffer is invoked in
end.

Fixes: #8687
PR-URL: #9922
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Italo A. Casas <me@italoacasas.com>
MylesBorins pushed a commit that referenced this pull request Jan 24, 2017
This checks to see that clearBuffer appropriately decrements the
correct values in _writableState when clearBuffer is invoked in
end.

Fixes: #8687
PR-URL: #9922
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Italo A. Casas <me@italoacasas.com>
This was referenced Jan 24, 2017
MylesBorins pushed a commit that referenced this pull request Jan 31, 2017
This checks to see that clearBuffer appropriately decrements the
correct values in _writableState when clearBuffer is invoked in
end.

Fixes: #8687
PR-URL: #9922
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Italo A. Casas <me@italoacasas.com>
MylesBorins pushed a commit that referenced this pull request Feb 1, 2017
This checks to see that clearBuffer appropriately decrements the
correct values in _writableState when clearBuffer is invoked in
end.

Fixes: #8687
PR-URL: #9922
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Italo A. Casas <me@italoacasas.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
code-and-learn Issues related to the Code-and-Learn events and PRs submitted during the events. stream Issues and PRs related to the stream subsystem. test Issues and PRs related to the tests.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

stream, test: Add test for _writableState clearBuffer state machine
10 participants