Skip to content

Commit

Permalink
some refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
davidmrdavid committed Oct 1, 2024
1 parent 055c2e1 commit 3d6ecfc
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public static async Task<HttpResponseData> HttpStartOOMOrchestrator(

// Function input comes from the request content.
string instanceId = await client.ScheduleNewOrchestrationInstanceAsync(
nameof(OOMOrchestrator), instanceId: "OOMOrchestrator");
nameof(OOMOrchestrator));

logger.LogInformation("Started orchestration with ID = '{instanceId}'.", instanceId);

Expand All @@ -129,7 +129,7 @@ public static async Task<HttpResponseData> HttpStartProcessExitOrchestrator(

// Function input comes from the request content.
string instanceId = await client.ScheduleNewOrchestrationInstanceAsync(
nameof(ProcessExitOrchestrator), instanceId: "ProcessExitOrchestrator");
nameof(ProcessExitOrchestrator));

logger.LogInformation("Started orchestration with ID = '{instanceId}'.", instanceId);

Expand All @@ -148,7 +148,7 @@ public static async Task<HttpResponseData> HttpStartTimeoutOrchestrator(

// Function input comes from the request content.
string instanceId = await client.ScheduleNewOrchestrationInstanceAsync(
nameof(TimeoutOrchestrator), instanceId: "TimeoutOrchestrator");
nameof(TimeoutOrchestrator));

logger.LogInformation("Started orchestration with ID = '{instanceId}'.", instanceId);

Expand Down
109 changes: 65 additions & 44 deletions test/SmokeTests/OOProcSmokeTests/DotNetIsolated/run-smoke-tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -6,55 +6,76 @@ param(
[string]$HttpStartPath
)

# This delay a bit excessive, but we want to make sure the Functions runtime is up and running before we start the orchestration
# This number was determined, through trial and error, to be a safe amount of time to wait
Start-Sleep -Seconds 40

try {
# Make sure the Functions runtime is up and running
$pingUrl = "http://localhost:7071/admin/host/ping"
Write-Host "Pinging app at $pingUrl to ensure the host is healthy" -ForegroundColor Yellow
Invoke-RestMethod -Method Post -Uri "http://localhost:7071/admin/host/ping"
Write-Host "Host is healthy!" -ForegroundColor Green

# Note that any HTTP protocol errors (e.g. HTTP 4xx or 5xx) will cause an immediate failure
$startOrchestrationUri = "http://localhost:7071/$HttpStartPath"
Write-Host "Starting a new orchestration instance via POST to $startOrchestrationUri..." -ForegroundColor Yellow

$result = Invoke-RestMethod -Method Post -Uri $startOrchestrationUri
Write-Host "Started orchestration with instance ID '$($result.id)'!" -ForegroundColor Yellow
Write-Host "Waiting for orchestration to complete..." -ForegroundColor Yellow

$retryCount = 0
$success = $false
$statusUrl = $result.statusQueryGetUri

while ($retryCount -lt 65) {
$result = Invoke-RestMethod -Method Get -Uri $statusUrl
$runtimeStatus = $result.runtimeStatus
Write-Host "Orchestration is $runtimeStatus" -ForegroundColor Yellow
Write-Host $result

if ($result.runtimeStatus -eq "Completed") {
$success = $true
Do {
$testIsRunning = $true;

# Start the functions host if it's not running already.
# Then give it 40 seconds to start up. This is a long wait, but from experience the CI can be slow to start up the host.
$isFunctionsHostRunning = (Get-Process -Name func -ErrorAction SilentlyContinue)
if ($isFunctionsHostRunning -eq $null) {
Write-Host "Starting the Functions host..." -ForegroundColor Yellow

# The '&' operator is used to run the command in the background
cd ./test/SmokeTests/OOProcSmokeTests/DotNetIsolated && func host start --port 7071 &

Write-Host "Waiting for the Functions host to start up..." -ForegroundColor Yellow
Start-Sleep -Seconds 40
}


try {
# Make sure the Functions runtime is up and running
$pingUrl = "http://localhost:7071/admin/host/ping"
Write-Host "Pinging app at $pingUrl to ensure the host is healthy" -ForegroundColor Yellow
Invoke-RestMethod -Method Post -Uri "http://localhost:7071/admin/host/ping"
Write-Host "Host is healthy!" -ForegroundColor Green

# Note that any HTTP protocol errors (e.g. HTTP 4xx or 5xx) will cause an immediate failure
$startOrchestrationUri = "http://localhost:7071/$HttpStartPath"
Write-Host "Starting a new orchestration instance via POST to $startOrchestrationUri..." -ForegroundColor Yellow

$result = Invoke-RestMethod -Method Post -Uri $startOrchestrationUri
Write-Host "Started orchestration with instance ID '$($result.id)'!" -ForegroundColor Yellow
Write-Host "Waiting for orchestration to complete..." -ForegroundColor Yellow

$retryCount = 0
$success = $false
$statusUrl = $result.statusQueryGetUri

while ($retryCount -lt 65) {
$result = Invoke-RestMethod -Method Get -Uri $statusUrl
$runtimeStatus = $result.runtimeStatus
Write-Host "Orchestration is $runtimeStatus" -ForegroundColor Yellow
Write-Host $result
break

if ($result.runtimeStatus -eq "Completed") {
$success = $true
$testIsRunning = $false
break
}

cd ./test/SmokeTests/OOProcSmokeTests/DotNetIsolated && func host start --port 7071 &
Start-Sleep -Seconds 30
$retryCount = $retryCount + 1
}

cd ./test/SmokeTests/OOProcSmokeTests/DotNetIsolated && func host start --port 7071 &
Start-Sleep -Seconds 30
$retryCount = $retryCount + 1
if ($success -eq $false) {
throw "Orchestration didn't complete in time! :("
}
} catch {
Write-Host "An error occurred:" -ForegroundColor Red
Write-Host $_ -ForegroundColor Red

# Rethrow the original exception
throw
}

if ($success -eq $false) {
throw "Orchestration didn't complete in time! :("
}
} catch {
Write-Host "An error occurred:" -ForegroundColor Red
Write-Host $_ -ForegroundColor Red
# This delay a bit excessive, but we want to make sure the Functions runtime is up and running before we start the orchestration
# This number was determined, through trial and error, to be a safe amount of time to wait
Start-Sleep -Seconds 40
} while ($testIsRunning -eq $true)


# Rethrow the original exception
throw
}

Write-Host "Success!" -ForegroundColor Green

0 comments on commit 3d6ecfc

Please sign in to comment.