Developer-Dashboard

 view release on metacpan or  search on metacpan

integration/windows/run-strawberry-smoke.ps1  view on Meta::CPAN


    $collectorOutput = & $Dashboard collector output windows.collector | Out-String
    if ($LASTEXITCODE -ne 0) {
        throw "dashboard collector output windows.collector failed with exit code $LASTEXITCODE"
    }
    Invoke-AssertContains -Text $collectorOutput -Fragment "collector-ok" -Label "collector output"

    Write-PhaseStatus -Phase "run-collector-timeout-check"
    $timeoutMarker = "DD389_TIMEOUT_" + [guid]::NewGuid().ToString("N")
    $timeoutProbe = Join-Path $tempRoot "collector-timeout-probe.pl"
    $timeoutProbeSource = @'
use strict;
use warnings;
use File::Spec;
use Time::HiRes qw(time);
use Developer::Dashboard::Collector;
use Developer::Dashboard::CollectorRunner;
use Developer::Dashboard::FileRegistry;
use Developer::Dashboard::PathRegistry;

my ( $home, $marker ) = @ARGV;
my $paths = Developer::Dashboard::PathRegistry->new(
    home => $home,
    workspace_roots => [ File::Spec->catdir( $home, 'workspace' ) ],
);
my $runner = Developer::Dashboard::CollectorRunner->new(
    collectors => Developer::Dashboard::Collector->new( paths => $paths ),
    files      => Developer::Dashboard::FileRegistry->new( paths => $paths ),
    paths      => $paths,
);
my $started = time();
my $result = $runner->run_once(
    {
        name       => 'windows.timeout.collector',
        command    => q{Write-Output timeout-start; Start-Process powershell.exe -ArgumentList '-NoLogo','-NoProfile','-Command','Start-Sleep -Seconds 60 # } . $marker . q{' -Wait},
        cwd        => $home,
        timeout_ms => 1000,
    }
);
printf "elapsed_ms=%.0f exit_code=%d timed_out=%d stdout=%s\n",
  ( time() - $started ) * 1000,
  $result->{exit_code},
  $result->{timed_out},
  $result->{stdout};
exit( $result->{exit_code} == 124 && $result->{timed_out} ? 0 : 1 );
'@
    Set-Content -Path $timeoutProbe -Value $timeoutProbeSource -Encoding UTF8
    $timeoutProof = & $Perl $timeoutProbe $homeRoot $timeoutMarker | Out-String
    if ($LASTEXITCODE -ne 0) {
        throw "Windows collector timeout probe failed with exit code $LASTEXITCODE`: $timeoutProof"
    }
    if ($timeoutProof -notmatch 'elapsed_ms=(\d+)\s+exit_code=124\s+timed_out=1') {
        throw "Windows collector timeout proof was incomplete: $timeoutProof"
    }
    $timeoutElapsed = [int]$Matches[1]
    if ($timeoutElapsed -gt 10000) {
        throw "Windows collector timeout exceeded bounded cleanup grace: $timeoutElapsed ms"
    }
    $timeoutDescendants = @(Get-CimInstance Win32_Process | Where-Object { $_.CommandLine -like "*$timeoutMarker*" })
    if ($timeoutDescendants.Count -ne 0) {
        throw "Timed-out Windows collector left $($timeoutDescendants.Count) marked descendant process(es) alive"
    }
    Write-Host "Windows collector timeout $timeoutProof marker_processes=$($timeoutDescendants.Count)"

    Invoke-LoggedCommand -Label "dashboard auth add-user helper smoke-pass-123" -Command @($Dashboard, "auth", "add-user", "helper", "smoke-pass-123")

    Write-PhaseStatus -Phase "start-dashboard-server"
    $serve = Start-Process -FilePath $Dashboard -ArgumentList @("serve", "--host", "127.0.0.1", "--port", $Port) -PassThru -NoNewWindow
    try {
        Write-PhaseStatus -Phase "wait-for-http"
        Wait-HttpOk -Url "http://127.0.0.1:$Port/"

        $root = Invoke-WebRequest -UseBasicParsing -Uri "http://127.0.0.1:$Port/"
        Invoke-AssertContains -Text $root.Content -Fragment "textarea" -Label "root editor"

        $page = Invoke-WebRequest -UseBasicParsing -Uri "http://127.0.0.1:$Port/app/sample"
        Invoke-AssertContains -Text $page.Content -Fragment "windows-smoke-page" -Label "saved page"

        $ajaxRoute = '/ajax/hello.pl?type=text'
        Write-Host "saved Ajax route: $ajaxRoute"
        $ajax = Invoke-WebRequest -UseBasicParsing -Uri ("http://127.0.0.1:$Port" + $ajaxRoute)
        Write-Host "saved Ajax status: $($ajax.StatusCode)"
        Write-Host "saved Ajax body:"
        Write-Host $ajax.Content
        Invoke-AssertContains -Text $ajax.Content -Fragment "ajax-ok" -Label "saved Ajax"

        $browser = Get-BrowserBinary
        if ($browser) {
            Write-PhaseStatus -Phase "browser-dom-check"
            $dom = Get-DumpDom -Browser $browser -Url "http://127.0.0.1:$Port/app/sample" -UserDataDir $profileRoot
            Invoke-AssertContains -Text $dom -Fragment "hello from windows smoke" -Label "browser DOM"
        }
        else {
            Write-Warning "No Edge or Chrome browser found; skipping Windows browser DOM smoke"
        }
    }
    finally {
        if ($serve -and -not $serve.HasExited) {
            Stop-Process -Id $serve.Id -Force
            $serve.WaitForExit()
        }
    }
}
finally {
    Pop-Location
    if (-not $KeepTemp) {
        try {
            Remove-Item -Recurse -Force $tempRoot
        }
        catch {
            Write-Warning ("Unable to remove Windows smoke temp root {0}: {1}" -f $tempRoot, $_.Exception.Message)
        }
    }
}

Write-PhaseStatus -Phase "success"
Write-Host "Windows Strawberry Perl smoke passed"

<#
__END__



( run in 0.730 second using v1.01-cache-2.11-cpan-14f38c9f855 )