Skip to content

uploading more bytes into a body after having said the body is fully uploaded doesn't fail #252

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

Closed
weissi opened this issue Jun 13, 2020 · 0 comments · Fixed by #270
Closed
Assignees
Labels
kind/bug Feature doesn't work as expected.
Milestone

Comments

@weissi
Copy link
Contributor

weissi commented Jun 13, 2020

Here a test that shows the issue (currently gets stuck because of #250 the server just never replies)

    func testBodyUploadAfterEndFails() {
        let url = self.defaultHTTPBinURLPrefix + "/post"

        func uploader(_ streamWriter: HTTPClient.Body.StreamWriter) -> EventLoopFuture<Void> {
            let done = streamWriter.write(.byteBuffer(ByteBuffer(string: "X")))
            done.recover { error -> Void in
                XCTFail("unexpected error \(error)")
            }.whenSuccess {
                // This is executed when we have already sent the end of the request.
                done.eventLoop.execute {
                    streamWriter.write(.byteBuffer(ByteBuffer(string: "BAD BAD BAD"))).whenComplete { result in
                        switch result {
                        case .success:
                            XCTFail("we succeeded writing bytes after the end!?")
                        case .failure(let error):
                            XCTFail("\(error)")
                        }

                    }
                }
            }
            return done
        }

        XCTAssertThrowsError(
            try self.defaultClient.execute(request:
                                            Request(url: url,
                                                    body: .stream(length: 1, uploader))).wait()) { error in
            // TODO: check that the request fails with the appropriate error (or decide that that's okay)
        }

        // Quickly try another request and check that it works. If we by accident wrote some extra bytes into the
        // stream (and reuse the connection) that could cause problems.
        XCTAssertNoThrow(try self.defaultClient.get(url: self.defaultHTTPBinURLPrefix + "/get").wait())
    }

I can probably be convinced that this is programmer error and we'd just preconditionFailure. I don't know, we definitely need to do something (and test that behaviour).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug Feature doesn't work as expected.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants