Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement per-service test setup #1985

Merged
merged 102 commits into from
Jan 15, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
102 commits
Select commit Hold shift + click to select a range
e581529
Implement per-service test setup
LarryOsterman Jan 9, 2025
d9cdb8e
Second try for package location
LarryOsterman Jan 9, 2025
b34e7c2
Third try for package location
LarryOsterman Jan 9, 2025
7865d00
Fourth try for package location
LarryOsterman Jan 9, 2025
3f73951
Fifth try for package location
LarryOsterman Jan 9, 2025
dbfbb07
Sixth try for package location
LarryOsterman Jan 9, 2025
67f8e8b
Seventh try for package location
LarryOsterman Jan 9, 2025
ea900ba
Next try for package location
LarryOsterman Jan 9, 2025
af0a237
Next try for package location
LarryOsterman Jan 9, 2025
d6c9e31
Next try for package location
LarryOsterman Jan 9, 2025
a55d07e
Next try for package location
LarryOsterman Jan 9, 2025
e18b4ac
Next try for package location
LarryOsterman Jan 9, 2025
a0ed88d
Next try for package location
LarryOsterman Jan 9, 2025
11cf159
Next try for package location
LarryOsterman Jan 9, 2025
5661c76
Next try for package location
LarryOsterman Jan 9, 2025
3982ad6
Next try for package location
LarryOsterman Jan 9, 2025
58f681d
Next try for package location
LarryOsterman Jan 9, 2025
217e9aa
Next try for package location
LarryOsterman Jan 9, 2025
96e6287
Next try for package location
LarryOsterman Jan 9, 2025
4165061
Next try for package location
LarryOsterman Jan 9, 2025
b5ce96f
Next try for package location
LarryOsterman Jan 9, 2025
153c267
Need to check for OSX as well as Linux on chmod
LarryOsterman Jan 9, 2025
bc18572
For reasons the URL parsing doesn't work unless you're in the azure-a…
LarryOsterman Jan 9, 2025
ac3c1d1
Try heath's suggestion w.r.t. the URL parameter
LarryOsterman Jan 9, 2025
9de7977
Fix execution of cleanup script
LarryOsterman Jan 9, 2025
c601de7
Print out TestAmqpBroker process names
LarryOsterman Jan 9, 2025
4e30a29
Try running test broker from broker directory directly
LarryOsterman Jan 9, 2025
bbf828e
Split out windows and linux launching
LarryOsterman Jan 10, 2025
c2acb39
Split out windows and linux launching
LarryOsterman Jan 10, 2025
6ebe406
Split out windows and linux launching 3
LarryOsterman Jan 10, 2025
35d2a9a
Split out windows and linux launching 4
LarryOsterman Jan 10, 2025
3ae0fb4
Removed reference to broker Executable
LarryOsterman Jan 10, 2025
308e0b3
Try a new dotnet run invocation
LarryOsterman Jan 10, 2025
1a01b94
Try a different .net invocation
LarryOsterman Jan 10, 2025
7f5409c
Diagnostics for stopping the test job.
LarryOsterman Jan 10, 2025
496b5bb
Align windows and other platforms
LarryOsterman Jan 10, 2025
c818c25
Different test command line.
LarryOsterman Jan 10, 2025
e11dfc5
Try not using the -- separator
LarryOsterman Jan 10, 2025
aeb5a48
Try not using the -- separator 2
LarryOsterman Jan 10, 2025
61217fa
Add dotnet publish step
LarryOsterman Jan 10, 2025
38f7d4e
Fixed typo in dotnet exec command line; Dump attributes for test broker
LarryOsterman Jan 10, 2025
ef2a6e5
Moved test scripts to per-package directory
LarryOsterman Jan 10, 2025
c825315
Fixed missing trailing quote
LarryOsterman Jan 10, 2025
3901901
Fixed script path after changes
LarryOsterman Jan 10, 2025
963925e
Simpler path commit
LarryOsterman Jan 10, 2025
26e3a27
Fixed relative path to eng directory
LarryOsterman Jan 10, 2025
e46c1ee
Use Path.Combine instead of concatenation
LarryOsterman Jan 10, 2025
09e6b95
Use Path.Combine correctly
LarryOsterman Jan 10, 2025
04f6c1e
Create working directory if it does not exist
LarryOsterman Jan 10, 2025
461b8d8
Create directory correctly
LarryOsterman Jan 10, 2025
84721d2
Stop using dotnet run to launch broker
LarryOsterman Jan 10, 2025
e2d4b0f
Added diagnostics on stopping the test script
LarryOsterman Jan 10, 2025
0da5871
Test configuration is per-package so don't need to check the package
LarryOsterman Jan 10, 2025
d3c64c5
Don't check working directory parameter and stop checking package nam…
LarryOsterman Jan 10, 2025
54a3e0e
Refined checks for job state
LarryOsterman Jan 10, 2025
8df5430
Diagnostics
LarryOsterman Jan 10, 2025
9414a88
More start job diagnostics
LarryOsterman Jan 10, 2025
b744fb1
Another command line broker fix
LarryOsterman Jan 10, 2025
e118920
Another try at finding job output
LarryOsterman Jan 10, 2025
af6d7e3
Try adding a path to the start of the test amqp broker command line
LarryOsterman Jan 10, 2025
18e668e
Sleep after job startup to see state at launch
LarryOsterman Jan 10, 2025
b431483
Try self-contained builds
LarryOsterman Jan 10, 2025
5ee2066
Use selfcontained package directory
LarryOsterman Jan 10, 2025
d5b8694
Forgot to delete a line
LarryOsterman Jan 10, 2025
ca113e0
Removed a couple of variables that are no longer needed
LarryOsterman Jan 10, 2025
3f0f936
Fixed variable name
LarryOsterman Jan 10, 2025
3c7d1b2
AMQP Connection tests use test broker
LarryOsterman Jan 10, 2025
7689185
Ooops, accidentally broke the connect with error test :).
LarryOsterman Jan 10, 2025
9f5476b
Tests now run (fixed silly typo)
LarryOsterman Jan 10, 2025
3c9e2a6
PR feedback
LarryOsterman Jan 13, 2025
07c2c19
Undid some PR feedback; pin to release 2.6.9 of the azure-amqp reposi…
LarryOsterman Jan 13, 2025
0190ce9
Added test instructions; Fixed git clone command
LarryOsterman Jan 13, 2025
dbe0a0f
Added back manual dotnet restore
LarryOsterman Jan 13, 2025
f6239e4
azure-amqp version 2.6.9 (most recent release) apparently references …
LarryOsterman Jan 13, 2025
c8ddc34
Fixed git clone variable
LarryOsterman Jan 13, 2025
e467d3e
Removed individual build steps and just use dotnet publish
LarryOsterman Jan 13, 2025
a43a4cb
Reduced references to Job IDs in script output
LarryOsterman Jan 13, 2025
c896357
Try to run TestAmqpBroker without dotnet publish
LarryOsterman Jan 13, 2025
e980b96
TestAmqpBroker try 2
LarryOsterman Jan 13, 2025
b218756
Try TestAmqpBroker with no extension and a runtimeconfig file
LarryOsterman Jan 13, 2025
720fc68
Not sure what's up right now
LarryOsterman Jan 13, 2025
5534819
Removed --runtimeconfig switch
LarryOsterman Jan 13, 2025
9c70bc6
Try .Dll extension
LarryOsterman Jan 13, 2025
4c2eeaf
Try .Dll extension
LarryOsterman Jan 13, 2025
ec78db9
another attempt at dotnet exec command line.
LarryOsterman Jan 14, 2025
bed6ff4
Try rolling forward to the latest dotnet
LarryOsterman Jan 14, 2025
1c29e22
Fixed roll-forward switch name
LarryOsterman Jan 14, 2025
51fada4
Applyh --roll-forward to dotnet exec not dotnet build
LarryOsterman Jan 14, 2025
2d433fa
Roll forward as a property
LarryOsterman Jan 14, 2025
59ab7c4
Simplify expression to confirm test broker is still running
LarryOsterman Jan 14, 2025
fc3b503
Removed test package parameter from test scripts
LarryOsterman Jan 15, 2025
0586642
Removed package name parameter to test script invocation
LarryOsterman Jan 15, 2025
ee939cc
PR feedback
LarryOsterman Jan 15, 2025
6e024a3
Use hotfix branch, not main
LarryOsterman Jan 15, 2025
a0d5efc
Use master branch after all
LarryOsterman Jan 15, 2025
e25e523
Run example tests in parallel
LarryOsterman Jan 15, 2025
b65b594
Changed output level of connection ignored error
LarryOsterman Jan 15, 2025
6894273
Don't log test cleanup script name
LarryOsterman Jan 15, 2025
2fc0ea0
Fixed slash direction in powershell snippet
LarryOsterman Jan 15, 2025
12be0e7
Fixed dotnet name.
LarryOsterman Jan 15, 2025
12cfb85
Cleaned up language around running the test scripts
LarryOsterman Jan 15, 2025
4cd4702
Removed one spurious .net reference
LarryOsterman Jan 15, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion SUPPORT.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ To ensure the relevance and manageability of our issue queue, we have an automat

