From eecc0efc4ee86ae722cd450738be1574078952eb Mon Sep 17 00:00:00 2001
From: Alex Pott <alex.a.pott@googlemail.com>
Date: Wed, 23 Oct 2019 10:07:22 +0100
Subject: [PATCH] =?UTF-8?q?Issue=20#3088447=20by=20Mile23,=20heddn,=20Krzy?=
 =?UTF-8?q?sztof=20Doma=C5=84ski:=20BuildTestBase->standUpServer=20always?=
 =?UTF-8?q?=20starts=20new=20server?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 .../BuildTests/Framework/BuildTestBase.php    |  8 +++--
 .../Framework/Tests/BuildTestTest.php         | 31 +++++++++++++++++++
 2 files changed, 36 insertions(+), 3 deletions(-)

diff --git a/core/tests/Drupal/BuildTests/Framework/BuildTestBase.php b/core/tests/Drupal/BuildTests/Framework/BuildTestBase.php
index 22559bca2d09..335844cce197 100644
--- a/core/tests/Drupal/BuildTests/Framework/BuildTestBase.php
+++ b/core/tests/Drupal/BuildTests/Framework/BuildTestBase.php
@@ -382,9 +382,11 @@ protected function standUpServer($working_dir = NULL) {
       $this->stopServer();
     }
     // If there's not a server at this point, make one.
-    $this->serverProcess = $this->instantiateServer($this->getPortNumber(), $working_dir);
-    if ($this->serverProcess) {
-      $this->serverDocroot = $working_dir;
+    if (!$this->serverProcess || $this->serverProcess->isTerminated()) {
+      $this->serverProcess = $this->instantiateServer($this->getPortNumber(), $working_dir);
+      if ($this->serverProcess) {
+        $this->serverDocroot = $working_dir;
+      }
     }
   }
 
diff --git a/core/tests/Drupal/BuildTests/Framework/Tests/BuildTestTest.php b/core/tests/Drupal/BuildTests/Framework/Tests/BuildTestTest.php
index ae2c09708a21..b505ef83522c 100644
--- a/core/tests/Drupal/BuildTests/Framework/Tests/BuildTestTest.php
+++ b/core/tests/Drupal/BuildTests/Framework/Tests/BuildTestTest.php
@@ -154,4 +154,35 @@ public function testPortMany() {
     }
   }
 
+  /**
+   * @covers ::standUpServer
+   */
+  public function testStandUpServer() {
+    // Stand up a server with working directory 'first'.
+    $this->standUpServer('first');
+
+    // Get the process object for the server.
+    $ref_process = new \ReflectionProperty(parent::class, 'serverProcess');
+    $ref_process->setAccessible(TRUE);
+    $first_process = $ref_process->getValue($this);
+
+    // Standing up the server again should not change the server process.
+    $this->standUpServer('first');
+    $this->assertSame($first_process, $ref_process->getValue($this));
+
+    // Standing up the server with working directory 'second' should give us a
+    // new server process.
+    $this->standUpServer('second');
+    $this->assertNotSame(
+      $first_process,
+      $second_process = $ref_process->getValue($this)
+    );
+
+    // And even with the original working directory name, we should get a new
+    // server process.
+    $this->standUpServer('first');
+    $this->assertNotSame($first_process, $ref_process->getValue($this));
+    $this->assertNotSame($second_process, $ref_process->getValue($this));
+  }
+
 }
-- 
GitLab