mirror of
https://github.com/square/okhttp.git
synced 2026-01-12 10:23:16 +03:00
Fix some failing tests that CI hasn't been running (#9179)
Thankfully there's nothing here that indicates we've shipped a bug to our users. Co-authored-by: Jesse Wilson <jwilson@squareup.com>
This commit is contained in:
@@ -60,6 +60,7 @@ class WebSocketReader(
|
||||
private val noContextTakeover: Boolean,
|
||||
) : Closeable {
|
||||
private var closed = false
|
||||
private var receivedCloseFrame = false
|
||||
|
||||
// Stateful data about the current frame.
|
||||
private var opcode = 0
|
||||
@@ -105,6 +106,8 @@ class WebSocketReader(
|
||||
*/
|
||||
@Throws(IOException::class)
|
||||
fun processNextFrame() {
|
||||
check(!closed) { "closed" }
|
||||
|
||||
readHeader()
|
||||
if (isControlFrame) {
|
||||
readControlFrame()
|
||||
@@ -115,7 +118,7 @@ class WebSocketReader(
|
||||
|
||||
@Throws(IOException::class, ProtocolException::class)
|
||||
private fun readHeader() {
|
||||
if (closed) throw IOException("closed")
|
||||
if (receivedCloseFrame) throw IOException("closed")
|
||||
|
||||
// Disable the timeout to read the first byte of a new frame.
|
||||
val b0: Int
|
||||
@@ -228,7 +231,7 @@ class WebSocketReader(
|
||||
if (codeExceptionMessage != null) throw ProtocolException(codeExceptionMessage)
|
||||
}
|
||||
frameCallback.onReadClose(code, reason)
|
||||
closed = true
|
||||
receivedCloseFrame = true
|
||||
}
|
||||
else -> {
|
||||
throw ProtocolException("Unknown control opcode: " + opcode.toHexString())
|
||||
@@ -262,7 +265,7 @@ class WebSocketReader(
|
||||
/** Read headers and process any control frames until we reach a non-control frame. */
|
||||
@Throws(IOException::class)
|
||||
private fun readUntilNonControlFrame() {
|
||||
while (!closed) {
|
||||
while (!receivedCloseFrame) {
|
||||
readHeader()
|
||||
if (!isControlFrame) {
|
||||
break
|
||||
@@ -279,7 +282,7 @@ class WebSocketReader(
|
||||
@Throws(IOException::class)
|
||||
private fun readMessage() {
|
||||
while (true) {
|
||||
if (closed) throw IOException("closed")
|
||||
if (receivedCloseFrame) throw IOException("closed")
|
||||
|
||||
if (frameLength > 0L) {
|
||||
source.readFully(messageFrameBuffer, frameLength)
|
||||
@@ -303,6 +306,8 @@ class WebSocketReader(
|
||||
|
||||
@Throws(IOException::class)
|
||||
override fun close() {
|
||||
if (closed) return
|
||||
closed = true
|
||||
messageInflater?.closeQuietly()
|
||||
source.closeQuietly()
|
||||
}
|
||||
|
||||
@@ -640,10 +640,7 @@ class InterceptorTest {
|
||||
call.enqueue(callback)
|
||||
val recordedResponse = callback.await(server.url("/"))
|
||||
assertThat(recordedResponse.failure, "canceled due to java.lang.RuntimeException: boom!")
|
||||
recordedResponse.failure!!.assertSuppressed { throwables: List<Throwable>? ->
|
||||
assertThat(throwables!!).contains(boom)
|
||||
Unit
|
||||
}
|
||||
assertThat(recordedResponse.failure?.cause).isEqualTo(boom)
|
||||
assertThat(call.isCanceled()).isTrue()
|
||||
assertThat(executor.takeException()).isEqualTo(boom)
|
||||
}
|
||||
|
||||
@@ -38,6 +38,7 @@ import kotlin.test.assertFailsWith
|
||||
import mockwebserver3.MockResponse
|
||||
import mockwebserver3.MockWebServer
|
||||
import mockwebserver3.junit5.StartStop
|
||||
import okhttp3.CallEvent.CallFailed
|
||||
import okhttp3.CallEvent.CallStart
|
||||
import okhttp3.CallEvent.ConnectStart
|
||||
import okhttp3.CallEvent.DnsEnd
|
||||
@@ -363,7 +364,7 @@ class ClientAuthTest {
|
||||
ConnectStart::class,
|
||||
SecureConnectStart::class,
|
||||
)
|
||||
assertThat(recordedEventTypes).endsWith("CallFailed")
|
||||
assertThat(recordedEventTypes).endsWith(CallFailed::class)
|
||||
}
|
||||
|
||||
private fun buildClient(
|
||||
|
||||
@@ -437,7 +437,7 @@ class WebSocketReaderTest {
|
||||
callback.assertTextMessage("Hello")
|
||||
data.write("c107f248cdc9c90700".decodeHex()) // Hello
|
||||
clientReaderWithCompression.close()
|
||||
assertFailsWith<Exception> {
|
||||
assertFailsWith<IllegalStateException> {
|
||||
clientReaderWithCompression.processNextFrame()
|
||||
}.also { expected ->
|
||||
assertThat(expected.message!!).contains("closed")
|
||||
|
||||
Reference in New Issue
Block a user