- Take a look at the [Azure SDK blog](https://devblogs.microsoft.com/azure-sdk/).
- Search for similar issues in [our GitHub repository](https://github.com/Azure/azure-sdk-for-rust/issues)
- Ask a question on [StackOverflow](https://stackoverflow.com/questions/tagged/azure-sdk-rust) and tag it with azure-sdk-.net
- Ask a question on [StackOverflow](https://stackoverflow.com/questions/tagged/azure-sdk-rust) and tag it with azure-sdk-rust
- Share or upvote feature requests on [Feedback Page](https://feedback.azure.com/forums/34192--general-feedback).
- Ask a question on [Twitter](https://twitter.com/AzureSDK)
- Ask a question at [Microsoft Q&A](https://learn.microsoft.com/answers/products/azure?WT.mc_id=Portal-Microsoft_Azure_Support&product=all)
Expand Down
20 changes: 20 additions & 0 deletions eng/scripts/Test-Packages.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,18 @@ $env:RUSTFLAGS = "-Dwarnings"
foreach ($package in $packagesToTest) {
Push-Location ([System.IO.Path]::Combine($RepoRoot, $package.DirectoryPath))
try {
$packageDirectory = ([System.IO.Path]::Combine($RepoRoot, $package.DirectoryPath))

$setupScript = Join-Path $packageDirectory "Test-Setup.ps1"
if (Test-Path $setupScript) {
Write-Host "`n`nRunning test setup script for package: '$($package.Name)'`n"
Invoke-LoggedCommand $setupScript
if (!$? -ne 0) {
Write-Error "Test setup script failed for package: '$($package.Name)'"
exit 1
}
}

Write-Host "`n`nTesting package: '$($package.Name)'`n"

Invoke-LoggedCommand "cargo +$Toolchain build --keep-going"
Expand All @@ -68,6 +80,14 @@ foreach ($package in $packagesToTest) {

Invoke-LoggedCommand "cargo +$Toolchain test --doc --no-fail-fast"
Write-Host "`n`n"

$cleanupScript = Join-Path $packageDirectory "Test-Cleanup.ps1"
if (Test-Path $cleanupScript) {
Write-Host "`n`nRunning test cleanup script for package: '$($package.Name)'`n"
Invoke-LoggedCommand $cleanupScript
# We ignore the exit code of the cleanup script.

}
}
finally {
Pop-Location
Expand Down
70 changes: 58 additions & 12 deletions sdk/core/azure_core_amqp/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,69 @@ NOTE: THIS IS NOT A GENERAL PURPOSE AMQP LIBRARY AND SHOULD NOT BE USED AS SUCH.

This crate is part of a collection of crates: for more information please refer to [https://github.com/azure/azure-sdk-for-rust](https://github.com/azure/azure-sdk-for-rust).

## Example
## Testing the AMQP Client.

```rust,no_run
use azure_messaging::*;
The AMQP package is tested using the standard `cargo test` command line:

#[tokio::main]
async fn main() -> azure_core::Result<()> {
let eventhubs_namespace = std::env::var("AZURE_EVENTHUB_NAMESPACE").expect("missing AZURE_EVENTHUB_NAMESPACE");
```bash
cargo test --package azure_core_amqp --all-features
```

Certain AMQP tests requires that there be a running AMQP broker on the machine at the time of the test (the tests will run without the broker, the relevant tests will just be skipped).

One existing AMQP broker is the "TestAMQPBroker" from the azure-amqp GitHub repository.

To launch the TestAMQPBroker, there are two ways of installing and running the TestAmqpBroker, Scripted and Manual.

### Scripted Broker Install
Running the broker from a script requires that you first [install Powershell](https://learn.microsoft.com/powershell/scripting/install/installing-powershell?view=powershell-7.4).
From a running powershell instance, run the powershell script in the sdk/core/azure_core_amqp directory:

```
./sdk/core/azure_core_amqp/Test-Setup.ps1
```

This will download the TestAmqpBroker, build it and launch the executable in the background.

Note that this requires that you have the [.NET SDK](https://dot.net/download) installed on your machine.

You can then run the azure_core_amqp package tests.

Once you have finished running your tests, you run:

```
./sdk/core/azure_core_amqp/Test-Cleanup.ps1
```

let client = ProducerClient::new(
eventhubs_namespace, credential,
)?;
which will terminate the test broker.

client.send_event("hello world").await?;
### Manual Broker Install
For Manual testing, first clone the azure-amqp repository to a local directory:

Ok(())
}
```bash
cd <Test Working Directory>
git clone https://github.com/Azure/azure-amqp
```

Alternately, you can clone to a specific release in the azure-amqp repository:

```
git clone https://github.com/Azure/azure-amqp.git --branch hotfix
```

Set an environment variable the test AMQP broker should listen on:

```powershell
$env:TEST_BROKER_ADDRESS = 'amqp://127.0.0.1:25672'
```

And launch the test broker:

```powershell
cd azure-amqp/test/TestAmqpBroker
dotnet run -- $env:TEST_BROKER_ADDRESS
```

Now, when you run the cargo tests, the networking functionality of the AMQP APIs will be executed.

License: MIT
21 changes: 21 additions & 0 deletions sdk/core/azure_core_amqp/Test-Cleanup.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
# cspell: ignore JOBID

. "$PSScriptRoot\..\..\..\eng\common\scripts\common.ps1"

Write-Host "Test Broker output:"
Receive-Job -Id $env:TEST_BROKER_JOBID

# Check if the test broker job is still running
$job = Get-Job -Id $env:TEST_BROKER_JOBID
if ($job.State -ne "Running") {
Write-Host "Test broker terminated unexpectedly."
exit 1
}

# Stop the test broker job started in Test-Setup.ps1
Write-Host "Stopping test broker"
Stop-Job -Id $env:TEST_BROKER_JOBID
Remove-Job -Id $env:TEST_BROKER_JOBID
Write-Host "Test broker stopped."
69 changes: 69 additions & 0 deletions sdk/core/azure_core_amqp/Test-Setup.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
# cspell: ignore JOBID depsfile


# Load common ES scripts
. "$PSScriptRoot\..\..\..\eng\common\scripts\common.ps1"

# Create the test binary *outside* the repo root to avoid polluting the repo.
$WorkingDirectory = ([System.IO.Path]::Combine($RepoRoot, "../TestArtifacts"))

# Create the working directory if it does not exist.
Write-Host "Using Working Directory $WorkingDirectory"

if (-not (Test-Path $WorkingDirectory)) {
Write-Host "Working directory does not exist, creating working directory: $WorkingDirectory"
New-Item -ItemType Directory -Path $WorkingDirectory
}

Write-Host "Setting current directory to working directory: $WorkingDirectory"
Push-Location -Path $WorkingDirectory

# Clone and build the Test Amqp Broker.
try {

$repositoryUrl = "https://github.com/Azure/azure-amqp.git"
# We would like to use the "hotfix" branch because that is current, but unfortunately it references System.Net.Security version 4.0.0
$repositoryBranch = "master"
$cloneCommand = "git clone $repositoryUrl --branch $repositoryBranch"

Write-Host "Cloning repository from $repositoryUrl..."
Invoke-LoggedCommand $cloneCommand

Set-Location -Path "./azure-amqp/test/TestAmqpBroker"

Invoke-LoggedCommand "dotnet build -p RollForward=LatestMajor --framework net6.0"
if (!$? -ne 0) {
Write-Error "Failed to build TestAmqpBroker."
exit 1
}

Write-Host "Test broker built successfully."

# now that the Test broker has been built, launch the broker on a local address.
$env:TEST_BROKER_ADDRESS = 'amqp://127.0.0.1:25672'

Write-Host "Starting test broker listening on ${env:TEST_BROKER_ADDRESS} ..."

Set-Location -Path $WorkingDirectory/azure-amqp/bin/Debug/TestAmqpBroker/net6.0

$job = dotnet exec ./TestAmqpBroker.dll ${env:TEST_BROKER_ADDRESS} /headless &

$env:TEST_BROKER_JOBID = $job.Id

Write-Host "Waiting for test broker to start..."
Start-Sleep -Seconds 3

Write-Host "Job Output after wait:"
Receive-Job $job.Id

$job = Get-Job -Id $env:TEST_BROKER_JOBID
if ($job.State -ne "Running") {
Write-Host "Test broker failed to start."
exit 1
}
}
finally {
Pop-Location
}
11 changes: 6 additions & 5 deletions sdk/core/azure_core_amqp/examples/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
// 1. Clone the repository:
// git clone https://github.com/Azure/azure-amqp
// 2. Build the project:
// dotnet restore
// dotnet build
// 3. Run the broker:
// dotnet run --project .\test\TestAmqpBroker\TestAmqpBroker.csproj --framework net462 amqp://localhost:25672
Expand Down Expand Up @@ -74,8 +73,10 @@ async fn amqp_connection_close_with_error() {
pub async fn main() {
tracing_subscriber::fmt::init();

amqp_connection_open().await;
amqp_connection_open_with_error().await;
amqp_connection_close().await;
amqp_connection_close_with_error().await;
tokio::join!(
amqp_connection_open(),
amqp_connection_open_with_error(),
amqp_connection_close(),
amqp_connection_close_with_error()
);
}
50 changes: 30 additions & 20 deletions sdk/core/azure_core_amqp/src/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -245,50 +245,58 @@ mod tests {
);
}

// Tests disabled until we have a way to start the AMQP test broker in CI
#[allow(dead_code)]
mod disabled {
use super::super::*;

// #[tokio::test]
async fn amqp_connection_open() {
tracing_subscriber::fmt::init();
#[tokio::test]
async fn amqp_connection_open() {
let address = std::env::var("TEST_BROKER_ADDRESS");
if address.is_ok() {
let connection = AmqpConnection::new();

let url = Url::parse("amqp://localhost:25672").unwrap();
let url = Url::parse(&address.unwrap()).unwrap();
connection
.open("test".to_string(), url, None)
.await
.unwrap();
} else {
println!("TEST_BROKER_ADDRESS is not set. Skipping test.");
}
}

// #[tokio::test]
async fn amqp_connection_open_with_error() {
tracing_subscriber::fmt::try_init().unwrap();
#[tokio::test]
async fn amqp_connection_open_with_error() {
let address = std::env::var("TEST_BROKER_ADDRESS");
if address.is_ok() {
let connection = AmqpConnection::new();
let url = Url::parse("amqp://localhost:32767").unwrap();
assert!(connection
.open("test".to_string(), url, None)
.await
.is_err());
} else {
println!("TEST_BROKER_ADDRESS is not set. Skipping test.");
}
}

// #[tokio::test]
async fn amqp_connection_close() {
#[tokio::test]
async fn amqp_connection_close() {
let address = std::env::var("TEST_BROKER_ADDRESS");
if address.is_ok() {
let connection = AmqpConnection::new();
let url = Url::parse("amqp://localhost:25672").unwrap();
let url = Url::parse(&address.unwrap()).unwrap();
connection
.open("test".to_string(), url, None)
.await
.unwrap();
connection.close().await.unwrap();
} else {
println!("TEST_BROKER_ADDRESS is not set. Skipping test.");
}
}

// #[tokio::test]
async fn amqp_connection_close_with_error() {
tracing_subscriber::fmt::try_init().unwrap();
#[tokio::test]
async fn amqp_connection_close_with_error() {
let address = std::env::var("TEST_BROKER_ADDRESS");
if address.is_ok() {
let connection = AmqpConnection::new();
let url = Url::parse("amqp://localhost:25672").unwrap();
let url = Url::parse(&address.unwrap()).unwrap();
connection
.open("test".to_string(), url, None)
.await
Expand All @@ -306,6 +314,8 @@ mod tests {
assert!(err.to_string().contains("Internal error."));
}
}
} else {
println!("TEST_BROKER_ADDRESS is not set. Skipping test.");
}
}
}
4 changes: 2 additions & 2 deletions sdk/core/azure_core_amqp/src/fe2o3/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use async_std::sync::Mutex;
use azure_core::{Result, Url};
use fe2o3_amqp::connection::ConnectionHandle;
use std::{borrow::BorrowMut, sync::OnceLock};
use tracing::{debug, info, warn};
use tracing::{debug, warn};

use super::error::{AmqpConnection, AmqpOpen};

Expand Down Expand Up @@ -166,7 +166,7 @@ impl AmqpConnectionApis for Fe2o3AmqpConnection {
Ok(_) => Ok(()),
Err(e) => match e.0 {
fe2o3_amqp::connection::Error::TransportError(e) => {
info!(
debug!(
"Transport error closing connection with error: {:?} - ignored",
e
);
Expand Down
1 change: 1 addition & 0 deletions sdk/core/azure_core_amqp/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ use std::fmt::Debug;

// AMQP Settle mode:
// https://docs.oasis-open.org/amqp/core/v1.0/os/amqp-core-transport-v1.0-os.html#type-sender-settle-mode

const AMQP_SENDER_SETTLE_MODE_UNSETTLED: isize = 0;
const AMQP_SENDER_SETTLE_MODE_SETTLED: isize = 1;
const AMQP_SENDER_SETTLE_MODE_MIXED: isize = 2;
Expand Down