Skip to content

Commit 2c54f96

Browse files
committed
Add test suite that uses toxiproxy
Fixes #1492 * Add dedicated test class for Toxiproxy * Start Toxiproxy via docker on GHA ubuntu runner * Start Toxiproxy in same Powershell session as `dotnet test` on GHA windows runner * Add toxiproxy-netcore as a submodule so that we can strong-name it. * Remove use of socket read timeout, and depend on heartbeats instead. * Remove duplicate tests * Use `ConcurrentBag` where necessary
1 parent 16bfe25 commit 2c54f96

20 files changed

+296
-101
lines changed

.ci/ubuntu/gha-setup.sh

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ readonly script_dir
99
echo "[INFO] script_dir: '$script_dir'"
1010

1111
readonly docker_name_prefix='rabbitmq-dotnet-client'
12+
readonly docker_network_name="$docker_name_prefix-network"
1213

1314
if [[ ! -v GITHUB_ACTIONS ]]
1415
then
@@ -23,18 +24,46 @@ else
2324
echo "[INFO] set GITHUB_WORKSPACE to: '$GITHUB_WORKSPACE'"
2425
fi
2526

27+
if [[ $1 == 'toxiproxy' ]]
28+
then
29+
readonly run_toxiproxy='true'
30+
else
31+
readonly run_toxiproxy='false'
32+
fi
33+
2634
set -o nounset
2735

2836
declare -r rabbitmq_docker_name="$docker_name_prefix-rabbitmq"
37+
declare -r toxiproxy_docker_name="$docker_name_prefix-toxiproxy"
38+
39+
function start_toxiproxy
40+
{
41+
if [[ $run_toxiproxy == 'true' ]]
42+
then
43+
sudo ss -4nlp
44+
echo "[INFO] starting Toxiproxy server docker container"
45+
docker rm --force "$toxiproxy_docker_name" 2>/dev/null || echo "[INFO] $toxiproxy_docker_name was not running"
46+
docker run --pull always --detach \
47+
--name "$toxiproxy_docker_name" \
48+
--hostname "$toxiproxy_docker_name" \
49+
--publish 8474:8474 \
50+
--publish 55672:55672 \
51+
--network "$docker_network_name" \
52+
'ghcr.io/shopify/toxiproxy:2.7.0'
53+
fi
54+
}
2955

3056
function start_rabbitmq
3157
{
58+
echo "[INFO] starting RabbitMQ server docker container"
3259
chmod 0777 "$GITHUB_WORKSPACE/.ci/ubuntu/log"
3360
docker rm --force "$rabbitmq_docker_name" 2>/dev/null || echo "[INFO] $rabbitmq_docker_name was not running"
34-
docker run --pull always --detach --name "$rabbitmq_docker_name" \
61+
docker run --pull always --detach \
62+
--name "$rabbitmq_docker_name" \
63+
--hostname "$rabbitmq_docker_name" \
3564
--publish 5671:5671 \
3665
--publish 5672:5672 \
37-
--publish 15672:15672 \
66+
--network "$docker_network_name" \
3867
--volume "$GITHUB_WORKSPACE/.ci/ubuntu/enabled_plugins:/etc/rabbitmq/enabled_plugins" \
3968
--volume "$GITHUB_WORKSPACE/.ci/ubuntu/rabbitmq.conf:/etc/rabbitmq/rabbitmq.conf:ro" \
4069
--volume "$GITHUB_WORKSPACE/.ci/certs:/etc/rabbitmq/certs:ro" \
@@ -109,6 +138,10 @@ function install_ca_certificate
109138
-pass pass:grapefruit < /dev/null
110139
}
111140

141+
docker network create "$docker_network_name" || echo "[INFO] network '$docker_network_name' is already created"
142+
143+
start_toxiproxy
144+
112145
start_rabbitmq
113146

114147
wait_rabbitmq

.ci/windows/toxiproxy/LICENSE

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2014 Shopify
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.
22+
8.9 MB
Binary file not shown.
8.66 MB
Binary file not shown.

.ci/windows/versions.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
{
2-
"erlang": "26.2.1",
3-
"rabbitmq": "3.12.10"
2+
"erlang": "26.2.2",
3+
"rabbitmq": "3.12.12"
44
}

