From a48fe277982eb5f64075709d4b86f2d2064ec86d Mon Sep 17 00:00:00 2001 From: Dagfinn Olsen Date: Thu, 28 Nov 2024 10:13:24 +0100 Subject: [PATCH 1/6] make test run on windows --- .../workflows/taxreport-loadtest-ondemand.yml | 24 ++++++ .../generate-tokens/src/generate-tokens.ps1 | 85 +++++++++++++++++++ .../tax-report/src/tax-report.js | 1 + 3 files changed, 110 insertions(+) create mode 100755 performance-tests/generate-tokens/src/generate-tokens.ps1 diff --git a/.github/workflows/taxreport-loadtest-ondemand.yml b/.github/workflows/taxreport-loadtest-ondemand.yml index 9d401dc..ada3a6d 100644 --- a/.github/workflows/taxreport-loadtest-ondemand.yml +++ b/.github/workflows/taxreport-loadtest-ondemand.yml @@ -34,6 +34,30 @@ jobs: - name: Checkout uses: actions/checkout@v4 + - name: Generate tokens (Linux/Mac) + if: runner.os != 'Windows' + working-directory: ./performance-tests/tax-report/src + run: ../../generate-tokens/src/generate-tokens.sh ../../generate-tokens/src ${{ inputs.limit }} + env: + API_ENVIRONMENT: ${{ secrets.YTENVIRONMENT }} + TOKEN_GENERATOR_USERNAME: ${{ secrets.TOKENGENUSER }} + TOKEN_GENERATOR_PASSWORD: ${{ secrets.TOKENGENPWD }} + + - name: Generate tokens (Windows) + if: runner.os == 'Windows' + working-directory: ./performance-tests/tax-report/src + run: pwsh ../../generate-tokens/src/generate-tokens.ps1 ` + -testdatafilepath ../../generate-tokens/src ` + -limit ${{ inputs.limit }} ` + -API_ENVIRONMENT ${{ secrets.YTENVIRONMENT }} ` + -TOKEN_GENERATOR_USERNAME ${{ secrets.TOKENGENUSER }} ` + -TOKEN_GENERATOR_PASSWORD ${{ secrets.TOKENGENPWD }} + env: + API_ENVIRONMENT: ${{ secrets.YTENVIRONMENT }} + TOKEN_GENERATOR_USERNAME: ${{ secrets.TOKENGENUSER }} + TOKEN_GENERATOR_PASSWORD: ${{ secrets.TOKENGENPWD }} + + - name: Generate tokens working-directory: ./performance-tests/tax-report/src run: ../../generate-tokens/src/generate-tokens.sh ../../generate-tokens/src ${{ inputs.limit }} diff --git a/performance-tests/generate-tokens/src/generate-tokens.ps1 b/performance-tests/generate-tokens/src/generate-tokens.ps1 new file mode 100755 index 0000000..73f0b1f --- /dev/null +++ b/performance-tests/generate-tokens/src/generate-tokens.ps1 @@ -0,0 +1,85 @@ +param ( + [Parameter(Mandatory=$true)] + [string]$TOKEN_GENERATOR_USERNAME, + [Parameter(Mandatory=$true)] + [string]$TOKEN_GENERATOR_PASSWORD, + [Parameter(Mandatory=$true)] + [string]$API_ENVIRONMENT, + [Parameter(Mandatory=$true)] + [string]$testdatafilepath, + [Parameter(Mandatory=$true)] + [int]$limit +) + +# Check if required environment variables are set +if (-not $TOKEN_GENERATOR_USERNAME -or -not $TOKEN_GENERATOR_PASSWORD -or -not $API_ENVIRONMENT) { + Write-Host "Error: TOKEN_GENERATOR_USERNAME, TOKEN_GENERATOR_PASSWORD, and API_ENVIRONMENT must be set" + exit 1 +} + +# Function to display usage information +function Usage { + Write-Host "Usage: $PSCommandPath -testdatafilepath -limit " + Write-Host " : Path to the test data files" + Write-Host " : limit number of tokens to generate. 0 means generate all" + exit 1 +} + +# Validate arguments +#if ($args.Length -ne 2) { +# Usage +#} + +$tokengenuser = $env:TOKEN_GENERATOR_USERNAME +$tokengenpasswd = $env:TOKEN_GENERATOR_PASSWORD + +$env = "" +switch ($API_ENVIRONMENT) { + "at21" { $env = "at21" } + "tt02" { $env = "tt02" } + "yt01" { $env = "yt01" } + default { + Write-Host "Error: Unknown api environment $API_ENVIRONMENT" + exit 1 + } +} + +$enduser_datafile = "$testdatafilepath/data-$API_ENVIRONMENT.csv" +$enduser_tokenfile = ".data-with-tokens.csv" + +if (-not (Test-Path $enduser_datafile)) { + Write-Host "Error: Input file not found: $enduser_datafile" + exit 1 +} + +"userId,partyId,ssn,token" | Out-File -FilePath $enduser_tokenfile -Encoding utf8 +$status = $? +if ($status -ne 1) { + Write-Host "Error: Failed to write header to file $enduser_tokenfile" + exit 1 +} + +$generated = 0 +Import-Csv -Path $enduser_datafile | ForEach-Object { + if ($limit -gt 0 -and $generated -ge $limit) { + break + } + $partyId = $_.partyId + $userId = $_.userId + $ssn = $_.ssn + + $url = "https://altinn-testtools-token-generator.azurewebsites.net/api/GetPersonalToken?env=$env&userId=$userId&partyId=$partyId&pid=$ssn&ttl=3600" + $token = Invoke-RestMethod -Uri $url -Method Get -Credential (New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $tokengenuser, (ConvertTo-SecureString -String $tokengenpasswd -AsPlainText -Force)) + #$token = Invoke-RestMethod -Uri $url -Headers @{Authorization=("Basic " + [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes("${tokengenuser}:${tokengenpasswd}")))} -Method Get + if (-not $?) { + Write-Host "Error: Failed to generate personal token for: $ssn, $scopes" + continue + } + "$userId,$partyId,$ssn,$token" | Out-File -FilePath $enduser_tokenfile -Append -Encoding utf8 + $status = $? + if ($status -ne 1) { + Write-Host "Error: Failed to write personal token to file for: $ssn $status" + } else { + $generated++ + } +} diff --git a/performance-tests/tax-report/src/tax-report.js b/performance-tests/tax-report/src/tax-report.js index 5454116..e34a9e2 100644 --- a/performance-tests/tax-report/src/tax-report.js +++ b/performance-tests/tax-report/src/tax-report.js @@ -64,6 +64,7 @@ export function submit_tax(data, id) { // 1. Create instance var instance_resp = create_instance(data, id); + console.log(instance_resp.body); if (instance_resp.status != 201) return; // 2. Uplod tax report From 3e06515f2e60978e004f4d8bf18fdde011e4ccea Mon Sep 17 00:00:00 2001 From: Dagfinn Olsen Date: Thu, 28 Nov 2024 10:19:26 +0100 Subject: [PATCH 2/6] make test run on windows --- performance-tests/generate-tokens/src/generate-tokens.ps1 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/performance-tests/generate-tokens/src/generate-tokens.ps1 b/performance-tests/generate-tokens/src/generate-tokens.ps1 index 73f0b1f..b9be2d1 100755 --- a/performance-tests/generate-tokens/src/generate-tokens.ps1 +++ b/performance-tests/generate-tokens/src/generate-tokens.ps1 @@ -69,8 +69,8 @@ Import-Csv -Path $enduser_datafile | ForEach-Object { $ssn = $_.ssn $url = "https://altinn-testtools-token-generator.azurewebsites.net/api/GetPersonalToken?env=$env&userId=$userId&partyId=$partyId&pid=$ssn&ttl=3600" - $token = Invoke-RestMethod -Uri $url -Method Get -Credential (New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $tokengenuser, (ConvertTo-SecureString -String $tokengenpasswd -AsPlainText -Force)) - #$token = Invoke-RestMethod -Uri $url -Headers @{Authorization=("Basic " + [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes("${tokengenuser}:${tokengenpasswd}")))} -Method Get + #$token = Invoke-RestMethod -Uri $url -Method Get -Credential (New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $tokengenuser, (ConvertTo-SecureString -String $tokengenpasswd -AsPlainText -Force)) + $token = Invoke-RestMethod -Uri $url -Headers @{Authorization=("Basic " + [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes("${tokengenuser}:${tokengenpasswd}")))} -Method Get if (-not $?) { Write-Host "Error: Failed to generate personal token for: $ssn, $scopes" continue From 044ef35df25dcc039a204a60f4e52948b5a42465 Mon Sep 17 00:00:00 2001 From: Dagfinn Olsen Date: Thu, 28 Nov 2024 10:54:28 +0100 Subject: [PATCH 3/6] make test run on windows --- performance-tests/generate-tokens/src/generate-tokens.ps1 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/performance-tests/generate-tokens/src/generate-tokens.ps1 b/performance-tests/generate-tokens/src/generate-tokens.ps1 index b9be2d1..14d7351 100755 --- a/performance-tests/generate-tokens/src/generate-tokens.ps1 +++ b/performance-tests/generate-tokens/src/generate-tokens.ps1 @@ -30,8 +30,8 @@ function Usage { # Usage #} -$tokengenuser = $env:TOKEN_GENERATOR_USERNAME -$tokengenpasswd = $env:TOKEN_GENERATOR_PASSWORD +$tokengenuser = $TOKEN_GENERATOR_USERNAME +$tokengenpasswd = $TOKEN_GENERATOR_PASSWORD $env = "" switch ($API_ENVIRONMENT) { From 553e233ec42c7f51badaf58b9be2060c68b52db0 Mon Sep 17 00:00:00 2001 From: Dagfinn Olsen Date: Thu, 28 Nov 2024 10:56:09 +0100 Subject: [PATCH 4/6] make test run on windows --- .github/workflows/taxreport-loadtest-ondemand.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/taxreport-loadtest-ondemand.yml b/.github/workflows/taxreport-loadtest-ondemand.yml index ada3a6d..0ae8aed 100644 --- a/.github/workflows/taxreport-loadtest-ondemand.yml +++ b/.github/workflows/taxreport-loadtest-ondemand.yml @@ -26,6 +26,7 @@ on: options: - "'ubuntu-latest'" - "['self-hosted', 'macOS', 'X64']" + - "['self-hosted', 'X64', 'Windows']" jobs: run-taxreport-ondemand: From 1088c496b26b5b23e65ed6392b985d84c415818e Mon Sep 17 00:00:00 2001 From: Dagfinn Olsen Date: Thu, 28 Nov 2024 15:08:00 +0100 Subject: [PATCH 5/6] fix runners, added mac os --- .../workflows/taxreport-loadtest-ondemand.yml | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/.github/workflows/taxreport-loadtest-ondemand.yml b/.github/workflows/taxreport-loadtest-ondemand.yml index 0ae8aed..a00598c 100644 --- a/.github/workflows/taxreport-loadtest-ondemand.yml +++ b/.github/workflows/taxreport-loadtest-ondemand.yml @@ -25,8 +25,8 @@ on: default: "'ubuntu-latest'" options: - "'ubuntu-latest'" - - "['self-hosted', 'macOS', 'X64']" - - "['self-hosted', 'X64', 'Windows']" + - "'windows-latest'" + - "'macOS-latest'" jobs: run-taxreport-ondemand: @@ -58,15 +58,6 @@ jobs: TOKEN_GENERATOR_USERNAME: ${{ secrets.TOKENGENUSER }} TOKEN_GENERATOR_PASSWORD: ${{ secrets.TOKENGENPWD }} - - - name: Generate tokens - working-directory: ./performance-tests/tax-report/src - run: ../../generate-tokens/src/generate-tokens.sh ../../generate-tokens/src ${{ inputs.limit }} - env: - API_ENVIRONMENT: ${{ secrets.YTENVIRONMENT }} - TOKEN_GENERATOR_USERNAME: ${{ secrets.TOKENGENUSER }} - TOKEN_GENERATOR_PASSWORD: ${{ secrets.TOKENGENPWD }} - - name: Setup K6 uses: grafana/setup-k6-action@v1 @@ -78,8 +69,8 @@ jobs: env: K6_WEB_DASHBOARD: true K6_WEB_DASHBOARD_EXPORT: html-report.html - K6_CLOUD_TOKEN: ${{ secrets.K6_CLOUD_TOKEN }} - K6_CLOUD_PROJECT_ID: ${{ secrets.K6_CLOUD_PROJECT_ID }} + #K6_CLOUD_TOKEN: ${{ secrets.K6_CLOUD_TOKEN }} + #K6_CLOUD_PROJECT_ID: ${{ secrets.K6_CLOUD_PROJECT_ID }} serviceowner: ${{ secrets.OWNER }} - name: Upload summary html report From 68a0be8c2cc7715f3a97308dd3b4f7c09681fa06 Mon Sep 17 00:00:00 2001 From: Dagfinn Olsen Date: Thu, 28 Nov 2024 15:32:59 +0100 Subject: [PATCH 6/6] remove debug print --- performance-tests/tax-report/src/tax-report.js | 1 - 1 file changed, 1 deletion(-) diff --git a/performance-tests/tax-report/src/tax-report.js b/performance-tests/tax-report/src/tax-report.js index e34a9e2..5454116 100644 --- a/performance-tests/tax-report/src/tax-report.js +++ b/performance-tests/tax-report/src/tax-report.js @@ -64,7 +64,6 @@ export function submit_tax(data, id) { // 1. Create instance var instance_resp = create_instance(data, id); - console.log(instance_resp.body); if (instance_resp.status != 201) return; // 2. Uplod tax report