Skip to content

Async Generator flow control tests #871

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

Merged
merged 1 commit into from
Mar 6, 2017

Conversation

caitp
Copy link
Contributor

@caitp caitp commented Feb 26, 2017

Here's a starter suite of tests for basic flow control in Async Generators.

This relates primarily to the behaviour of AsyncGeneratorResumeNext, AsyncGeneratorStart, AsyncGeneratorResolve and AsyncGeneratorReject, as well as some coverage of changes to GeneratorYield.

There is stuff missing, as I haven't exhaustively written tests for all of the variations that are necessary.

@caitp caitp force-pushed the AsyncGeneratorFlow branch from 82683c1 to 8bdcd58 Compare February 26, 2017 20:13
@caitp
Copy link
Contributor Author

caitp commented Feb 28, 2017

Ping, it would be great to get a look at these and start filling in holes in coverage here

@leobalter
Copy link
Member

Hi, @caitp! I'm back to the regular work time on test262, although, there are other older PR I've had to look before this one.

I'll review this one first thing tomorrow.

Can you confirm if you're planning to add more tests in this PR or this is the current work that we should land and expect/start a follow PR for coverage completion?

@caitp
Copy link
Contributor Author

caitp commented Mar 1, 2017

well, if I come up with more tests, they'll be either in this PR or a followup. I don't think there's any problem with incrementally landing more coverage.

@leobalter
Copy link
Member

It's not a problem, for sure. I just want to make the best time strategy for reviews and I really appreciate the work.

@leobalter leobalter self-assigned this Mar 2, 2017
Copy link
Member

@leobalter leobalter left a comment

Choose a reason for hiding this comment

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

There's a few nit picks, some related to formatting. It is looking great so far.

---*/

