diff --git a/test/E2E/Start-E2ETest.ps1 b/test/E2E/Start-E2ETest.ps1 index a60f1887..8870ea86 100644 --- a/test/E2E/Start-E2ETest.ps1 +++ b/test/E2E/Start-E2ETest.ps1 @@ -8,6 +8,55 @@ param $UseCoreToolsBuildFromIntegrationTests ) +function NewTaskHubName +{ + param( + [int]$Length = 45 + ) + + <# + Task hubs are identified by a name that conforms to these rules: + - Contains only alphanumeric characters + - Starts with a letter + - Has a minimum length of 3 characters, maximum length of 45 characters + + doc: According to the documentation here https://docs.microsoft.com/en-us/azure/azure-functions/durable/durable-functions-task-hubs?tabs=csharp + #> + + $min = 20 + $max = 45 + + if ($length -lt $min -or $Length -gt $max) + { + throw "Length must be between $min and $max characters. Provided value: $length" + } + + $letters = 'a'..'z' + 'A'..'Z' + $numbers = 0..9 + $alphanumeric = $letters + $numbers + + # First value is a letter + $sb = [System.Text.StringBuilder]::new() + $value = $letters | Get-Random + $sb.Append($value) | Out-Null + + # Add the date and time as part of the name. This way, we can delete older versions. + # Example: 202104251929 is for 2021-04-25:1929 (this value is 12 characters long) + $value = Get-Date -Format "yyyyMMddHHmm" + $sb.Append($value) | Out-Null + + # The remaining of the characters are random alphanumeric values + for ($index = 13; $index -lt $length; $index++) + { + $value = $alphanumeric | Get-Random + $sb.Append($value) | Out-Null + } + + $sb.ToString() +} + +$taskHubName = NewTaskHubName -Length 45 + $FUNC_RUNTIME_VERSION = '3' $NETCOREAPP_VERSION = '3.1' $POWERSHELL_VERSION = '7' @@ -68,6 +117,7 @@ if (-not $UseCoreToolsBuildFromIntegrationTests.IsPresent) Write-Host "Starting Functions Host..." +$Env:TestTaskHubName = $taskHubName $Env:FUNCTIONS_WORKER_RUNTIME = "powershell" $Env:FUNCTIONS_WORKER_RUNTIME_VERSION = $POWERSHELL_VERSION $Env:AZURE_FUNCTIONS_ENVIRONMENT = "development" diff --git a/test/E2E/TestFunctionApp/host.json b/test/E2E/TestFunctionApp/host.json index 8ed8697e..e8396118 100644 --- a/test/E2E/TestFunctionApp/host.json +++ b/test/E2E/TestFunctionApp/host.json @@ -6,5 +6,10 @@ "extensionBundle": { "id": "Microsoft.Azure.Functions.ExtensionBundle", "version": "[2.*, 3.0.0)" - } + }, + "extensions": { + "durableTask": { + "hubName": "%TestTaskHubName%" + } + } }