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

Fix WebSocket subscription tests #27

Merged
merged 2 commits into from
Dec 6, 2021
Merged

Fix WebSocket subscription tests #27

merged 2 commits into from
Dec 6, 2021

Conversation

AlexBlumer
Copy link
Contributor

Fixes #26

The requestId changes are due to PR Vantiq/ag2rs#7934, It removed the field from the subscription's return, presumably because the value is also available in the header X-Request-Id.

Comment on lines +434 to +435
assertThat(msg.get("subscriptionName"), instanceOf(String.class));
assertThat(callback.getMessage().getHeaders().get("X-Request-Id"), instanceOf(String.class));
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This way we don't get an NPE/cast error if the values are wrong. The one test that uses these values now assigns them after the asserts.

Comment on lines 437 to 442
// Sometimes the connection occurs during the validations above. Check for completion only if it's not connected
if (!callback.isConnected()) {
callback.reset();
callback.waitForCompletion();
assertThat("Connected", callback.isConnected(), is(true));
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

If the connection message comes fast enough, it will occur before the reset. The assert here will then fail since reset() clears all the flags used by the test callback class.

Copy link
Contributor

Choose a reason for hiding this comment

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

Might put the assert outside of the IF, just so it is always checked. Makes test clearer to me.

Suggested change
// Sometimes the connection occurs during the validations above. Check for completion only if it's not connected
if (!callback.isConnected()) {
callback.reset();
callback.waitForCompletion();
assertThat("Connected", callback.isConnected(), is(true));
}
// Sometimes the connection occurs during the validations above.
// So wait for completion only if it's not already connected
if (!callback.isConnected()) {
callback.reset();
callback.waitForCompletion();
}
assertThat("Connected", callback.isConnected(), is(true));

Copy link
Contributor

@rblumer4 rblumer4 left a comment

Choose a reason for hiding this comment

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

LGTM.
One nit about waitForCompletion IFs

Comment on lines 437 to 442
// Sometimes the connection occurs during the validations above. Check for completion only if it's not connected
if (!callback.isConnected()) {
callback.reset();
callback.waitForCompletion();
assertThat("Connected", callback.isConnected(), is(true));
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Might put the assert outside of the IF, just so it is always checked. Makes test clearer to me.

Suggested change
// Sometimes the connection occurs during the validations above. Check for completion only if it's not connected
if (!callback.isConnected()) {
callback.reset();
callback.waitForCompletion();
assertThat("Connected", callback.isConnected(), is(true));
}
// Sometimes the connection occurs during the validations above.
// So wait for completion only if it's not already connected
if (!callback.isConnected()) {
callback.reset();
callback.waitForCompletion();
}
assertThat("Connected", callback.isConnected(), is(true));

@AlexBlumer AlexBlumer merged commit ae49030 into master Dec 6, 2021
@AlexBlumer AlexBlumer deleted the ajb-testFix-#26 branch December 6, 2021 21:40
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.

Fix tests for WebSocket subscriptions
2 participants