.github/workflows/build-test.yaml

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ jobs:
2626
- name: Build (Debug)
2727
run: dotnet build ${{ github.workspace }}\Build.csproj
2828
- name: Verify
29-
run: dotnet format ${{ github.workspace }}\RabbitMQDotNetClient.sln --no-restore --verify-no-changes --verbosity=diagnostic
29+
run: dotnet format ${{ github.workspace }}\RabbitMQDotNetClient.sln --no-restore --verify-no-changes
3030
- name: APIApproval Test
3131
run: dotnet test "${{ github.workspace }}\projects\Test\Unit\Unit.csproj" --no-restore --no-build --logger 'console;verbosity=detailed' --filter='FullyQualifiedName=Test.Unit.APIApproval.Approve'
3232
- name: Unit Tests
@@ -67,7 +67,18 @@ jobs:
6767
id: install-start-rabbitmq
6868
run: .\.ci\windows\gha-setup.ps1
6969
- name: Integration Tests
70-
run: dotnet test --environment "RABBITMQ_RABBITMQCTL_PATH=${{ steps.install-start-rabbitmq.outputs.path }}" --environment 'RABBITMQ_LONG_RUNNING_TESTS=true' --environment 'PASSWORD=grapefruit' --environment SSL_CERTS_DIR="${{ github.workspace }}\.ci\certs" "${{ github.workspace }}\projects\Test\Integration\Integration.csproj" --no-restore --no-build --logger 'console;verbosity=detailed'
70+
run: |
71+
$tx = Start-Job -Verbose -ScriptBlock { & "${{ github.workspace }}\.ci\windows\toxiproxy\toxiproxy-server.exe" }; `
72+
Start-Sleep -Seconds 1; `
73+
Receive-Job -Job $tx; `
74+
& "${{ github.workspace }}\.ci\windows\toxiproxy\toxiproxy-cli.exe" list; `
75+
dotnet test `
76+
--environment "RABBITMQ_RABBITMQCTL_PATH=${{ steps.install-start-rabbitmq.outputs.path }}" `
77+
--environment 'RABBITMQ_LONG_RUNNING_TESTS=true' `
78+
--environment 'RABBITMQ_TOXIPROXY_TESTS=true' `
79+
--environment 'PASSWORD=grapefruit' `
80+
--environment SSL_CERTS_DIR="${{ github.workspace }}\.ci\certs" `
81+
"${{ github.workspace }}\projects\Test\Integration\Integration.csproj" --no-restore --no-build --logger 'console;verbosity=detailed'
7182
- name: Maybe upload RabbitMQ logs
7283
if: failure()
7384
uses: actions/upload-artifact@v3
@@ -132,11 +143,11 @@ jobs:
132143
- name: Build (Debug)
133144
run: dotnet build ${{ github.workspace }}/Build.csproj
134145
- name: Verify
135-
run: dotnet format ${{ github.workspace }}/RabbitMQDotNetClient.sln --no-restore --verify-no-changes --verbosity=diagnostic
146+
run: dotnet format ${{ github.workspace }}/RabbitMQDotNetClient.sln --no-restore --verify-no-changes
136147
- name: APIApproval Test
137148
run: dotnet test "${{ github.workspace }}/projects/Test/Unit/Unit.csproj" --no-restore --no-build --logger 'console;verbosity=detailed' --filter='FullyQualifiedName=Test.Unit.APIApproval.Approve'
138149
- name: Unit Tests
139-
run: dotnet test "${{ github.workspace }}/projects/Test/Unit/Unit.csproj" --no-restore --no-build --verbosity=diagnostic --logger 'console;verbosity=detailed'
150+
run: dotnet test "${{ github.workspace }}/projects/Test/Unit/Unit.csproj" --no-restore --no-build --logger 'console;verbosity=detailed'
140151
- name: Upload Build (Debug)
141152
uses: actions/upload-artifact@v3
142153
with:
@@ -165,12 +176,13 @@ jobs:
165176
path: projects
166177
- name: Start RabbitMQ
167178
id: start-rabbitmq
168-
run: ${{ github.workspace }}/.ci/ubuntu/gha-setup.sh
179+
run: ${{ github.workspace }}/.ci/ubuntu/gha-setup.sh toxiproxy
169180
- name: Integration Tests
170181
run: |
171182
dotnet test \
172183
--environment "RABBITMQ_RABBITMQCTL_PATH=DOCKER:${{ steps.start-rabbitmq.outputs.id }}" \
173184
--environment 'RABBITMQ_LONG_RUNNING_TESTS=true' \
185+
--environment 'RABBITMQ_TOXIPROXY_TESTS=true' \
174186
--environment 'PASSWORD=grapefruit' \
175187
--environment SSL_CERTS_DIR="${{ github.workspace }}/.ci/certs" \
176188
"${{ github.workspace }}/projects/Test/Integration/Integration.csproj" --no-restore --no-build --logger 'console;verbosity=detailed'

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,6 @@
22
path = _site
33
url = https://github.com/rabbitmq/rabbitmq-dotnet-client.git
44
branch = gh-pages
5+
[submodule "projects/toxiproxy-netcore"]
6+
path = projects/toxiproxy-netcore
7+
url = https://github.com/rabbitmq/toxiproxy-netcore.git