var g = async function*() {
$ERROR('Generator must not be resumed.');
Copy link
Member

Choose a reason for hiding this comment

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

we can replace $ERROR with throw new Test262Error('....

It should not block this PR, but it's a +1 if we can use the current conventional form.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

/*---
author: Caitlin Potter <[email protected]>
esid: pending
description: >
Copy link
Member

Choose a reason for hiding this comment

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

in every file, the description tags are in a good shape for the info tag. We still miss a short description for each case.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm open to suggestions on better description text, but otherwise I'm leaving these as-is, and the web runner can just deal with it

// Generator is closed
it.next().then(function(ret) {
assert.sameValue(ret.value, undefined);
assert.sameValue(ret.done, true);
Copy link
Member

Choose a reason for hiding this comment

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

Interesting! You assert the iteration is done on line 22, but for this is still fine to assert the generator is really closed and won't resume. I like this.

+1


it.return('sent-value').then($DONE, function(err) {
// Throw in finally block
assert(err instanceof Err);
Copy link
Member

Choose a reason for hiding this comment

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

if you store the reference for new Error you can throw it in the finally block and assert err is the same reference, right?

It also saves the need for an Error subclass


}).catch($DONE);

}).catch($DONE);
Copy link
Member

Choose a reason for hiding this comment

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

I wish we could have Promise#finally already

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't think it would help with the nested Promises

Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a specific reason these are nested instead of chained anyway?

it.next()
.then(function(ret) {
  assert.sameValue(ret.value, 1, 'Initial yield');
  assert.sameValue(ret.done, false, 'Initial yield');

  return it.return('sent-value');
})
.then(function(ret) {
  assert.sameValue(ret.value, 2, 'Yield in finally block');
  assert.sameValue(ret.done, false, 'Yield in finally block');

  return it.next();
})
.then(function(ret) {
  assert.sameValue(ret.value, 'sent-value', 'AsyncGeneratorResolve(generator, resultValue, true)');
  assert.sameValue(ret.done, true, 'AsyncGeneratorResolve(generator, resultValue, true)');

  return it.next();
})
.then(function(ret) {
  assert.sameValue(ret.value, undefined, 'Generator is closed');
  assert.sameValue(ret.done, true, 'Generator is closed');
})
.then($DONE, $DONE);

Copy link
Contributor Author

@caitp caitp Mar 3, 2017

Choose a reason for hiding this comment

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

(returning a Promise and chaining is) harder to read, less obvious, etc

Copy link
Contributor

@gnarf gnarf Mar 6, 2017

Choose a reason for hiding this comment

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

I very much disagree, 4 level nested callbacks are much less readable than chaining promises, but I also don't care enough to block, it seems you've reached "annoyed" point on this PR (been there myself, sorry if I'm projecting) and I don't want to add to it any more. Thanks for the contribution!

assert.sameValue(ret.value, 1);
assert.sameValue(ret.done, false);

it.throw(new Err).then(function(ret) {
Copy link
Member

Choose a reason for hiding this comment

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

this is the same case I mentioned above for storing an instance of new Error.

it.next().then(function(ret) {
// Initial yield
assert.sameValue(ret.value, 1);
assert.sameValue(ret.done, false);
Copy link
Member

Choose a reason for hiding this comment

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

the comments are great to track the steps. If you don't mind, can you move them to become assertion messages?

This way we can have a powerful track of each assertion and, better, tells the implementors where each test is failing at.

Example for the case above:

assert.sameValue(ret.value, 1, 'Initial yield');
assert.sameValue(ret.done, false, 'Initial yield');

Even if they are the same message, I can already identify each one due to the respective expected values.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've done this --- but it gets complicated for the generator-closing operations. I've gone with using the spec step which leads to the promise capability resolve/reject call instead there, but that seems awkward too.

@leobalter
Copy link
Member

To avoid noises, I left some suggestions that can be applied to multiple places, but in a single comment as an example.

Some cases are:

  1. Moving inline comments to assertion messages.
  2. throwing the error reference to check for the sameValue instead of err instanceof Err, avoiding the Error subclass
  3. splitting the current frontmatter description content into description and info

etc.

Thank you for the tests, @caitp! I'm looking forward the next review round!

@caitp caitp force-pushed the AsyncGeneratorFlow branch from 8bdcd58 to 79baf2b Compare March 3, 2017 18:28
@tcare
Copy link
Member

tcare commented Mar 3, 2017

Could you please keep spec text in an "info:" section and use "description:" as a short description of why the individual test is interesting?

@leobalter
Copy link
Member

Thanks for the updates, @caitp.

As @tcare mentioned, the short description is something we need to keep the conventional conformance and a good point for a short reasoning on each test.

@caitp
Copy link
Contributor Author

caitp commented Mar 3, 2017

The description lines are influenced by existing tests in the repository, which include spec citations. I would appreciate specific suggestions for individual tests.

For example (test/language/expressions/arrow-function/syntax/arrowparameters-binding-identifier-eval.js):

// Copyright (C) 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 14.2.1
description: >
    ArrowParameters[Yield] :
      BindingIdentifier[?Yield]
      ...
    
    Parameter named "eval", non-strict

flags: [noStrict]
---*/
var af = eval => eval;


assert.sameValue(typeof af, "function");
assert.sameValue(af(1), 1);

@tcare
Copy link
Member

tcare commented Mar 3, 2017

Updating all the tests is preventatively expensive. Another example is the es6id there, which is now superseded by esid. We do drive-by cleanup and all new tests coming in should conform to the current standard.

@caitp
Copy link
Contributor Author

caitp commented Mar 4, 2017

I'm happy to change the frontmatter to anything requested (within reason), but please be specific about those requests.

@tcare
Copy link
Member

tcare commented Mar 4, 2017

Sorry for the confusion.

A random example: https://github.com/tc39/test262/blob/82c2ca070976329e822a466e2d6bafa88b87bc4d/test/intl402/PluralRules/prototype/select/tainting.js

Generally, "info:" can be used to dump spec text, and "description:" is for the brief description of what the test is trying to achieve or why it is interesting. We try to avoid having spec text in "description:" so that it can be used as a quick reference.

The descriptions from your previous commit 098f9ca are fine. Relevant spec text sections can be put into "info:".

@leobalter
Copy link
Member

@caitp You've done a lot of great work here, and I really appreciate your contribution.

I will follow up with a new PR to address the remaining nit picky formatting things, mostly providing the frontmatter descriptions. Hopefully you may help me reviewing the new changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants