-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add tests for timeout handling (#74)
Adding some tests for timeout handling. Also tests the use of `OpenAPI.Clients.with_timeout` method provided to invoke OpenAPI client side APIs with a timeout value.
- Loading branch information
Showing
26 changed files
with
647 additions
and
0 deletions.
There are no files selected for viewing
23 changes: 23 additions & 0 deletions
23
test/client/timeouttest/TimeoutTestClient/.openapi-generator-ignore
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,23 @@ | ||
# OpenAPI Generator Ignore | ||
# Generated by openapi-generator https://github.com/openapitools/openapi-generator | ||
|
||
# Use this file to prevent files from being overwritten by the generator. | ||
# The patterns follow closely to .gitignore or .dockerignore. | ||
|
||
# As an example, the C# client generator defines ApiClient.cs. | ||
# You can make changes and tell OpenAPI Generator to ignore just this file by uncommenting the following line: | ||
#ApiClient.cs | ||
|
||
# You can match any string of characters against a directory, file or extension with a single asterisk (*): | ||
#foo/*/qux | ||
# The above matches foo/bar/qux and foo/baz/qux, but not foo/bar/baz/qux | ||
|
||
# You can recursively match patterns against a directory, file or extension with a double asterisk (**): | ||
#foo/**/qux | ||
# This matches foo/bar/qux, foo/baz/qux, and foo/bar/baz/qux | ||
|
||
# You can also negate patterns with an exclamation (!). | ||
# For example, you can ignore all files in a docs folder with the file extension .md: | ||
#docs/*.md | ||
# Then explicitly reverse the ignore rule for a single file: | ||
#!docs/README.md |
8 changes: 8 additions & 0 deletions
8
test/client/timeouttest/TimeoutTestClient/.openapi-generator/FILES
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,8 @@ | ||
.openapi-generator-ignore | ||
README.md | ||
docs/DefaultApi.md | ||
docs/DelayresponseGet200Response.md | ||
src/TimeoutTestClient.jl | ||
src/apis/api_DefaultApi.jl | ||
src/modelincludes.jl | ||
src/models/model_DelayresponseGet200Response.jl |
1 change: 1 addition & 0 deletions
1
test/client/timeouttest/TimeoutTestClient/.openapi-generator/VERSION
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 @@ | ||
7.2.0 |
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,39 @@ | ||
# Julia API client for TimeoutTestClient | ||
|
||
No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) | ||
|
||
## Overview | ||
This API client was generated by the [OpenAPI Generator](https://openapi-generator.tech) project. By using the [openapi-spec](https://openapis.org) from a remote server, you can easily generate an API client. | ||
|
||
- API version: 1.0.0 | ||
- Build package: org.openapitools.codegen.languages.JuliaClientCodegen | ||
|
||
|
||
## Installation | ||
Place the Julia files generated under the `src` folder in your Julia project. Include TimeoutTestClient.jl in the project code. | ||
It would include the module named TimeoutTestClient. | ||
|
||
Documentation is generated as markdown files under the `docs` folder. You can include them in your project documentation. | ||
Documentation is also embedded in Julia which can be used with a Julia specific documentation generator. | ||
|
||
## API Endpoints | ||
|
||
Class | Method | ||
------------ | ------------- | ||
*DefaultApi* | [**delayresponse_get**](docs/DefaultApi.md#delayresponse_get)<br/>**GET** /delayresponse<br/>Delay Response Endpoint | ||
|
||
|
||
## Models | ||
|
||
- [DelayresponseGet200Response](docs/DelayresponseGet200Response.md) | ||
|
||
|
||
<a id="authorization"></a> | ||
## Authorization | ||
Endpoints do not require authorization. | ||
|
||
|
||
## Author | ||
|
||
|
||
|
37 changes: 37 additions & 0 deletions
37
test/client/timeouttest/TimeoutTestClient/docs/DefaultApi.md
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,37 @@ | ||
# DefaultApi | ||
|
||
All URIs are relative to *http://localhost* | ||
|
||
Method | HTTP request | Description | ||
------------- | ------------- | ------------- | ||
[**delayresponse_get**](DefaultApi.md#delayresponse_get) | **GET** /delayresponse | Delay Response Endpoint | ||
|
||
|
||
# **delayresponse_get** | ||
> delayresponse_get(_api::DefaultApi, delay_seconds::Int64; _mediaType=nothing) -> DelayresponseGet200Response, OpenAPI.Clients.ApiResponse <br/> | ||
> delayresponse_get(_api::DefaultApi, response_stream::Channel, delay_seconds::Int64; _mediaType=nothing) -> Channel{ DelayresponseGet200Response }, OpenAPI.Clients.ApiResponse | ||
Delay Response Endpoint | ||
|
||
### Required Parameters | ||
|
||
Name | Type | Description | Notes | ||
------------- | ------------- | ------------- | ------------- | ||
**_api** | **DefaultApi** | API context | | ||
**delay_seconds** | **Int64**| Number of seconds to delay the response | [default to nothing] | ||
|
||
### Return type | ||
|
||
[**DelayresponseGet200Response**](DelayresponseGet200Response.md) | ||
|
||
### Authorization | ||
|
||
No authorization required | ||
|
||
### HTTP request headers | ||
|
||
- **Content-Type**: Not defined | ||
- **Accept**: application/json | ||
|
||
[[Back to top]](#) [[Back to API list]](../README.md#api-endpoints) [[Back to Model list]](../README.md#models) [[Back to README]](../README.md) | ||
|
12 changes: 12 additions & 0 deletions
12
test/client/timeouttest/TimeoutTestClient/docs/DelayresponseGet200Response.md
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,12 @@ | ||
# DelayresponseGet200Response | ||
|
||
|
||
## Properties | ||
Name | Type | Description | Notes | ||
------------ | ------------- | ------------- | ------------- | ||
**delay_seconds** | **String** | | [optional] [default to nothing] | ||
|
||
|
||
[[Back to Model list]](../README.md#models) [[Back to API list]](../README.md#api-endpoints) [[Back to README]](../README.md) | ||
|
||
|
16 changes: 16 additions & 0 deletions
16
test/client/timeouttest/TimeoutTestClient/src/TimeoutTestClient.jl
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,16 @@ | ||
# This file was generated by the Julia OpenAPI Code Generator | ||
# Do not modify this file directly. Modify the OpenAPI specification instead. | ||
|
||
module TimeoutTestClient | ||
|
||
using Dates, TimeZones | ||
using OpenAPI | ||
using OpenAPI.Clients | ||
|
||
const API_VERSION = "1.0.0" | ||
|
||
include("modelincludes.jl") | ||
|
||
include("apis/api_DefaultApi.jl") | ||
|
||
end # module TimeoutTestClient |
45 changes: 45 additions & 0 deletions
45
test/client/timeouttest/TimeoutTestClient/src/apis/api_DefaultApi.jl
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,45 @@ | ||
# This file was generated by the Julia OpenAPI Code Generator | ||
# Do not modify this file directly. Modify the OpenAPI specification instead. | ||
|
||
struct DefaultApi <: OpenAPI.APIClientImpl | ||
client::OpenAPI.Clients.Client | ||
end | ||
|
||
""" | ||
The default API base path for APIs in `DefaultApi`. | ||
This can be used to construct the `OpenAPI.Clients.Client` instance. | ||
""" | ||
basepath(::Type{ DefaultApi }) = "http://localhost" | ||
|
||
const _returntypes_delayresponse_get_DefaultApi = Dict{Regex,Type}( | ||
Regex("^" * replace("200", "x"=>".") * "\$") => DelayresponseGet200Response, | ||
) | ||
|
||
function _oacinternal_delayresponse_get(_api::DefaultApi, delay_seconds::Int64; _mediaType=nothing) | ||
OpenAPI.validate_param("delay_seconds", "delayresponse_get", :minimum, delay_seconds, 0, false) | ||
|
||
_ctx = OpenAPI.Clients.Ctx(_api.client, "GET", _returntypes_delayresponse_get_DefaultApi, "/delayresponse", []) | ||
OpenAPI.Clients.set_param(_ctx.query, "delay_seconds", delay_seconds) # type Int64 | ||
OpenAPI.Clients.set_header_accept(_ctx, ["application/json", ]) | ||
OpenAPI.Clients.set_header_content_type(_ctx, (_mediaType === nothing) ? [] : [_mediaType]) | ||
return _ctx | ||
end | ||
|
||
@doc raw"""Delay Response Endpoint | ||
Params: | ||
- delay_seconds::Int64 (required) | ||
Return: DelayresponseGet200Response, OpenAPI.Clients.ApiResponse | ||
""" | ||
function delayresponse_get(_api::DefaultApi, delay_seconds::Int64; _mediaType=nothing) | ||
_ctx = _oacinternal_delayresponse_get(_api, delay_seconds; _mediaType=_mediaType) | ||
return OpenAPI.Clients.exec(_ctx) | ||
end | ||
|
||
function delayresponse_get(_api::DefaultApi, response_stream::Channel, delay_seconds::Int64; _mediaType=nothing) | ||
_ctx = _oacinternal_delayresponse_get(_api, delay_seconds; _mediaType=_mediaType) | ||
return OpenAPI.Clients.exec(_ctx, response_stream) | ||
end | ||
|
||
export delayresponse_get |
4 changes: 4 additions & 0 deletions
4
test/client/timeouttest/TimeoutTestClient/src/modelincludes.jl
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,4 @@ | ||
# This file was generated by the Julia OpenAPI Code Generator | ||
# Do not modify this file directly. Modify the OpenAPI specification instead. | ||
|
||
include("models/model_DelayresponseGet200Response.jl") |
30 changes: 30 additions & 0 deletions
30
test/client/timeouttest/TimeoutTestClient/src/models/model_DelayresponseGet200Response.jl
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,30 @@ | ||
# This file was generated by the Julia OpenAPI Code Generator | ||
# Do not modify this file directly. Modify the OpenAPI specification instead. | ||
|
||
|
||
@doc raw"""_delayresponse_get_200_response | ||
DelayresponseGet200Response(; | ||
delay_seconds=nothing, | ||
) | ||
- delay_seconds::String | ||
""" | ||
Base.@kwdef mutable struct DelayresponseGet200Response <: OpenAPI.APIModel | ||
delay_seconds::Union{Nothing, String} = nothing | ||
|
||
function DelayresponseGet200Response(delay_seconds, ) | ||
OpenAPI.validate_property(DelayresponseGet200Response, Symbol("delay_seconds"), delay_seconds) | ||
return new(delay_seconds, ) | ||
end | ||
end # type DelayresponseGet200Response | ||
|
||
const _property_types_DelayresponseGet200Response = Dict{Symbol,String}(Symbol("delay_seconds")=>"String", ) | ||
OpenAPI.property_type(::Type{ DelayresponseGet200Response }, name::Symbol) = Union{Nothing,eval(Base.Meta.parse(_property_types_DelayresponseGet200Response[name]))} | ||
|
||
function check_required(o::DelayresponseGet200Response) | ||
true | ||
end | ||
|
||
function OpenAPI.validate_property(::Type{ DelayresponseGet200Response }, name::Symbol, val) | ||
end |
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,5 @@ | ||
java -jar openapi-generator-cli.jar generate \ | ||
-i ../../specs/timeouttest.yaml \ | ||
-g julia-client \ | ||
-o TimeoutTestClient \ | ||
--additional-properties=packageName=TimeoutTestClient |
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,58 @@ | ||
module TimeoutTests | ||
|
||
include(joinpath(@__DIR__, "TimeoutTestClient", "src", "TimeoutTestClient.jl")) | ||
using .TimeoutTestClient | ||
using Test | ||
using JSON | ||
using HTTP | ||
using OpenAPI | ||
using OpenAPI.Clients | ||
import OpenAPI.Clients: Client, with_timeout, ApiException | ||
|
||
const M = TimeoutTestClient | ||
const server = "http://127.0.0.1:8081" | ||
|
||
function test_normal_operation(client, delay_secs) | ||
@info("timeout default, delay $delay_secs secs") | ||
api = M.DefaultApi(client) | ||
api_return, http_resp = delayresponse_get(api, delay_secs) | ||
@test http_resp.status == 200 | ||
@test api_return.delay_seconds == string(delay_secs) | ||
end | ||
|
||
function test_timeout_operation(client, timeout_secs, delay_secs) | ||
@info("timeout $timeout_secs secs, delay $delay_secs secs") | ||
with_timeout(client, timeout_secs) do client | ||
try | ||
api = M.DefaultApi(client) | ||
delayresponse_get(api, delay_secs) | ||
error("Timeout not thrown") | ||
catch ex | ||
@test isa(ex, ApiException) | ||
@test ex.status == 0 | ||
@test startswith(ex.reason, "Operation timed out") | ||
end | ||
end | ||
end | ||
|
||
function runtests() | ||
@testset "timeout_tests" begin | ||
@info("TimeoutTest") | ||
client = Client(server) | ||
|
||
test_normal_operation(client, 10) | ||
|
||
for timeout_secs in (5, 120) # test different timeouts | ||
delay_secs = timeout_secs + 60 | ||
test_timeout_operation(client, timeout_secs, delay_secs) | ||
|
||
# but the client should still be usable | ||
test_normal_operation(client, 10) | ||
end | ||
|
||
# also test a long delay in general (default libcurl timeout is 0) | ||
test_normal_operation(client, 160) | ||
end | ||
end | ||
|
||
end # module TimeoutTests |
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
23 changes: 23 additions & 0 deletions
23
test/server/timeouttest/TimeoutTestServer/.openapi-generator-ignore
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,23 @@ | ||
# OpenAPI Generator Ignore | ||
# Generated by openapi-generator https://github.com/openapitools/openapi-generator | ||
|
||
# Use this file to prevent files from being overwritten by the generator. | ||
# The patterns follow closely to .gitignore or .dockerignore. | ||
|
||
# As an example, the C# client generator defines ApiClient.cs. | ||
# You can make changes and tell OpenAPI Generator to ignore just this file by uncommenting the following line: | ||
#ApiClient.cs | ||
|
||
# You can match any string of characters against a directory, file or extension with a single asterisk (*): | ||
#foo/*/qux | ||
# The above matches foo/bar/qux and foo/baz/qux, but not foo/bar/baz/qux | ||
|
||
# You can recursively match patterns against a directory, file or extension with a double asterisk (**): | ||
#foo/**/qux | ||
# This matches foo/bar/qux, foo/baz/qux, and foo/bar/baz/qux | ||
|
||
# You can also negate patterns with an exclamation (!). | ||
# For example, you can ignore all files in a docs folder with the file extension .md: | ||
#docs/*.md | ||
# Then explicitly reverse the ignore rule for a single file: | ||
#!docs/README.md |
8 changes: 8 additions & 0 deletions
8
test/server/timeouttest/TimeoutTestServer/.openapi-generator/FILES
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,8 @@ | ||
.openapi-generator-ignore | ||
README.md | ||
docs/DefaultApi.md | ||
docs/DelayresponseGet200Response.md | ||
src/TimeoutTestServer.jl | ||
src/apis/api_DefaultApi.jl | ||
src/modelincludes.jl | ||
src/models/model_DelayresponseGet200Response.jl |
1 change: 1 addition & 0 deletions
1
test/server/timeouttest/TimeoutTestServer/.openapi-generator/VERSION
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 @@ | ||
7.2.0 |
Oops, something went wrong.