Skip to content

Commit

Permalink
Improve timeouts
Browse files Browse the repository at this point in the history
  • Loading branch information
zltnDC committed Sep 12, 2023
1 parent 5689bdf commit 3c1e1be
Show file tree
Hide file tree
Showing 9 changed files with 30 additions and 20 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package pl.leancode.patrol;

import org.apache.hc.core5.util.Timeout
import pl.leancode.patrol.contracts.Contracts
import pl.leancode.patrol.contracts.PatrolAppServiceClientException
import pl.leancode.patrol.contracts.PatrolAppServiceClient as Client
Expand All @@ -10,14 +11,16 @@ import pl.leancode.patrol.contracts.PatrolAppServiceClient as Client
class PatrolAppServiceClient {

private var client: Client
// https://github.com/leancodepl/patrol/issues/1683
private val timeout = Timeout.ofHours(2)

constructor() {
client = Client(address = "localhost", port = 8082)
client = Client(address = "localhost", port = 8082, timeout = timeout)
Logger.i("Created PatrolAppServiceClient: ${client.serverUrl}")
}

constructor(address: String) {
client = Client(address = address, port = 8082)
client = Client(address = address, port = 8082, timeout = timeout)
Logger.i("Created PatrolAppServiceClient: ${client.serverUrl}")
}

Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@
class PatrolAppServiceClient {
private let port: Int
private let address: String
private let timeout: TimeInterval

init(port: Int, address: String) {
init(port: Int, address: String, timeout: TimeInterval) {
self.port = port
self.address = address
self.timeout = timeout
}

func listDartTests() async throws -> ListDartTestsResponse {
Expand All @@ -25,13 +27,13 @@ class PatrolAppServiceClient {
let url = URL(string: "http://\(address):\(port)/\(requestName)")!

let urlconfig = URLSessionConfiguration.default
urlconfig.timeoutIntervalForRequest = TimeInterval(300)
urlconfig.timeoutIntervalForResource = TimeInterval(300)
urlconfig.timeoutIntervalForRequest = timeout
urlconfig.timeoutIntervalForResource = timeout

var request = URLRequest(url: url)
request.httpMethod = "POST"
request.httpBody = body
request.timeoutInterval = TimeInterval(300)
request.timeoutInterval = timeout

let (data, response) = try await URLSession(configuration: urlconfig).data(for: request)
guard (response as? HTTPURLResponse)?.statusCode == 200 else {
Expand Down
4 changes: 3 additions & 1 deletion packages/patrol/ios/Classes/ObjCPatrolAppServiceClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,12 @@
/// Construct client for accessing PatrolAppService server using the existing channel.
@objc public override init() {
let port = 8082 // TODO: Document this value better
// https://github.com/leancodepl/patrol/issues/1683
let timeout = TimeInterval(2*60*60)

NSLog("PatrolAppServiceClient: created, port: \(port)")

client = PatrolAppServiceClient(port: port, address: "localhost")
client = PatrolAppServiceClient(port: port, address: "localhost", timeout: timeout)
}

@objc public func listDartTests() async throws -> [String] {
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion packages/patrol/lib/src/native/patrol_app_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import 'package:shelf/shelf.dart' as shelf;
import 'package:shelf/shelf_io.dart' as shelf_io;

const _port = 8082;
const _idleTimeout = Duration(hours: 2);

class _TestExecutionResult {
const _TestExecutionResult({required this.passed, required this.details});
Expand All @@ -32,7 +33,7 @@ Future<void> runAppService(PatrolAppService service) async {
poweredByHeader: null,
);

server.idleTimeout = const Duration(seconds: 300);
server.idleTimeout = _idleTimeout;

final address = server.address;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ import org.http4k.core.Status
final urlWithPath = r'"$serverUrl$path"';

return '''
class ${service.name}Client(private val address: String, private val port: Int) {
class ${service.name}Client(private val address: String, private val port: Int, private val timeout: Timeout) {
$endpoints
Expand All @@ -62,8 +62,8 @@ $endpoints
HttpClients.custom().setDefaultRequestConfig(
RequestConfig
.copy(RequestConfig.DEFAULT)
.setResponseTimeout(Timeout.ofSeconds(300))
.setConnectionRequestTimeout(Timeout.ofSeconds(300))
.setResponseTimeout(timeout)
.setConnectionRequestTimeout(timeout)
.build()
).build())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class ${service.name}Client {
${service.name}Client(
this._client,
this._apiUri, {
Duration timeout = const Duration(seconds: 300),
Duration timeout = const Duration(seconds: 30),
}) : _timeout = timeout, $headers;
final Duration _timeout;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,12 @@ class IOSURLSessionClientGenerator {
class ${service.name}Client {
private let port: Int
private let address: String
private let timeout: TimeInterval
init(port: Int, address: String) {
init(port: Int, address: String, timeout: TimeInterval) {
self.port = port
self.address = address
self.timeout = timeout
}
$endpoints
Expand All @@ -48,13 +50,13 @@ $endpoints
let url = URL(string: "$url")!
let urlconfig = URLSessionConfiguration.default
urlconfig.timeoutIntervalForRequest = TimeInterval(300)
urlconfig.timeoutIntervalForResource = TimeInterval(300)
urlconfig.timeoutIntervalForRequest = timeout
urlconfig.timeoutIntervalForResource = timeout
var request = URLRequest(url: url)
request.httpMethod = "POST"
request.httpBody = body
request.timeoutInterval = TimeInterval(300)
request.timeoutInterval = timeout
let (data, response) = try await URLSession(configuration: urlconfig).data(for: request)
guard (response as? HTTPURLResponse)?.statusCode == 200 else {
Expand Down

0 comments on commit 3c1e1be

Please sign in to comment.