Skip to content

Fix bi directional streaming test #405

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

Merged

Conversation

fabianfett
Copy link
Member

Motivation

The HTTPEchoHandler has a property var promises: CircularBuffer<EventLoopPromise<Void>> that is currently accessed without lock from different eventLoops (self.serverGroup and self.defaultClient.eventLoopGroup). This in itself may not be a problem. However testing bi directional streaming should not depend on shared promises. Instead the client should write something to an echo server, wait for the body to be echoed and write some more.

Changes

  • bi directional streaming, writes and reads from an echo server.

Result

No weird shared state in promises between client and server.

@fabianfett fabianfett added the semver/none No version bump required. label Aug 11, 2021
@fabianfett fabianfett added this to the HTTP/2 support milestone Aug 11, 2021
@Lukasa
Copy link
Collaborator

Lukasa commented Aug 12, 2021

FWIW the shared state isn't an issue: NIO's multithreading rules mean there is no data race here.

}

func didSendRequest(task: HTTPClient.Task<Response>) {
XCTAssert(self.eventLoop.inEventLoop)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we remove this assertion? inEventLoop is validly allowed to return false negatives, so we shouldn't assert that it won't. We can add preconditionInEventLoop instead if you want the check.


let sent = ByteBuffer(integer: index)
writer.write(.byteBuffer(sent)).flatMap { () -> EventLoopFuture<ByteBuffer?> in
XCTAssert(delegateEL.inEventLoop, "Always dispatch back to delegate el")
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same note here about false positives.

Copy link
Collaborator

@glbrntt glbrntt left a comment

Choose a reason for hiding this comment

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

Looks good; nothing beyond Cory's comments.

@fabianfett fabianfett force-pushed the ff-fix-bi-directional-streaming-test branch from 8277b0f to 5875377 Compare August 12, 2021 09:17
@fabianfett fabianfett merged commit da5da25 into swift-server:main Aug 12, 2021
@fabianfett fabianfett deleted the ff-fix-bi-directional-streaming-test branch August 12, 2021 10:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
semver/none No version bump required.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants