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

Add TransformStream tests for re-entrant strategies #795

Merged
merged 3 commits into from Sep 15, 2017

Conversation

ricea
Copy link
Collaborator

@ricea ricea commented Sep 11, 2017

Add tests to ensure that implementations of TransformStream behave correctly
when operations are triggered from within the readableStrategy.size function.

This is not really a "supported" use case as any code that does this is either
malicious or broken, but implementations need to avoid crashes or memory
corruption in these cases.

Also merge changes to recording-streams.js from web-platform-tests that are
required to make these tests work.

Add tests to ensure that implementations of TransformStream behave correctly
when operations are triggered from within the readableStrategy.size function.

This is not really a "supported" use case as any code that does this is either
malicious or broken, but implementations need to avoid crashes or memory
corruption in these cases.

Also merge changes to recording-streams.js from web-platform-tests that are
required to make these tests work.
@ricea ricea force-pushed the transform-stream-reentrant-strategies branch from 168e56c to 4e970b0 Compare September 11, 2017 11:06
});
reader = ts.readable.getReader();
const writer = ts.writable.getWriter();
let writeCalled = false;
Copy link
Member

Choose a reason for hiding this comment

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

how about naming this writeResolved, writeCompleted, etc?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Great, thanks. Done.

}).then(() => {
assert_true(writeCalled);
assert_equals(calls, 1, 'size() should only be called once');
return readPromises[0];
Copy link
Member

Choose a reason for hiding this comment

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

readPromise?

Copy link
Member

Choose a reason for hiding this comment

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

Oh, it's already fixed :)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, Travis found the bug just before you did. Thanks for checking anyway!

@ricea
Copy link
Collaborator Author

ricea commented Sep 13, 2017

It's very tiring to read these tests, so feel free to take your time reviewing them. They're not blocking anything else.

Copy link
Member

@domenic domenic left a comment

Choose a reason for hiding this comment

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

LGTM with a couple questions... still need to think about #794 more though.


// The behaviour in this test may seem strange, but it is logical. The call to controller.close() happens while the
// readable queue is still empty, so the readable transitions to the "closed" state immediately, and the chunk is left
// stranded in the readable's queue.
Copy link
Member

Choose a reason for hiding this comment

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

stranded in the writable's queue, right?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Nope, readable's queue. I've changed from one big comment to commenting the individual steps, which will hopefully make it clearer.

assert_false(done, 'done should be false');
// See https://github.com/whatwg/streams/issues/794 for why this chunk is not 'a'.
assert_equals(value, 'b', 'chunk should have been read');
return writePromise;
Copy link
Member

Choose a reason for hiding this comment

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

Maybe throw in another assert on calls? It doesn't hurt... Same in next test.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done.

Also add some extra checks for the number of times size() is called.
@ricea ricea merged commit 0e90723 into whatwg:master Sep 15, 2017
@ricea ricea deleted the transform-stream-reentrant-strategies branch September 15, 2017 12:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

None yet

3 participants