Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

fix: Unhandled promise rejection in tests #95

Closed
wants to merge 1 commit into from
Closed

fix: Unhandled promise rejection in tests #95

wants to merge 1 commit into from

Conversation

helio-frota
Copy link
Contributor

@helio-frota helio-frota commented Apr 29, 2020

No description provided.

Copy link
Member

@lance lance left a comment

Choose a reason for hiding this comment

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

Can you look into what the actual value is and determine if the test is failing and that's what's causing this error?

expect(err.message).to.equal("invalid payload");
})
.catch((err) => {
console.error(err);
Copy link
Member

Choose a reason for hiding this comment

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

I think this should fail the test. If the message is not correct, it will throw. This seems to indicate that there's something wrong with the test itself. It's failing but not registering as a failure.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

PR updated, please take a look when you have a time. 👍

@fabiojose
Copy link
Contributor

@helio-frota have you take a look at @lance's requested changes?

@helio-frota
Copy link
Contributor Author

@fabiojose yeah I still need to understand the issue. I agree with @lance that probably the test has something wrong.

But in other hand that test will be removed since it is related to spec 0.3
depending on #99

it("Throw error when the event does not follow the spec 0.3", () => {

This PR is just to remove the Node warning:

UnhandledPromiseRejectionWarning: AssertionError: expected 'failed' to equal 'invalid payload'

When we deal with another catch block, we can see clearly the result:

{
  message: "expected 'failed' to equal 'invalid payload'",
  showDiff: true,
  actual: 'failed',
  expected: 'invalid payload'
}

I think it is better to close this PR and wait for that warning message to be removed without a discarded effort. 😃

Please, let me know what do you think 👍

@lance
Copy link
Member

lance commented May 4, 2020

@helio-frota I did some experimenting with this over the weekend. These tests are particularly problematic in a way that the 1.0 version of the tests is not, because the 0.3 unmarshalling is async. Any of the unmarshalling tests for 0.3 will exhibit this same behavior. When the call to expect() fails, Chai throws an exception. But since this is happening asynchronously, it's not caught by the test framework and won't be registered as a failure. I think to effectively test this, something like Chai As Promised would need to be used.

I think we need to determine whether 0.3 is going to be removed. If not, we need to fix this for all of the 0.3 unmarshaling tests. If 0.3 goes away, then this problem magically disappears on master but I still think it should be fixed on the v1.x-backport branch.

@helio-frota
Copy link
Contributor Author

@lance yeah, I agree with that, I'm favor to wait for #110 decision.
I'm going to keep the PR open for about 72 hours, then revisit and see what can be done (if nobody does it before -- which will be good if that happen of course)

Sound good ?

@helio-frota
Copy link
Contributor Author

helio-frota commented May 4, 2020

Seems good now and able to be merged 👍
@fabiojose @lance

@helio-frota helio-frota requested a review from lance May 5, 2020 10:57
.catch((err) =>
expect(err.message).to.equal("invalid payload"));
try {
await un.unmarshall(payload, headers);
Copy link
Member

Choose a reason for hiding this comment

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

@helio-frota you should fail the test after this line. The expectation is that the unmarshalling should throw if the incoming message does not conform to spec. As the test is now, that isn't happening. We never enter the catch block below. You can change that .to.equal() call to be .to.equal('tacos') and the test still passes.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OOps you right! I was only focused on solve the unhandled promise exception.
Thanks for the review, commit updated.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It still not good btw..
I'm trying to understand what is happening...

@helio-frota helio-frota requested a review from lance May 5, 2020 14:37
Signed-off-by: Helio Frota <00hf11@gmail.com>
@helio-frota
Copy link
Contributor Author

Ok I found that spec.check(payload) was never called.
I think it is good for this PR which initially was addressing the unhandled promise warning.

If the spec.check() is not being called on the right place and/or other thing. Then in this case it will be good to create a new issue to fix that. (or to discard that in case v0.3 removal)

@lance
Copy link
Member

lance commented May 5, 2020

@helio-frota as we keep nibbling around the edges of what is a bigger problem, I'm starting to think that the right move here is to modify the 0.3 unmarshaling API so that it's no longer asynchronous and matches the API exposed for the 1.0 protocol. There is no reason that this API should be async.

Maybe the best plan of attack is to open a new PR that addresses that. WDYT?

@helio-frota
Copy link
Contributor Author

@lance I agree with that. (Not saying that I'm going to send a PR soon afterwards 😄 )
Also not sure if I'm currently able to do that size of refactor on this repo.

But anyway related to this specific issue I think we are good, the spec.check() was not executed and that was causing the issue related to the expect. And the unhandled promise warning is another issue.

lance added a commit to lance/sdk-javascript that referenced this pull request May 5, 2020
This commit removes the unnecessary use of Promises in the 0.3 unmarshaller.
There was actually no asynchronous activity happening in that function, so
there was no need to deal with Promises, and as a result testing was made
much more difficult.

Fixes: cloudevents#95

Signed-off-by: Lance Ball <lball@redhat.com>
@lance
Copy link
Member

lance commented May 5, 2020

Closing - superseded by #126

@lance lance closed this May 5, 2020
lance added a commit that referenced this pull request May 7, 2020
This commit removes the unnecessary use of Promises in the 0.3 unmarshaller.
There was actually no asynchronous activity happening in that function, so
there was no need to deal with Promises, and as a result testing was made
much more difficult.

Fixes: #95

Signed-off-by: Lance Ball <lball@redhat.com>
@helio-frota helio-frota deleted the test-fix branch May 7, 2020 11:04
@helio-frota helio-frota self-assigned this May 12, 2020
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants