Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
66 changes: 38 additions & 28 deletions sdk/core/azure-core-amqp/Test-Setup.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,22 @@
# Licensed under the MIT License.
# cspell: ignore JOBID depsfile


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

if ($IsMacOS) {
Write-Host "AMQP tests are not supported on macOS. Skipping test setup."
exit 0
}

if ($true) {
Comment thread
LarryOsterman marked this conversation as resolved.
Write-Host "Disabling AMQP Test Broker temporarily"
exit 0
}

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

# Create the working directory if it does not exist.
Write-Host "Using Working Directory $WorkingDirectory"
Expand All @@ -22,52 +33,51 @@ 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"
$repositoryDir = [System.IO.Path]::Combine($WorkingDirectory, "azure-amqp")
if (Test-Path $repositoryDir) {
Write-Host "Removing previously cloned repository: $repositoryDir"
Remove-Item $repositoryDir -Force -Recurse | Out-Null
}

$repositoryUrl = "https://github.com/Azure/azure-amqp.git"
$repositoryHash = "111de654e170de3ab6cefe150043458c67b6660d"
$cloneCommand = "git clone $repositoryUrl --revision $repositoryHash --depth=1"

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

Set-Location -Path "./azure-amqp/test/TestAmqpBroker"
Comment thread
LarryOsterman marked this conversation as resolved.

Invoke-LoggedCommand "dotnet build -p RollForward=LatestMajor --framework net8.0"
if (!$? -ne 0) {
Invoke-LoggedCommand "dotnet build --framework net10.0"
if (-not $?) {
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.
Write-Host "Starting test broker listening on ${env:TEST_BROKER_ADDRESS} ..."
$env:TEST_BROKER_ADDRESS = 'amqp://localhost:25672'

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

# $job = dotnet exec ./TestAmqpBroker.dll ${env:TEST_BROKER_ADDRESS} /headless &
$Process = Start-Process -NoNewWindow -FilePath "dotnet" -ArgumentList "exec ./TestAmqpBroker.dll ${env:TEST_BROKER_ADDRESS} /headless" -PassThru -RedirectStandardOutput $WorkingDirectory/test-broker.log -RedirectStandardError $WorkingDirectory/test-broker-error.log

if (!$? -ne 0) {
Write-Error "Failed to start TestAmqpBroker."
exit 1
}

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

# Note that we cannot use `dotnet run -f` here because the TestAmqpBroker relies on args[0] being the broker address.
# If we use `dotnet run -f`, the first argument is the csproj file.
# Instead, we use `dotnet exec` to run the compiled DLL directly.
# This allows us to pass the broker address as the first argument.
Set-Location -Path $WorkingDirectory/azure-amqp/bin/Debug/TestAmqpBroker/net10.0
$process = Start-Process -FilePath "dotnet" -ArgumentList "exec", "./TestAmqpBroker.dll", "${env:TEST_BROKER_ADDRESS}", "/headless" -PassThru

$env:TEST_BROKER_JOBID = $Process.Id
$env:TEST_BROKER_JOBID = $process.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
# }
$process = Get-Process -Id $env:TEST_BROKER_JOBID -ErrorAction SilentlyContinue
if (-not $process -or $process.HasExited) {
Write-Host "Test broker failed to start."
exit 1
}
}
finally {
Pop-Location
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@
# Load common ES scripts
. "$PSScriptRoot\..\..\..\eng\common\scripts\common.ps1"

if ($true) {
Write-Host "Disabling AMQP Test Broker temporarily"
exit 0
}

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ namespace Azure { namespace Core { namespace Amqp { namespace Tests {
auto testBrokerUrl = Azure::Core::_internal::Environment::GetVariable("TEST_BROKER_ADDRESS");
if (testBrokerUrl.empty())
{
GTEST_FATAL_FAILURE_("Could not find required environment variable TEST_BROKER_ADDRESS");
GTEST_SKIP_("Could not find required environment variable TEST_BROKER_ADDRESS");
}
GTEST_LOG_(INFO) << "Use broker address: " << testBrokerUrl;
Azure::Core::Url brokerUrl(testBrokerUrl);
Expand Down
2 changes: 1 addition & 1 deletion sdk/core/azure-core-amqp/test/ut/connection_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ namespace Azure { namespace Core { namespace Amqp { namespace Tests {
auto testBrokerUrl = Azure::Core::_internal::Environment::GetVariable("TEST_BROKER_ADDRESS");
if (testBrokerUrl.empty())
{
GTEST_FATAL_FAILURE_("Could not find required environment variable TEST_BROKER_ADDRESS");
GTEST_SKIP_("Could not find required environment variable TEST_BROKER_ADDRESS");
}
Azure::Core::Url brokerUrl(testBrokerUrl);
Azure::Core::Amqp::_internal::ConnectionOptions connectionOptions;
Expand Down
2 changes: 1 addition & 1 deletion sdk/core/azure-core-amqp/test/ut/management_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ namespace Azure { namespace Core { namespace Amqp { namespace Tests {
auto testBrokerUrl = Azure::Core::_internal::Environment::GetVariable("TEST_BROKER_ADDRESS");
if (testBrokerUrl.empty())
{
GTEST_FATAL_FAILURE_("Could not find required environment variable TEST_BROKER_ADDRESS");
GTEST_SKIP_("Could not find required environment variable TEST_BROKER_ADDRESS");
}
Azure::Core::Url brokerUrl(testBrokerUrl);
m_brokerEndpoint = brokerUrl;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ namespace Azure { namespace Core { namespace Amqp { namespace Tests {
auto testBrokerUrl = Azure::Core::_internal::Environment::GetVariable("TEST_BROKER_ADDRESS");
if (testBrokerUrl.empty())
{
GTEST_FATAL_FAILURE_("Could not find required environment variable TEST_BROKER_ADDRESS");
GTEST_SKIP_("Could not find required environment variable TEST_BROKER_ADDRESS");
}
Azure::Core::Url brokerUrl(testBrokerUrl);
m_brokerEndpoint = brokerUrl;
Expand Down
2 changes: 1 addition & 1 deletion sdk/core/azure-core-amqp/test/ut/session_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ namespace Azure { namespace Core { namespace Amqp { namespace Tests {
auto testBrokerUrl = Azure::Core::_internal::Environment::GetVariable("TEST_BROKER_ADDRESS");
if (testBrokerUrl.empty())
{
GTEST_FATAL_FAILURE_("Could not find required environment variable TEST_BROKER_ADDRESS");
GTEST_SKIP_("Could not find required environment variable TEST_BROKER_ADDRESS");
}
Azure::Core::Url brokerUrl(testBrokerUrl);
m_brokerEndpoint = brokerUrl;
Expand Down
Loading
Loading