LoginVSI automates performance testing and I need to automate LoginVSI.
By calling this one function, I can invoke a single LoginVSI test.
At a high-level, the test does the following
Prepare test
These items simply get the environment ready for a LoginVSI test. It includes doing the following:
- Delete any old test files on the LoginVSI server
- Create log file if one does not exist
- Disable RDP connection warning message when connecting to my launcher machine
- Start LoginVSI Session Monitor if not already running
- Connect to LoginVSI Launcher
Start LoginVSI test
One thing I added was to monitor the LoginVSI debug file directory for the current test. If I had a test set to run for 60 minutes, the test wouldn’t stop until 60 minutes elapsed. However, if the test failed, I want the script to stop the current test so I don’t waste a lot of time.
To get this to work, I need to monitor the LoginVSI debug folder for the current test. If a JPG file appears, that is an error screen capture.
I typically have a series of tests running over the course of many days and need a fast way to see if those tests succeeded or failed. To do this, I append the success or failure result to a simple log file.
At a high-level, the LoginVSI test does the following
- Start LoginVSI test
- Every minute, look if LoginVSI test failed. If so, stop current test
- When test completes, write “Test Success” or “Test Failure” in the log file
function Invoke-VSITest { param( [string] $vsishare, # \\servername\sharename [string] $DomainName, [string] $VSIProfileName, # foldername in the LoginVSI profile $vsishare\_VSI_Profiles [string] $launchers, #server name for LoginVSI launcher machine [string] $TestName, # must be unique [int] $Duration, # Number of minutes to run test [string] $MasterImage, # name of the master image used for the test [string] $VSILogFile # Path and filename for a text file ) # Clean up old test files Write-host (date -Format hh:mm:ss) - Deleting old test files if any -ForegroundColor Yellow -Verbose Remove-Item ($vsishare + "\*.IsActiveTest") -recurse Remove-Item ($vsishare +"\*.PrepTest") -recurse # Prepare log file does not exist, create If((Test-Path $VSILogFile) -eq $false) { New-Item $VSILogFile -type file } # Bypassing identity of the remote computer verification reg add "HKEY_CURRENT_USER\Software\Microsoft\Terminal Server Client" /v "AuthenticationLevelOverride" /t "REG_DWORD" /d 0 /f # Checking if Session Monitor is running. $ProcessActive = Get-Process SessionMonitor -ErrorAction SilentlyContinue if($ProcessActive -eq $null) { # Starting the Session Monitor. Write-host (date -Format hh:mm:ss) - Starting the Session Monitor -ForegroundColor Yellow -Verbose $SessionMointor = Join-Path -ChildPath \_VSI_Binaries\Launcher\SessionMonitor.exe -Path $vsishare Invoke-Expression -Command $SessionMointor } else { # Session Monitor is already running. Write-host (date -Format hh:mm:ss) - Session Monitor is already running -ForegroundColor Yellow -Verbose } # Start Launcher Workflow Invoke-Expression ($vsishare + "\_VSI_Binaries\Connectors\RDPConnect.exe /server $launchers /user $domainname\Launcher-v4 /password Password! /nowarning /display 1600x900" ) # Wait 30 seconds for launcher to settle Start-Sleep -s 30 # Begin test Write-host (date -Format hh:mm:ss) - Starting the Login VSI Test $testname -ForegroundColor Yellow -Verbose Invoke-Expression ($vsishare + "\_VSI_ManagementConsole\LoginVSICMD.exe -testname $Testname -profile $VSIProfileName") Write-host (date -Format hh:mm:ss) - Sleeping for $Duration minutes while test executes -ForegroundColor Green -Verbose # while test is running, do the following every minute for($count = 1; $count -le $Duration; $count++) { Start-sleep -s 60 Write-host (date -Format hh:mm:ss) - Test $Testname running. Time Elapsed - $count of $Duration minutes -ForegroundColor Yellow -Verbose # test if LoginVSI encountered an error # Find newest log directory. This will be the currently running test $VSILogDir = (Get-ChildItem -Path $vsishare\_VSI_Logfiles | sort LastwriteTime | Select -last 1).Name # Look for the error log folders. If(Test-path -Path $VSIShare\_VSI_Logfiles\$VSILogDir\Debug\ErrorShots) { # Look for a JPG file. This is an error screenshot that means the test failed $debugfiles = get-childitem -path $VSIShare\_VSI_Logfiles\$VSILogDir\Debug\ErrorShots Foreach($DebugFile in $debugfiles) { If($Debugfile.name -like "*-E.jpg") { Write-host (date -Format hh:mm:ss) - ERROR with Test $Testname -ForegroundColor Red -Verbose # Append result of current test $time = date -format "yyyy-M-dd hh:mm:ss" add-content -path $VSILogFile "[FAILURE] $time - $MasterImage Test $Testname failed at $count minutes" # Test failed. Exit from test Return } } } } $time = date -format "yyyy-M-dd hh:mm:ss" Write-host $time - SUCCESS - Test $Testname is Complete! -ForegroundColor Green -Verbose # Append result of current test to log file add-content -path $VSILogFile "[SUCCESS] $time - $MasterImage Test $Testname is Complete!" }