Build.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
<ProjectReference Include="projects/Benchmarks/Benchmarks.csproj" />
1010
<ProjectReference Include="projects/RabbitMQ.Client/RabbitMQ.Client.csproj" />
1111
<ProjectReference Include="projects/RabbitMQ.Client.OAuth2/RabbitMQ.Client.OAuth2.csproj" />
12+
<ProjectReference Include="projects/toxiproxy-netcore/src/ToxiproxyNetCore/ToxiproxyNetCore.csproj" />
1213
<ProjectReference Include="projects/Test/Common/Common.csproj" />
1314
<ProjectReference Include="projects/Test/Applications/CreateChannel/CreateChannel.csproj" />
1415
<ProjectReference Include="projects/Test/Applications/MassPublish/MassPublish.csproj" />

RabbitMQDotNetClient.sln

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SequentialIntegration", "pr
3838
EndProject
3939
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Common", "projects\Test\Common\Common.csproj", "{C11F25F4-7EA1-4874-9E25-DEB42E3A7C67}"
4040
EndProject
41+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ToxiproxyNetCore", "projects\toxiproxy-netcore\src\ToxiproxyNetCore\ToxiproxyNetCore.csproj", "{AB5B7C53-D7EC-4985-A6DE-70178E4B688A}"
42+
EndProject
4143
Global
4244
GlobalSection(SolutionConfigurationPlatforms) = preSolution
4345
Debug|Any CPU = Debug|Any CPU
@@ -84,6 +86,10 @@ Global
8486
{C11F25F4-7EA1-4874-9E25-DEB42E3A7C67}.Debug|Any CPU.Build.0 = Debug|Any CPU
8587
{C11F25F4-7EA1-4874-9E25-DEB42E3A7C67}.Release|Any CPU.ActiveCfg = Release|Any CPU
8688
{C11F25F4-7EA1-4874-9E25-DEB42E3A7C67}.Release|Any CPU.Build.0 = Release|Any CPU
89+
{AB5B7C53-D7EC-4985-A6DE-70178E4B688A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
90+
{AB5B7C53-D7EC-4985-A6DE-70178E4B688A}.Debug|Any CPU.Build.0 = Debug|Any CPU
91+
{AB5B7C53-D7EC-4985-A6DE-70178E4B688A}.Release|Any CPU.ActiveCfg = Release|Any CPU
92+
{AB5B7C53-D7EC-4985-A6DE-70178E4B688A}.Release|Any CPU.Build.0 = Release|Any CPU
8793
EndGlobalSection
8894
GlobalSection(SolutionProperties) = preSolution
8995
HideSolutionNode = FALSE
@@ -97,6 +103,7 @@ Global
97103
{B01347D8-C327-471B-A1FE-7B86F7684A27} = {EFD4BED5-13A5-4D9C-AADF-CAB7E1573704}
98104
{F25725D7-2978-45F4-B90F-25D6F8B71C9E} = {EFD4BED5-13A5-4D9C-AADF-CAB7E1573704}
99105
{C11F25F4-7EA1-4874-9E25-DEB42E3A7C67} = {EFD4BED5-13A5-4D9C-AADF-CAB7E1573704}
106+
{AB5B7C53-D7EC-4985-A6DE-70178E4B688A} = {EFD4BED5-13A5-4D9C-AADF-CAB7E1573704}
100107
EndGlobalSection
101108
GlobalSection(ExtensibilityGlobals) = postSolution
102109
SolutionGuid = {3C6A0C44-FA63-4101-BBF9-2598641167D1}

projects/RabbitMQ.Client/client/api/InternalConstants.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,5 +37,7 @@ internal static class InternalConstants
3737
{
3838
internal static readonly TimeSpan DefaultConnectionAbortTimeout = TimeSpan.FromSeconds(5);
3939
internal static readonly TimeSpan DefaultConnectionCloseTimeout = TimeSpan.FromSeconds(30);
40+
41+
internal static string Now => DateTime.UtcNow.ToString("s", System.Globalization.CultureInfo.InvariantCulture);
4042
}
4143
}

0 commit comments

Comments
 (0)