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

#2933. Add tests for Stream.error and Stream.value constructors. #2934

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

sgrekhov
Copy link
Contributor

No description provided.

Copy link
Member

@eernstg eernstg left a comment

Choose a reason for hiding this comment

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

LGTM.

@lrhn, it would be great if you could take a look as well.

/// This stream emits a single error event of `error` and `stackTrace` and then
/// completes with a done event.
///
/// @description Checks that if `stackTrace` is specified.
Copy link
Member

Choose a reason for hiding this comment

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

Perhaps?:

Suggested change
/// @description Checks that if `stackTrace` is specified.
/// @description Checks that if `stackTrace` is specified it is provided
/// if and when a `catch` clause is executed to catch the error.

Copy link
Member

Choose a reason for hiding this comment

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

My normal phrasing is that "provided" is used for being given as an argument, and I'd use "available in"/"part of" the emitted event to describe where it comes out again.

/// This stream emits a single error event of `error` and `stackTrace` and then
/// completes with a done event.
///
/// @description Checks that `Stream.error()` constructor creates a stream which
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
/// @description Checks that `Stream.error()` constructor creates a stream which
/// @description Checks that the `Stream.error()` constructor creates a stream which

/// This stream emits a single data event of value and then closes with a done
/// event.
///
/// @description Checks that `Stream.value()` constructor creates a stream which
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
/// @description Checks that `Stream.value()` constructor creates a stream which
/// @description Checks that the `Stream.value()` constructor creates a stream which

/// This stream emits a single data event of value and then closes with a done
/// event.
///
/// @description Checks that `Stream.value()` constructor creates a stream which
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
/// @description Checks that `Stream.value()` constructor creates a stream which
/// @description Checks that the `Stream.value()` constructor creates a stream which

asyncStart();
Stream stream = Stream.value("Stream.value");
stream.listen((v) {
Expect.equals("Stream.value", v);
Copy link
Member

Choose a reason for hiding this comment

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

Perhaps add a side effect (++counter) and check it in onDone, in order to see that the data event does get posted?

Yes, it does look like LibTest/async/Stream/Stream.value_A01_t01.dart will test this already, but it seems reasonable to check it here as well, because it's non-trivial to see when looking at this test that there is another test which is indeed testing that behavior.

Copy link
Member

Choose a reason for hiding this comment

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

(Also, if behavior differs depending on whether you provide an onDone handler, the two tests might not agree.)

@eernstg eernstg requested a review from lrhn October 14, 2024 15:48
/// This stream emits a single error event of `error` and `stackTrace` and then
/// completes with a done event.
///
/// @description Checks that if `stackTrace` is specified.
Copy link
Member

Choose a reason for hiding this comment

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

My normal phrasing is that "provided" is used for being given as an argument, and I'd use "available in"/"part of" the emitted event to describe where it comes out again.

var v = await stream.first;
Expect.fail("Unexpected event $v");
} catch (e, st) {
Expect.equals(stackTrace, st);
Copy link
Member

Choose a reason for hiding this comment

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

Can't assume that stack traces preserve identity.
I'd do Expect.equals("My StackTrace", st.toString());.

(It's probably preserved here, but it isn't necessarily by Error.throwWithStackTrace because that goes through the platform throw. And we don't promise to not use Error.throwWithStackTrace internally in Stream.error.)

stream.listen((v) {
Expect.fail("Unexpected event $v");
}, onError: (e) {
Expect.equals("Stream.error", e);
Copy link
Member

Choose a reason for hiding this comment

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

Could count onError invocations here, to check that it's not called twice.

var onErrors = 0;
...
  onError: (e) {
    onErrors++;
    ...
  }, onDone: () {
    Expect.equals(onErrors, 1);
    ...
  });

asyncStart();
Stream stream = Stream.value("Stream.value");
stream.listen((v) {
Expect.equals("Stream.value", v);
Copy link
Member

Choose a reason for hiding this comment

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

(Also, if behavior differs depending on whether you provide an onDone handler, the two tests might not agree.)

@sgrekhov
Copy link
Contributor Author

Thank you! Updated. PTAL.

@sgrekhov sgrekhov requested review from lrhn and eernstg October 15, 2024 14:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants