Skip to content

Conversation

@lauzadis
Copy link
Member

@lauzadis lauzadis commented Jun 1, 2023

Issue #, if available:
N/A

Description of changes:
This PR replaces our usage of httpbin.org with a mock server. httpbin.org can be flaky at times and causes tests to fail occasionally.

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@lauzadis lauzadis added the no-changelog Indicates that a changelog entry isn't required for a pull request. Use sparingly. label Jun 1, 2023
@lauzadis lauzadis marked this pull request as ready for review June 1, 2023 21:47
@lauzadis lauzadis requested a review from a team as a code owner June 1, 2023 21:47
Copy link
Contributor

@ianbotsf ianbotsf left a comment

Choose a reason for hiding this comment

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

Minor nits, fix and ship (unless you feel like hunting down a KMP mock server).

Comment on lines 119 to 120
val response = roundTrip(url = "$url/anything", verb = "PUT", body = bodyToSend)
mockServer.clear(expectedRequest)
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: The mockServer.clear call should be in a finally block.

Comment on lines 109 to 113
dependencies {
implementation(kotlin("test-common"))
implementation(kotlin("test-annotations-common"))
implementation("org.mock-server:mockserver-netty:$mockServerVersion")
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: Discussed offline, MockServer belongs in jvmTest since it's not a KMP client.

Copy link
Contributor

Choose a reason for hiding this comment

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

Correct that this dependency is jvm only. If we add this we basically have to move the tests to jvmTest as well and we won't be able to have common test suite anymore. This is ok for right now but eventually we'll be wiring up a kotlin/native version as well.

Copy link
Member Author

Choose a reason for hiding this comment

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

I relocated them for now, we can discuss if that's the best thing long-term

"This is a sample to prove that http downloads and uploads work. It doesn't really matter what's in here, we mainly just need to verify the downloads and uploads work."
private val TEST_DOC_SHA256 = "c7fdb5314b9742467b16bd5ea2f8012190b5e2c44a005f7984f89aab58219534"

val port = 60108
Copy link
Contributor

Choose a reason for hiding this comment

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

suggestion: Is there not a way to get a random open port rather than hard coding? Similar to how we do it in smithy-kotlin http test suite?

Copy link
Member Author

Choose a reason for hiding this comment

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

There is a way, by setting the port to 0

Comment on lines 109 to 113
dependencies {
implementation(kotlin("test-common"))
implementation(kotlin("test-annotations-common"))
implementation("org.mock-server:mockserver-netty:$mockServerVersion")
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Correct that this dependency is jvm only. If we add this we basically have to move the tests to jvmTest as well and we won't be able to have common test suite anymore. This is ok for right now but eventually we'll be wiring up a kotlin/native version as well.

Copy link
Contributor

@ianbotsf ianbotsf left a comment

Choose a reason for hiding this comment

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

One final minor nit, fix and ship!

Comment on lines 26 to 33
var mockServer: MockServerClient = MockServerClient("localhost", 0)
var url = "http://localhost:"

@BeforeAll
fun setup() {
mockServer = ClientAndServer.startClientAndServer(0)
url += mockServer.port
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: Why set mockServer and url in field initializers and then re-set them in setup? Seems like a perfect case for lateinit:

lateinit var mockServer: MockServerClient
lateinit var url: String

@BeforeAll
fun setup() {
    mockServer = ClientAndServer.startClientAndServer(0)
    url = "http://localhost:${mockServer.port}"
}

@sonarqubecloud
Copy link

sonarqubecloud bot commented Jun 2, 2023

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 1 Code Smell

No Coverage information No Coverage information
0.0% 0.0% Duplication

@lauzadis lauzadis merged commit c93e78a into main Jun 2, 2023
@lauzadis lauzadis deleted the misc-remove-httpbin-dependency branch June 2, 2023 19:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

no-changelog Indicates that a changelog entry isn't required for a pull request. Use sparingly.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants