Skip to content

Commit

Permalink
More fixes and refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
nibanks committed Jan 11, 2024
1 parent 25fd4d4 commit cf641c4
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 35 deletions.
25 changes: 18 additions & 7 deletions scripts/secnetperf-helpers.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -10,26 +10,37 @@ function Write-GHError($msg) {

# Waits for a remote job to be ready based on looking for a particular string in
# the output.
function Wait-ForRemoteReady {
param ($Job, $Matcher)
function Start-RemoteServer {
param ($Command)
$Job = Invoke-Command -Session $Session -ScriptBlock { $Using:Command } -AsJob
$StopWatch = [system.diagnostics.stopwatch]::StartNew()
$Started = $false
while ($StopWatch.ElapsedMilliseconds -lt 10000) {
$CurrentResults = Receive-Job -Job $Job -Keep -ErrorAction Continue
if (![string]::IsNullOrWhiteSpace($CurrentResults)) {
$DidMatch = $CurrentResults -match $Matcher
$DidMatch = $CurrentResults -match "Started!"
if ($DidMatch) {
return $true
$Started = $true
break;
}
}
Start-Sleep -Seconds 0.1 | Out-Null
}
return $false
if (!$Started) {
Stop-Job -Job $Job
$RemoteResult = Receive-Job -Job $Job -ErrorAction Stop
$RemoteResult = $RemoteResult -join "`n"
Write-GHError "Server failed to start! Output:"
Write-Output $RemoteResult
return $null
}
return $Job
}

# Sends a special UDP packet to tell the remote secnetperf to shutdown, and then
# waits for the job to complete. Finally, it returns the console output of the
# job.
function Wait-ForRemote {
function Stop-RemoteServer {
param ($Job, $ErrorAction = "Stop")
# Ping side-channel socket on 9999 to tell the app to die
$Socket = New-Object System.Net.Sockets.UDPClient
Expand All @@ -47,7 +58,7 @@ function Wait-ForRemote {

Stop-Job -Job $Job | Out-Null
$RetVal = Receive-Job -Job $Job -ErrorAction $ErrorAction
return $RetVal -join "`n"
$RetVal = $RetVal -join "`n"
}

# Invokes all the secnetperf tests.
Expand Down
34 changes: 6 additions & 28 deletions scripts/secnetperf.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -138,19 +138,8 @@ if (!$isWindows) {

# Run secnetperf on the server.
Write-Output "Starting secnetperf server..."
$Job = Invoke-Command -Session $Session -ScriptBlock {
& "$Using:RemoteDir/$Using:SecNetPerfPath -exec:maxtput"
} -AsJob

# Wait for the server to start.
Write-Output "Waiting for server to start..."
$ReadyToStart = Wait-ForRemoteReady -Job $Job -Matcher "Started!"
if (!$ReadyToStart) {
Stop-Job -Job $Job
$RemoteResult = Receive-Job -Job $Job -ErrorAction Stop
$RemoteResult = $RemoteResult -join "`n"
Write-GHError "Server failed to start! Output:"
Write-Output $RemoteResult
$Job = Start-RemoteServer "$RemoteDir/$SecNetPerfPath -exec:maxtput"
if ($null -eq $Job) {
throw "Server failed to start!"
}

Expand Down Expand Up @@ -213,23 +202,12 @@ $SQL += Invoke-SecnetperfTest $maxtputIds $maxtput $exe $json $LogProfile
# Start and restart the SecNetPerf server without maxtput.
Write-Host "Restarting server without maxtput..."
Write-Host "`nStopping server. Server Output:"
$RemoteResults = Wait-ForRemote $Job
$RemoteResults = Stop-RemoteServer $Job
Write-Host $RemoteResults.ToString()

Write-Host "Starting server back up again..."
$Job = Invoke-Command -Session $Session -ScriptBlock {
& "$Using:RemoteDir/$Using:SecNetPerfPath -exec:lowlat"
} -AsJob

# Wait for the server to start.
Write-Output "Waiting for server to start..."
$ReadyToStart = Wait-ForRemoteReady -Job $Job -Matcher "Started!"
if (!$ReadyToStart) {
Stop-Job -Job $RemoteJob
$RemoteResult = Receive-Job -Job $Job -ErrorAction $ErrorAction
$RemoteResult = $RemoteResult -join "`n"
Write-GHError "Server failed to start! Output:"
Write-Output $RemoteResult
$Job = Start-RemoteServer "$RemoteDir/$SecNetPerfPath -exec:lowlat"
if ($null -eq $Job) {
throw "Server failed to start!"
}

Expand All @@ -243,7 +221,7 @@ $SQL += Invoke-SecnetperfTest $lowlatIds $lowlat $exe $json $LogProfile

# Kill the server process.
Write-Output "`nStopping server. Server Output:"
$RemoteResults = Wait-ForRemote $Job
$RemoteResults = Stop-RemoteServer $Job
Write-Output $RemoteResults.ToString()

# if ($LogProfile -ne "" -and $LogProfile -ne "NULL") { # TODO: Linux back slash works?
Expand Down

0 comments on commit cf641c4

Please sign in to comment.