From 46c5d5313444fbc5750f8b7ef1be5cce71baa209 Mon Sep 17 00:00:00 2001 From: Luke Bakken Date: Tue, 2 May 2023 13:57:49 -0700 Subject: [PATCH 1/5] Build using traversal project Update testing versions --- .ci/versions.json | 4 ++-- Build.csproj | 16 ++++++++++++++++ build.ps1 | 25 +++++++++++++++++++++++++ 3 files changed, 43 insertions(+), 2 deletions(-) create mode 100644 Build.csproj create mode 100644 build.ps1 diff --git a/.ci/versions.json b/.ci/versions.json index 4715cc1083..9da3f13b77 100644 --- a/.ci/versions.json +++ b/.ci/versions.json @@ -1,4 +1,4 @@ { - "erlang": "25.3", - "rabbitmq": "3.11.11" + "erlang": "25.3.1", + "rabbitmq": "3.11.15" } diff --git a/Build.csproj b/Build.csproj new file mode 100644 index 0000000000..2acee38279 --- /dev/null +++ b/Build.csproj @@ -0,0 +1,16 @@ + + + + false + true + + + + + + + + + + + diff --git a/build.ps1 b/build.ps1 new file mode 100644 index 0000000000..cd9af0751d --- /dev/null +++ b/build.ps1 @@ -0,0 +1,25 @@ +[CmdletBinding(PositionalBinding=$false)] +param( + [switch]$RunTests +) + +Write-Host "Run Parameters:" -ForegroundColor Cyan +Write-Host "`tPSScriptRoot: $PSScriptRoot" +Write-Host "`tRunTests: $RunTests" +Write-Host "`tdotnet --version: $(dotnet --version)" + +Write-Host "Building all projects (Build.csproj traversal)..." -ForegroundColor "Magenta" +dotnet build "$PSScriptRoot\Build.csproj" +Write-Host "Done building." -ForegroundColor "Green" + +if ($RunTests) { + Write-Host "Running tests: Build.csproj traversal (all frameworks)" -ForegroundColor "Magenta" + dotnet test "$PSScriptRoot\Build.csproj" --no-build --logger "console;verbosity=detailed" + if ($LastExitCode -ne 0) { + Write-Host "Error with tests, aborting build." -Foreground "Red" + Exit 1 + } + Write-Host "Tests passed!" -ForegroundColor "Green" +} + +Write-Host "Done." From d9823733c91a57351b5ddfd89ecc34c6b175b8da Mon Sep 17 00:00:00 2001 From: Luke Bakken Date: Wed, 3 May 2023 09:34:59 -0700 Subject: [PATCH 2/5] Use traversal project in CI. Ensure formatting is verified on linux and windows --- .ci/gha-run-tests.ps1 | 4 ++-- .github/workflows/main.yaml | 16 +++++++++------- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/.ci/gha-run-tests.ps1 b/.ci/gha-run-tests.ps1 index d2c47ce495..547aad6252 100644 --- a/.ci/gha-run-tests.ps1 +++ b/.ci/gha-run-tests.ps1 @@ -28,5 +28,5 @@ Write-Host "[INFO] Setting RABBITMQ_RABBITMQCTL_PATH to '$rabbitmqctl_path'..." $env:RABBITMQ_RABBITMQCTL_PATH = $rabbitmqctl_path [Environment]::SetEnvironmentVariable('RABBITMQ_RABBITMQCTL_PATH', $rabbitmqctl_path, 'Machine') -$solution_file = Join-Path -Path $env:GITHUB_WORKSPACE -ChildPath 'RabbitMQDotNetClient.sln' -dotnet test --no-restore --no-build --logger "console;verbosity=detailed" $solution_file +$build_csproj_file = Join-Path -Path $env:GITHUB_WORKSPACE -ChildPath 'Build.csproj' +dotnet test $build_csproj_file --no-restore --no-build --logger "console;verbosity=detailed" diff --git a/.github/workflows/main.yaml b/.github/workflows/main.yaml index 6f572bf6cc..00b306a000 100644 --- a/.github/workflows/main.yaml +++ b/.github/workflows/main.yaml @@ -42,9 +42,11 @@ jobs: - name: List NuGet sources run: dotnet nuget locals all --list - name: Restore - run: dotnet restore --verbosity=normal + run: dotnet restore ./Build.csproj --verbosity=normal - name: Build - run: dotnet build --no-restore --verbosity=normal + run: dotnet build ./Build.csproj --no-restore --verbosity=normal + - name: Verify + run: dotnet format ./RabbitMQDotNetClient.sln --no-restore --verbosity=diagnostic --verify-no-changes - name: Test run: ./.ci/gha-run-tests.ps1 @@ -79,12 +81,12 @@ jobs: restore-keys: | ${{ runner.os }}-v0-nuget- - name: Restore - run: dotnet restore --verbosity=normal + run: dotnet restore ./Build.csproj --verbosity=normal - name: Build - run: dotnet build --no-restore --verbosity=normal + run: dotnet build ./Build.csproj --no-restore --verbosity=normal + - name: Verify + run: dotnet format ./RabbitMQDotNetClient.sln --no-restore --verbosity=diagnostic --verify-no-changes - name: Test - run: dotnet test --no-restore --no-build --logger "console;verbosity=detailed" --framework "net6.0" + run: dotnet test ./Build.csproj --no-restore --no-build --logger "console;verbosity=detailed" --framework "net6.0" env: RABBITMQ_RABBITMQCTL_PATH: DOCKER:${{job.services.rabbitmq.id}} - - name: Verify Formatting - run: dotnet format --verbosity normal --no-restore --verify-no-changes From 07f39bb6902ebada853feb9803ca08bbf2a40316 Mon Sep 17 00:00:00 2001 From: Luke Bakken Date: Wed, 3 May 2023 11:26:22 -0700 Subject: [PATCH 3/5] Remove obsolete scripts, update docs --- APIDOCS.md | 2 +- CONTRIBUTING.md | 2 +- RUNNING_TESTS.md | 65 ++++++++++++++++++++++++++---------------------- build.bat | 4 --- build.sh | 17 ------------- run-test.bat | 3 --- run-test.sh | 16 ------------ 7 files changed, 37 insertions(+), 72 deletions(-) delete mode 100644 build.bat delete mode 100755 build.sh delete mode 100644 run-test.bat delete mode 100755 run-test.sh diff --git a/APIDOCS.md b/APIDOCS.md index f204cb52fc..a1c39479c6 100644 --- a/APIDOCS.md +++ b/APIDOCS.md @@ -9,7 +9,7 @@ pushd _site git remote add origin-ssh git@github.com:rabbitmq/rabbitmq-dotnet-client.git git checkout --track origin-ssh/gh-pages popd -.\build.bat +.\build.ps1 -RunTests:$false docfx.exe pushd _site git commit -a -m 'rabbitmq-dotnet-client docs vX.Y.Z' diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 9bfd74618b..c33bc7bf67 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -86,7 +86,7 @@ Benchmarks can be found under `./projects/Benchmarks`. On the command line, run like so: ``` -dotnet run -c Release -f netcoreapp5.0 --project ./projects/Benchmarks/ --filter Networking_BasicDeliver_LongLivedConnection +dotnet run -c Release -f net6.0 --project ./projects/Benchmarks/ --filter Networking_BasicDeliver_LongLivedConnection ``` ## Code of Conduct diff --git a/RUNNING_TESTS.md b/RUNNING_TESTS.md index dd13c16a94..a25a008221 100644 --- a/RUNNING_TESTS.md +++ b/RUNNING_TESTS.md @@ -1,36 +1,34 @@ -## Overview +# Overview -.NET client's test suite assumes there's a RabbitMQ node listening on `localhost:5672` -(the default settings). TLS tests require a node listening on the default -[TLS port](https://rabbitmq.com/ssl.html). +The RabbitMQ .NET client's test suite assumes there's a RabbitMQ node listening +on `localhost:5672` (the default settings). TLS tests require a node listening +on the default [TLS port](https://rabbitmq.com/ssl.html). -It is possible to use Visual Studio Community Edition .NET Core, and -`dotnet.exe` in `PATH`, to build the client and run the test suite. +It is possible to use Visual Studio Community Edition and `dotnet.exe` in +`PATH`, to build the client and run the test suite. ## Building -Before this project can be opened in Visual Studio, it's necessary to pull down dependencies -and perform protocol encoder/decoder code generation. -On Windows run: +### Windows -``` powershell -build.bat +```powershell +build.ps1 ``` -On MacOS and linux run: +### MacOS and Linux -``` shell -./build.sh +```shell +dotnet build ./Build.csproj ``` -This will complete the code AMQP 0-9-1 protocol code generation and build all projects. After this open the solution in Visual Studio. +This will build all projects. After this open the solution in Visual Studio. ## Test Environment Requirements -Tests can be run from Visual Studio using the NUnit Test Adapter. Note that it +Tests can be run from Visual Studio using the XUnit Test Adapter. Note that it may take some time for the adapter to discover tests in the assemblies. The test suite assumes there's a RabbitMQ node running locally with all @@ -38,6 +36,7 @@ defaults, and the tests will need to be able to run commands against the [`rabbitmqctl`](https://www.rabbitmq.com/rabbitmqctl.8.html) tool for that node. Two options to accomplish this are covered below. + ### Option One: Using a RabbitMQ Release It is possible to install and run a node using any [binary build](https://www.rabbitmq.com/download.html) @@ -46,16 +45,16 @@ invoked directly without using an absolute file path. Note that this method does On Windows, you must run unit tests as follows (replace `X.Y.Z` with your RabbitMQ version): -``` -set "RABBITMQ_RABBITMQCTL_PATH=C:\Program Files\RabbitMQ Server\rabbitmq_server-X.Y.Z\sbin\rabbitmqctl.bat" -.\run-test.bat +```powershell +$env:RABBITMQ_RABBITMQCTL_PATH='C:\Program Files\RabbitMQ Server\rabbitmq_server-X.Y.Z\sbin\rabbitmqctl.bat' +.\build.ps1 -RunTests ``` ### Option Two: Building a RabbitMQ Node from Source T run a RabbitMQ node [built from source](https://www.rabbitmq.com/build-server.html): -``` +```shell git clone https://github.com/rabbitmq/rabbitmq-server.git rabbitmq-server cd rabbitmq-server @@ -77,9 +76,14 @@ RABBITMQ_RABBITMQCTL_PATH=/path/to/rabbitmqctl dotnet test projects/Unit ### Option Three: Using a Docker Container -It is also possible to run a RabbitMQ node in a [Docker](https://www.docker.com/) container. Set the environment variable `RABBITMQ_RABBITMQCTL_PATH` to `DOCKER:` (for example `DOCKER:rabbitmq01`). This tells the unit tests to run the `rabbitmqctl` commands through Docker, in the format `docker exec rabbitmq01 rabbitmqctl `: +It is also possible to run a RabbitMQ node in a +[Docker](https://www.docker.com/) container. Set the environment variable +`RABBITMQ_RABBITMQCTL_PATH` to `DOCKER:` (for example +`DOCKER:rabbitmq01`). This tells the unit tests to run the `rabbitmqctl` +commands through Docker, in the format `docker exec rabbitmq01 rabbitmqctl +`: -``` shell +```shell docker run -d --hostname rabbitmq01 --name rabbitmq01 -p 15672:15672 -p 5672:5672 rabbitmq:3-management ``` @@ -87,16 +91,17 @@ docker run -d --hostname rabbitmq01 --name rabbitmq01 -p 15672:15672 -p 5672:567 Then, to run the tests use: -``` powershell -# will run tests on .NET Core and .NET Framework -run-test.bat + +### Windows + +```powershell +build.ps1 -RunTests ``` -On MacOS, Linux, BSD use: +### MacOS, Linux, BSD: -``` shell -# will only run tests on .NET Core -run-test.sh +```shell +dotnet test ./Build.csproj ``` ## Running Individual Suites or Test Cases @@ -115,5 +120,5 @@ dotnet test projects/Unit --filter "FullyQualifiedName~RabbitMQ.Client.Unit.Test To run tests targeting .NET 6.0: ``` shell -dotnet test -f ".net6.0" projects/Unit +dotnet test --framework net6.0 projects/Unit ``` diff --git a/build.bat b/build.bat deleted file mode 100644 index 9f1ed2e2ae..0000000000 --- a/build.bat +++ /dev/null @@ -1,4 +0,0 @@ -@ECHO OFF -set DOTNET_CLI_TELEMETRY_OPTOUT=1 -dotnet restore --verbosity=normal .\RabbitMQDotNetClient.sln -dotnet build --verbosity=normal .\RabbitMQDotNetClient.sln diff --git a/build.sh b/build.sh deleted file mode 100755 index 13d8aac5b5..0000000000 --- a/build.sh +++ /dev/null @@ -1,17 +0,0 @@ -#!/bin/sh - -export DOTNET_CLI_TELEMETRY_OPTOUT=1 - -set -e - -if command -v realpath >/dev/null 2>&1 -then - readonly script_dir="$(dirname "$(realpath "$0")")" -else - readonly script_dir="$(cd "$(dirname "$0")" && pwd)" -fi - -cd "$script_dir" - -dotnet restore ./RabbitMQDotNetClient.sln -dotnet build ./RabbitMQDotNetClient.sln diff --git a/run-test.bat b/run-test.bat deleted file mode 100644 index 107a3294d9..0000000000 --- a/run-test.bat +++ /dev/null @@ -1,3 +0,0 @@ -@echo off -set DOTNET_CLI_TELEMETRY_OPTOUT=1 -dotnet test --no-build --logger "console;verbosity=detailed" ./RabbitMQDotNetClient.sln diff --git a/run-test.sh b/run-test.sh deleted file mode 100755 index 56db81db23..0000000000 --- a/run-test.sh +++ /dev/null @@ -1,16 +0,0 @@ -#!/bin/sh - -export DOTNET_CLI_TELEMETRY_OPTOUT=1 - -set -e - -if command -v realpath >/dev/null 2>&1 -then - readonly script_dir="$(dirname "$(realpath "$0")")" -else - readonly script_dir="$(cd "$(dirname "$0")" && pwd)" -fi - -cd "$script_dir" - -dotnet test --no-build --logger 'console;verbosity=detailed' --framework 'net6.0' ./RabbitMQDotNetClient.sln < /dev/null From 0af04dbc24053fd8a7423f8d2ffe560655b23e37 Mon Sep 17 00:00:00 2001 From: Luke Bakken Date: Wed, 3 May 2023 12:40:44 -0700 Subject: [PATCH 4/5] No need to restore after a build --- build.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.ps1 b/build.ps1 index cd9af0751d..92b6137dfd 100644 --- a/build.ps1 +++ b/build.ps1 @@ -14,7 +14,7 @@ Write-Host "Done building." -ForegroundColor "Green" if ($RunTests) { Write-Host "Running tests: Build.csproj traversal (all frameworks)" -ForegroundColor "Magenta" - dotnet test "$PSScriptRoot\Build.csproj" --no-build --logger "console;verbosity=detailed" + dotnet test "$PSScriptRoot\Build.csproj" --no-restore --no-build --logger "console;verbosity=detailed" if ($LastExitCode -ne 0) { Write-Host "Error with tests, aborting build." -Foreground "Red" Exit 1 From b6af935619db112fa7a9ace1cb8311c998bcfb27 Mon Sep 17 00:00:00 2001 From: Luke Bakken Date: Wed, 3 May 2023 13:43:24 -0700 Subject: [PATCH 5/5] Add global.json --- global.json | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 global.json diff --git a/global.json b/global.json new file mode 100644 index 0000000000..47a7fa6036 --- /dev/null +++ b/global.json @@ -0,0 +1,5 @@ +{ + "sdk": { + "allowPrerelease": false + } +}