-
Notifications
You must be signed in to change notification settings - Fork 420
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Always use the same event loop for a client connection
Motivation: It might be useful for other applications interacting with gRPC to know that a client connection will always use the same event loop, event if it reconnects. Modifications: Use the same event loop when attempting reconnections. Result: A connection will only ever use one event loop.
- Loading branch information
Showing
5 changed files
with
152 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
import Foundation | ||
import GRPC | ||
import NIO | ||
import NIOTransportServices | ||
import XCTest | ||
|
||
class PlatformSupportTests: GRPCTestCase { | ||
var group: EventLoopGroup! | ||
|
||
override func tearDown() { | ||
XCTAssertNoThrow(try self.group?.syncShutdownGracefully()) | ||
} | ||
|
||
func testMakeEventLoopGroupReturnsMultiThreadedGroupForPosix() { | ||
self.group = PlatformSupport.makeEventLoopGroup( | ||
loopCount: 1, | ||
networkPreference: .userDefined(.posix) | ||
) | ||
|
||
XCTAssertTrue(self.group is MultiThreadedEventLoopGroup) | ||
} | ||
|
||
func testMakeEventLoopGroupReturnsNIOTSGroupForNetworkFramework() { | ||
// If we don't have Network.framework then we can't test this. | ||
#if canImport(Network) | ||
guard #available(macOS 10.14, *) else { return } | ||
|
||
self.group = PlatformSupport.makeEventLoopGroup( | ||
loopCount: 1, | ||
networkPreference: .userDefined(.networkFramework) | ||
) | ||
|
||
XCTAssertTrue(self.group is NIOTSEventLoopGroup) | ||
#endif | ||
} | ||
|
||
func testMakeClientBootstrapReturnsClientBootstrapForMultiThreadedGroup() { | ||
self.group = MultiThreadedEventLoopGroup(numberOfThreads: 1) | ||
let bootstrap = PlatformSupport.makeClientBootstrap(group: self.group) | ||
XCTAssertTrue(bootstrap is ClientBootstrap) | ||
} | ||
|
||
func testMakeClientBootstrapReturnsClientBootstrapForEventLoop() { | ||
self.group = MultiThreadedEventLoopGroup(numberOfThreads: 1) | ||
let eventLoop = self.group.next() | ||
let bootstrap = PlatformSupport.makeClientBootstrap(group: eventLoop) | ||
XCTAssertTrue(bootstrap is ClientBootstrap) | ||
} | ||
|
||
func testMakeClientBootstrapReturnsNIOTSConnectionBootstrapForNIOTSGroup() { | ||
// If we don't have Network.framework then we can't test this. | ||
#if canImport(Network) | ||
guard #available(macOS 10.14, *) else { return } | ||
|
||
self.group = NIOTSEventLoopGroup(loopCount: 1) | ||
let bootstrap = PlatformSupport.makeClientBootstrap(group: self.group) | ||
XCTAssertTrue(bootstrap is NIOTSConnectionBootstrap) | ||
#endif | ||
} | ||
|
||
func testMakeClientBootstrapReturnsNIOTSConnectionBootstrapForQoSEventLoop() { | ||
// If we don't have Network.framework then we can't test this. | ||
#if canImport(Network) | ||
guard #available(macOS 10.14, *) else { return } | ||
|
||
self.group = NIOTSEventLoopGroup(loopCount: 1) | ||
|
||
let eventLoop = self.group.next() | ||
XCTAssertTrue(eventLoop is QoSEventLoop) | ||
|
||
let bootstrap = PlatformSupport.makeClientBootstrap(group: eventLoop) | ||
XCTAssertTrue(bootstrap is NIOTSConnectionBootstrap) | ||
#endif | ||
} | ||
|
||
func testMakeServerBootstrapReturnsServerBootstrapForMultiThreadedGroup() { | ||
self.group = MultiThreadedEventLoopGroup(numberOfThreads: 1) | ||
let bootstrap = PlatformSupport.makeServerBootstrap(group: self.group) | ||
XCTAssertTrue(bootstrap is ServerBootstrap) | ||
} | ||
|
||
func testMakeServerBootstrapReturnsServerBootstrapForEventLoop() { | ||
self.group = MultiThreadedEventLoopGroup(numberOfThreads: 1) | ||
|
||
let eventLoop = self.group.next() | ||
let bootstrap = PlatformSupport.makeServerBootstrap(group: eventLoop) | ||
XCTAssertTrue(bootstrap is ServerBootstrap) | ||
} | ||
|
||
func testMakeServerBootstrapReturnsNIOTSListenerBootstrapForNIOTSGroup() { | ||
// If we don't have Network.framework then we can't test this. | ||
#if canImport(Network) | ||
guard #available(macOS 10.14, *) else { return } | ||
|
||
self.group = NIOTSEventLoopGroup(loopCount: 1) | ||
let bootstrap = PlatformSupport.makeServerBootstrap(group: self.group) | ||
XCTAssertTrue(bootstrap is NIOTSListenerBootstrap) | ||
#endif | ||
} | ||
|
||
func testMakeServerBootstrapReturnsNIOTSListenerBootstrapForQoSEventLoop() { | ||
// If we don't have Network.framework then we can't test this. | ||
#if canImport(Network) | ||
guard #available(macOS 10.14, *) else { return } | ||
|
||
self.group = NIOTSEventLoopGroup(loopCount: 1) | ||
|
||
let eventLoop = self.group.next() | ||
XCTAssertTrue(eventLoop is QoSEventLoop) | ||
|
||
let bootstrap = PlatformSupport.makeServerBootstrap(group: eventLoop) | ||
XCTAssertTrue(bootstrap is NIOTSListenerBootstrap) | ||
#if canImport(Network) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters