I have test written in artillery.io (yaml file):
config:
target: "http://localhost:3000/"
phases:
- duration: "{{duration}}" #//10
arrivalRate: 1
scenarios:
- name: "Emit an event"
engine: socketio
flow:
- loop:
- emit:
channel: "chat
message"
data: "{{data}}"
- think: 1
count: "{{count}}"
I have written powershell script for automatic run many scenarios:
##ArtilleryIo platform test
$no_of_requests = 1,2,25,100,500
$no_of_users = 1,2,10,100,500,1000
$content_length = 1,2,10,100,500,1000,10000
$args=""
foreach($request in $no_of_requests){
foreach($len in $content_length)
{
foreach($user in $no_of_users)
{
try{
$integer_len = [int]$len
$generatedData = -join ((65..90)+(97..122) | Get-Random -Count $integer_len | % {[char]$_})
$path = "artillery run --output test-run-report.json C:\Users\patryk\socket_io\server\tests\load-test.yml"
$waitForExit = $true
$psi = new-object "Diagnostics.ProcessStartInfo"
$psi.FileName = "artillery"
$integer_user = [int]$user
$integer_req = [int]$request
$pathToSave = "C:\Users\patryk\socket_io\server\tests\req_$request\len_$len-user_$user"
$dirComm = "mkdir $pathToSave"
#Write-Host "dir comm: " $dirComm
Invoke-Expression $dirComm
$args = ' run --variables ''{ \"duration\": '+$integer_user+', \"data\": \"'+$generatedData+'\", \"count\": '+$integer_req+ '}'' --output '+$pathToSave+'\test-run-report.json C:\Users\patryk\socket_io\server\tests\load-test.yml' #-f $integer_user,$generatedData,$integer_req,$pathToSave
$psi.Arguments = $args
$proc = [Diagnostics.Process]::Start($psi)
if ( $waitForExit ) {
#Write-Host $PWD
$proc.WaitForExit();
$stdout = $proc.StandardOutput.ReadToEnd()
$stderr = $proc.StandardError.ReadToEnd()
Write-Host "stdout: $stdout"
Write-Host "stderr: $stderr"
}
}
catch {
Write-Host "An error occurred:"
Write-Host $_
Write-Host "Error occured with: user: $user, data: $generatedData, noOfRequests: $request, args: $args"
}
}
}
}
During executing my script in see in the console:
An error occurred:
You cannot call a method on a null-valued expression.
Error occured with: user: 1, data: b, noOfRequests: 1, args: run --variables '{ \"duration\": 1, \"data\": \"b\", \"count\": 1}' --output C:\Users\patryk\socket_io\server\tests\req_1\len_1-user_1\test-run-report.json C:\Users\patryk\socket_io\server\tests\load-test.yml
but if i paste command artillery run --variables '{ \"duration\": 1, \"data\": \"b\", \"count\": 1}' --output C:\Users\patryk\socket_io\server\tests\req_1\len_1-user_1\test-run-report.json C:\Users\patryk\socket_io\server\tests\load-test.yml
directly to console and execute my test works.
Can you tell me what is wrong? I have read that this exception indicates that something is null (like null pointer exception) but still couldn't fix it.
Regards
Your primary problem is that you neglected to set the $psi.RedirectStandardOut
and $psi.RedirectStandardError
properties to $true
, which resulted in no output getting collected, in turn causing $proc.StandardOutput
and $proc.StandardError
to be $null
, which therefore caused the error you saw.
Secondarily, $args = ' run --variables ''{ \"dur...
cannot work, because on process command lines only "..."
rather than '...'
quoting may generally be used.
$args
was changed to $arguments
, because $args
is an automatic (built-in) variable in PowerShell:$arguments = @"
run --variables "{ \"duration\": $integer_user, \"data\": \"$generatedData\", \"count\": $integer_req }" --output $pathToSave\test-run-report.json C:\Users\patryk\socket_io\server\tests\load-test.yml
"@