janhoy commented on code in PR #3810:
URL: https://github.com/apache/solr/pull/3810#discussion_r2480536256


##########
solr/packaging/powershell-tests/Zk.Tests.ps1:
##########
@@ -42,6 +42,81 @@ BeforeAll {
   $script:ZK_PORT = if ($env:ZK_PORT) { $env:ZK_PORT } else { "9983" }
   $script:SOLR_PORT = if ($env:SOLR_PORT) { $env:SOLR_PORT } else { "8983" }
 
+  # Check if Solr is already running
+  $solrAlreadyRunning = $false
+  try {
+    $response = Invoke-WebRequest -Uri "http://localhost:$SOLR_PORT/solr/"; 
-UseBasicParsing -TimeoutSec 2 -ErrorAction SilentlyContinue
+    if ($response.StatusCode -eq 200) {
+      $solrAlreadyRunning = $true
+      Write-Host "Solr is already running on port $SOLR_PORT"
+    }
+  } catch {
+    $solrAlreadyRunning = $false
+  }

Review Comment:
   A bit disaapointing that while the BATS `setup_file()` function is a 
tw-liner, Pester needs 100 lines for the same? Why? Guess we could pull some of 
the verbose check-if-solr-running and start-solr out in Util scripts?



##########
solr/packaging/powershell-tests/Zk.Tests.ps1:
##########
@@ -42,6 +42,81 @@ BeforeAll {
   $script:ZK_PORT = if ($env:ZK_PORT) { $env:ZK_PORT } else { "9983" }
   $script:SOLR_PORT = if ($env:SOLR_PORT) { $env:SOLR_PORT } else { "8983" }
 
+  # Check if Solr is already running
+  $solrAlreadyRunning = $false
+  try {
+    $response = Invoke-WebRequest -Uri "http://localhost:$SOLR_PORT/solr/"; 
-UseBasicParsing -TimeoutSec 2 -ErrorAction SilentlyContinue
+    if ($response.StatusCode -eq 200) {
+      $solrAlreadyRunning = $true
+      Write-Host "Solr is already running on port $SOLR_PORT"
+    }
+  } catch {
+    $solrAlreadyRunning = $false
+  }
+
+  $script:SolrStartedByTests = $false
+
+  # Start Solr if it's not already running
+  if (-not $solrAlreadyRunning) {
+    Write-Host "Starting Solr in cloud mode..."
+
+    # Start Solr with embedded ZooKeeper using Start-Process to run 
asynchronously
+    $startArgs = @("start", "-p", "$SOLR_PORT")
+    Write-Host "Running: $SolrCmd $($startArgs -join ' ')"
+
+    # Use Start-Job with cmd.exe to properly parse arguments and maintain 
process hierarchy
+    $solrJob = Start-Job -ScriptBlock {
+        param($cmd, $argString)
+        cmd /c "`"$cmd`" $argString" 2>&1
+    } -ArgumentList $SolrCmd, $startArgs
+
+    # Wait a bit for Solr to start
+    Start-Sleep -Seconds 5

Review Comment:
   Is this necessary? Our start script waits until solr is ready before 
`bin\solr.cmd start` exits?



##########
solr/packaging/powershell-tests/Zk.Tests.ps1:
##########
@@ -65,6 +140,25 @@ BeforeAll {
   }
 }
 
+AfterAll {
+  # Stop Solr only if we started it
+  if ($script:SolrStartedByTests) {
+    Write-Host "Stopping Solr..."
+    $stopArgs = @("stop", "-p", $script:SOLR_PORT)

Review Comment:
   Linux test uses `--all` to stop all solr instances. And I assume that if a 
`bin\solr.cmd stop --all` command fails, it will fail the test, so probably no 
need to baby-sit the stop process here?



##########
solr/packaging/powershell-tests/Zk.Tests.ps1:
##########
@@ -42,6 +42,81 @@ BeforeAll {
   $script:ZK_PORT = if ($env:ZK_PORT) { $env:ZK_PORT } else { "9983" }
   $script:SOLR_PORT = if ($env:SOLR_PORT) { $env:SOLR_PORT } else { "8983" }
 
+  # Check if Solr is already running
+  $solrAlreadyRunning = $false
+  try {
+    $response = Invoke-WebRequest -Uri "http://localhost:$SOLR_PORT/solr/"; 
-UseBasicParsing -TimeoutSec 2 -ErrorAction SilentlyContinue
+    if ($response.StatusCode -eq 200) {
+      $solrAlreadyRunning = $true
+      Write-Host "Solr is already running on port $SOLR_PORT"
+    }
+  } catch {
+    $solrAlreadyRunning = $false
+  }
+
+  $script:SolrStartedByTests = $false
+
+  # Start Solr if it's not already running
+  if (-not $solrAlreadyRunning) {
+    Write-Host "Starting Solr in cloud mode..."
+
+    # Start Solr with embedded ZooKeeper using Start-Process to run 
asynchronously
+    $startArgs = @("start", "-p", "$SOLR_PORT")
+    Write-Host "Running: $SolrCmd $($startArgs -join ' ')"
+
+    # Use Start-Job with cmd.exe to properly parse arguments and maintain 
process hierarchy
+    $solrJob = Start-Job -ScriptBlock {
+        param($cmd, $argString)
+        cmd /c "`"$cmd`" $argString" 2>&1
+    } -ArgumentList $SolrCmd, $startArgs
+
+    # Wait a bit for Solr to start
+    Start-Sleep -Seconds 5
+
+    Write-Host "Solr starting on port $SOLR_PORT (Job ID: $($solrJob.Id))"
+
+    # Check if there were any immediate errors
+    $jobOutput = Receive-Job -Job $solrJob -Keep
+    if ($jobOutput) {
+        Write-Host "Solr output: $jobOutput"
+    }
+
+    $script:SolrStartedByTests = $true
+
+    # Wait for Solr to be ready (max 60 seconds)
+    Write-Host "Waiting for Solr to be ready..."
+    $maxWaitTime = 60
+    $waitInterval = 2
+    $elapsed = 0
+    $solrReady = $false
+
+    while ($elapsed -lt $maxWaitTime) {
+      Start-Sleep -Seconds $waitInterval
+      $elapsed += $waitInterval
+
+      try {
+        $response = Invoke-WebRequest -Uri "http://localhost:$SOLR_PORT/solr/"; 
-UseBasicParsing -TimeoutSec 5 -ErrorAction Stop

Review Comment:
   Again, why would this be neccessary on the Windows side when it is not on 
the linux side? If `bin\solr.cmd start -c` does not return until solr is ready 
and listening, we can shave off this?
   
   https://github.com/apache/solr/blob/main/solr/bin/solr.cmd#L1140-L1148



##########
solr/packaging/powershell-tests/Zk.Tests.ps1:
##########
@@ -42,6 +42,81 @@ BeforeAll {
   $script:ZK_PORT = if ($env:ZK_PORT) { $env:ZK_PORT } else { "9983" }
   $script:SOLR_PORT = if ($env:SOLR_PORT) { $env:SOLR_PORT } else { "8983" }
 
+  # Check if Solr is already running
+  $solrAlreadyRunning = $false
+  try {
+    $response = Invoke-WebRequest -Uri "http://localhost:$SOLR_PORT/solr/"; 
-UseBasicParsing -TimeoutSec 2 -ErrorAction SilentlyContinue
+    if ($response.StatusCode -eq 200) {
+      $solrAlreadyRunning = $true
+      Write-Host "Solr is already running on port $SOLR_PORT"
+    }
+  } catch {
+    $solrAlreadyRunning = $false
+  }
+
+  $script:SolrStartedByTests = $false
+
+  # Start Solr if it's not already running
+  if (-not $solrAlreadyRunning) {
+    Write-Host "Starting Solr in cloud mode..."
+
+    # Start Solr with embedded ZooKeeper using Start-Process to run 
asynchronously
+    $startArgs = @("start", "-p", "$SOLR_PORT")
+    Write-Host "Running: $SolrCmd $($startArgs -join ' ')"

Review Comment:
   The `bin/solr` script looks for `SOLR_PORT` env.variable and uses it by 
default if `-p` is not set. Is not the same true for the `bin\solr.cmd` script? 
If so, why? Also, before the test start, gradle finds an available port so we 
know that nothing is running on `SOLR_PORT`. Why do we then need to check if 
solr is running? Are we afraid that one of the other Pester tests have had an 
unclean exit?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to