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

OkHttpClientTestRule check connectionCount instead of idle #5226

Merged
merged 3 commits into from
Jun 26, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,11 @@ class OkHttpClientTestRule : TestRule {
}

fun ensureAllConnectionsReleased() {
val connectionPool = prototype!!.connectionPool
connectionPool.evictAll()
assertThat(connectionPool.idleConnectionCount()).isEqualTo(0)
prototype?.let {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

using let over simple if check because of a mutable field

val connectionPool = it.connectionPool
connectionPool.evictAll()
assertThat(connectionPool.connectionCount()).isEqualTo(0)
}
}

override fun apply(base: Statement, description: Description): Statement {
Expand All @@ -68,12 +70,25 @@ class OkHttpClientTestRule : TestRule {
}

private fun releaseClient() {
prototypes.push(prototype)
prototype = null
prototype?.let {
prototypes.push(it)
prototype = null
}
}
}
}

/**
* Called if a test is known to be leaky.
*/
fun abandonClient() {
prototype?.let {
prototype = null
it.dispatcher.executorService.shutdownNow()
it.connectionPool.evictAll()
}
}

companion object {
/**
* Quick and dirty pool of OkHttpClient instances. Each has its own independent dispatcher and
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ public final class WebSocketHttpTest {
clientListener.assertExhausted();

// TODO: assert all connections are released once leaks are fixed
clientTestRule.abandonClient();
}

@Test public void textMessage() {
Expand Down