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

Http compression integration tests; combatibility with Netty #1239

Merged
merged 2 commits into from
Dec 10, 2020

Conversation

tkountis
Copy link
Contributor

@tkountis tkountis commented Dec 4, 2020

Motivation:
Add integration tests between Netty & ServiceTalk with compression

Modifications:
Modified current compression tests to allow extending them for other server/client flavors.

Result:
Happy path scenarios with enabled compression is now tested both for ST/ST & ST/Netty

Copy link
Member

@idelpivnitskiy idelpivnitskiy left a comment

Choose a reason for hiding this comment

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

LGTM after comments addressed

}
}

protected enum Client {
Copy link
Member

Choose a reason for hiding this comment

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

Client and Server enums are identical. Can we rename it to the generic name and reuse?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Used different names to make the whenread better in English.
"when(H1, Server.DEFAULT, Client.DEFAULT, Request.ID, SHOULD_PASS)"

}
}

protected enum Protocol {
Copy link
Member

Choose a reason for hiding this comment

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

Consider reusing HttpProtocol enum we have for tests

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Made it public to access it, it was in different pkg.

Copy link
Member

Choose a reason for hiding this comment

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

Hm, why do you use http.api package here. This is http-netty module, we should use http.netty package for tests.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

IIRC the 'encodingFor' is part of api and pkg private.

Copy link
Member

Choose a reason for hiding this comment

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

Consider creating a hook specifically for that method and keep everything else in http.netty


protected enum Expectation {
SHOULD_PASS(true),
SHOULD_FAIL(false);
Copy link
Member

Choose a reason for hiding this comment

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

If we do not expect more cases consider using boolean. Otherwise, let's kill the SHOULD_ prefix.

}
}

protected enum Request {
Copy link
Member

Choose a reason for hiding this comment

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

Consider naming it Compression or Coding


public BaseContentCodingTest(final Scenario scenario) {
this.scenario = scenario;
this.expectedSuccess = scenario.valid;
Copy link
Member

Choose a reason for hiding this comment

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

Consider using scenario.valid instead of duplicating in a new variable

public String toString() {
return "When a client that supports " + encString(clientSupported) + ", sends a request encoded with "
+ requestEncoding.name() + ", to an " + (isH2 ? "H2" : "H1") + " server that supports "
+ encString(serverSupported) + ", the request should be " + (valid ? "ACCEPTED" : "REJECTED");
Copy link
Member

Choose a reason for hiding this comment

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

Consider simplified parametrized format:

client=[...], server=[...], request={}, protocol={}, shouldPass={}

Current format is hard to read in intellij idea and hard to run via command line a specific gradle test.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Included index in the params (to allow running from cmd easier [1]), and simplified the text.

  1. ./gradlew --info :servicetalk-http-netty:test --tests "io.servicetalk.http.netty.ServiceTalkContentCodingTest.testCompatibility[15*]"

.collect(StringBuilder::new, StringBuilder::append)
.toFuture().get().toString();

assertEquals(payloadAsString((byte) 'a'), requestPayload);
Copy link
Member

Choose a reason for hiding this comment

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

Assertions work only in main test thread. If you use assertion in offloaded thread or on a server side, they won't fail the test.
We usually use a BlockingQueue to save the result we observed on the server side and validate the values in the queue in the main test thread.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Discussed offline, the errors are surfaced with the assertion of expected successful response + printed stack trace.
However, changing the logic to capture the error and re-throw under main, to help with readability.

}
}

assertEquals(expected, encodingFor(client, response.headers()
Copy link
Member

Choose a reason for hiding this comment

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

Similar logic here. If you verify in the filter, it can be executed in offloaded thread. You need to verify results on the caller side. Read the response via client API.

assertResponse(client().request(client()
.get("/")
.encoding(encoding)
.payloadBody(payloadAsString((byte) 'a'), textSerializer())).toFuture().get().toStreamingResponse());
Copy link
Member

Choose a reason for hiding this comment

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

Consider using BlockingHttpClient by default


ChannelFuture f = ctx.write(response);

if (!keepAlive) {
Copy link
Member

Choose a reason for hiding this comment

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

For the purpose of the test, you don't need keep-alive logic. Just leave the connection open (@After will shutdown everything) or always close it, doesn't matter.

@tkountis tkountis force-pushed the impr/http-compr-compatibility branch from e4d7fb6 to 0a926ce Compare December 9, 2020 21:27
@tkountis tkountis merged commit b98aa8d into apple:main Dec 10, 2020
@tkountis tkountis deleted the impr/http-compr-compatibility branch December 10, 2020 10:13
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.

2 participants