-
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.
Make idle timeout configurable (#824)
* Make idle timeout configurable Motivation: We shed idle connections but don't offer the ability to configure the timeout; we should. Modifications: - Make server and client idle timeouts configurable - Add integ tests to check the timeouts works Result: Idle timeouts are configurable, more tests.
- Loading branch information
Showing
8 changed files
with
142 additions
and
3 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
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,80 @@ | ||
/* | ||
* Copyright 2020, gRPC Authors All rights reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
@testable import GRPC | ||
import NIO | ||
import EchoModel | ||
import EchoImplementation | ||
import XCTest | ||
|
||
class GRPCIdleTests: GRPCTestCase { | ||
func testClientIdleTimeout() { | ||
XCTAssertNoThrow(try self.doTestIdleTimeout(serverIdle: .minutes(5), clientIdle: .milliseconds(100))) | ||
} | ||
|
||
func testServerIdleTimeout() throws { | ||
XCTAssertNoThrow(try self.doTestIdleTimeout(serverIdle: .milliseconds(100), clientIdle: .minutes(5))) | ||
} | ||
|
||
func doTestIdleTimeout(serverIdle: TimeAmount, clientIdle: TimeAmount) throws { | ||
// Is the server idling first? This determines what state change the client should see when the | ||
// idle happens. | ||
let isServerIdleFirst = serverIdle < clientIdle | ||
|
||
let group = MultiThreadedEventLoopGroup(numberOfThreads: 1) | ||
defer { | ||
XCTAssertNoThrow(try group.syncShutdownGracefully()) | ||
} | ||
|
||
// Setup a server. | ||
let server = try Server.insecure(group: group) | ||
.withServiceProviders([EchoProvider()]) | ||
.withConnectionIdleTimeout(serverIdle) | ||
.bind(host: "localhost", port: 0) | ||
.wait() | ||
defer { | ||
XCTAssertNoThrow(try server.close().wait()) | ||
} | ||
|
||
// Setup a state change recorder for the client. | ||
let stateRecorder = RecordingConnectivityDelegate() | ||
stateRecorder.expectChanges(3) { changes in | ||
XCTAssertEqual(changes, [ | ||
Change(from: .idle, to: .connecting), | ||
Change(from: .connecting, to: .ready), | ||
Change(from: .ready, to: isServerIdleFirst ? .transientFailure : .idle) | ||
]) | ||
} | ||
|
||
// Setup a connection. | ||
let connection = ClientConnection.insecure(group: group) | ||
.withConnectivityStateDelegate(stateRecorder) | ||
.withConnectionIdleTimeout(clientIdle) | ||
.connect(host: "localhost", port: server.channel.localAddress!.port!) | ||
defer { | ||
XCTAssertNoThrow(try connection.close().wait()) | ||
} | ||
|
||
let client = Echo_EchoClient(channel: connection) | ||
|
||
// Make a call; this will trigger channel creation. | ||
let get = client.get(.with { $0.text = "ignored" }) | ||
let status = try get.status.wait() | ||
XCTAssertEqual(status.code, .ok) | ||
|
||
// Now wait for the state changes. | ||
stateRecorder.waitForExpectedChanges(timeout: .seconds(10)) | ||
} | ||
} |
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