Repository: quarkusio/quarkus
Issue: quarkus.http[s].test-port system properties are lost on app restart triggered by @TestProfile

**Describe the bug**
If you set e.g. `<quarkus.http.test-port>0</quarkus.http.test-port>` in `systemPropertyVariables` of `maven-surefire-plugin` and you have at least one `@QuarkusTest` *without* `@TestProfile` and one `@QuarkusTest` *with* `@TestProfile` then the port is not picked up by that second test (if run after the test without `@TestProfile`).

The reason for this lies in [VertxHttpRecorder](https://github.com/quarkusio/quarkus/blob/1.7.2.Final/extensions/vertx-http/runtime/src/main/java/io/quarkus/vertx/http/runtime/VertxHttpRecorder.java):
It is (re-?)setting the port properties here: https://github.com/quarkusio/quarkus/blob/1.7.2.Final/extensions/vertx-http/runtime/src/main/java/io/quarkus/vertx/http/runtime/VertxHttpRecorder.java#L898-L902
and it is *clearing* the port properties here:
https://github.com/quarkusio/quarkus/blob/1.7.2.Final/extensions/vertx-http/runtime/src/main/java/io/quarkus/vertx/http/runtime/VertxHttpRecorder.java#L916-L930

(I saw in the debugger that the recorder is setting the actual effective port, e.g. 62138)

That clearing occurs on shutdown which is triggered by the test extension because it finds a `@TestProfile`.
The app instance that is then booted up after that cannot (obviously) see the original port properties anymore, falling back to the default (or I guess to yaml/properties in case port properties are set there).

**Expected behavior**
Port system properties must survive restarts triggered by `@TestProfile`.

**Actual behavior**
Port system properties are lost on first restart by a `@TestProfile`.

**To Reproduce**
Steps to reproduce the behavior:
1. clone https://github.com/famod/quarkus-quickstarts
2. switch to issue-12087-port-sysprop-lost
    diff: https://github.com/quarkusio/quarkus-quickstarts/compare/master..famod:issue-12087-port-sysprop-lost
3. cd getting-started-testing
4. mvn clean test will show that random port is only used for the first test (second one uses profile):
    ```
    [INFO] Running org.acme.getting.started.testing.GreetingResourceTest
    2020-09-14 22:30:53,552 INFO  [io.quarkus] (main) Quarkus 1.7.3.Final on JVM started in 1.743s. Listening on: http://0.0.0.0:51063
    2020-09-14 22:30:53,555 INFO  [io.quarkus] (main) Profile test activated.
    2020-09-14 22:30:53,555 INFO  [io.quarkus] (main) Installed features: [cdi, resteasy]
    [INFO] Tests run: 2, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 5.031 s - in org.acme.getting.started.testing.GreetingResourceTest
    [INFO] Running org.acme.getting.started.testing.GreetingServiceTest
    2020-09-14 22:30:54,585 INFO  [io.quarkus] (main) Quarkus stopped in 0.021s
    2020-09-14 22:30:56,357 INFO  [io.quarkus] (main) Quarkus 1.7.3.Final on JVM started in 1.585s. Listening on: http://0.0.0.0:8081
    2020-09-14 22:30:56,357 INFO  [io.quarkus] (main) Profile test activated.
    2020-09-14 22:30:56,357 INFO  [io.quarkus] (main) Installed features: [cdi, resteasy]
    [INFO] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 2.017 s - in org.acme.getting.started.testing.GreetingServiceTest
    [INFO] Running org.acme.getting.started.testing.StaticContentTest
    2020-09-14 22:30:56,599 INFO  [io.quarkus] (main) Quarkus stopped in 0.015s
    2020-09-14 22:30:58,120 INFO  [io.quarkus] (main) Quarkus 1.7.3.Final on JVM started in 1.389s. Listening on: http://0.0.0.0:8081
    2020-09-14 22:30:58,120 INFO  [io.quarkus] (main) Profile test activated.
    2020-09-14 22:30:58,120 INFO  [io.quarkus] (main) Installed features: [cdi, resteasy]
    ```

**Configuration**
n/a

**Environment (please complete the following information):**
 - Output of `uname -a` or `ver`: `MINGW64_NT-10.0-18363 XXX 3.0.7-338.x86_64 2019-11-21 23:07 UTC x86_64 Msys`
 - Output of `java -version`: `OpenJDK 64-Bit Server VM AdoptOpenJDK (build 11.0.7+10, mixed mode)`
 - GraalVM version (if different from Java): n/a
 - Quarkus version or git rev: `1.7.2.Final`
 - Build tool (ie. output of `mvnw --version` or `gradlew --version`): `Apache Maven 3.6.3`

**Additional context**
(Add any other context about the problem here.)


Changed files:
extensions/vertx-http/runtime/src/main/java/io/quarkus/vertx/http/runtime/VertxHttpRecorder.java

diff --git a/extensions/vertx-http/runtime/src/main/java/io/quarkus/vertx/http/runtime/VertxHttpRecorder.java b/extensions/vertx-http/runtime/src/main/java/io/quarkus/vertx/http/runtime/VertxHttpRecorder.java
index b0b95c35bb9..ccbcb37b71c 100644
--- a/extensions/vertx-http/runtime/src/main/java/io/quarkus/vertx/http/runtime/VertxHttpRecorder.java
+++ b/extensions/vertx-http/runtime/src/main/java/io/quarkus/vertx/http/runtime/VertxHttpRecorder.java
@@ -9,6 +9,7 @@
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collections;
+import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 import java.util.Optional;
@@ -784,6 +785,7 @@ private static class WebDeploymentVerticle extends AbstractVerticle {
         private final LaunchMode launchMode;
         private volatile boolean clearHttpProperty = false;
         private volatile boolean clearHttpsProperty = false;
+        private volatile Map<String, String> portPropertiesToRestore;
         private final HttpConfiguration.InsecureRequests insecureRequests;
 
         public WebDeploymentVerticle(HttpServerOptions httpOptions, HttpServerOptions httpsOptions,
@@ -892,14 +894,21 @@ private void setupTcpHttpServer(HttpServer httpServer, HttpServerOptions options
                             clearHttpProperty = true;
                             schema = "http";
                         }
+                        portPropertiesToRestore = new HashMap<>();
                         String portPropertyValue = String.valueOf(actualPort);
                         String portPropertyName = (launchMode == LaunchMode.TEST ? "quarkus." + schema + ".test-port"
                                 : "quarkus." + schema + ".port");
-                        System.setProperty(portPropertyName, portPropertyValue);
+                        String prevPortPropertyValue = System.setProperty(portPropertyName, portPropertyValue);
+                        if (prevPortPropertyValue != null) {
+                            portPropertiesToRestore.put(portPropertyName, prevPortPropertyValue);
+                        }
                         if (launchMode.isDevOrTest()) {
                             // set the profile property as well to make sure we don't have any inconsistencies
-                            System.setProperty(propertyWithProfilePrefix(portPropertyName),
-                                    portPropertyValue);
+                            portPropertyName = propertyWithProfilePrefix(portPropertyName);
+                            prevPortPropertyValue = System.setProperty(portPropertyName, portPropertyValue);
+                            if (prevPortPropertyValue != null) {
+                                portPropertiesToRestore.put(portPropertyName, prevPortPropertyValue);
+                            }
                         }
                         // Set in HttpOptions to output the port in the Timing class
                         options.setPort(actualPort);
@@ -928,6 +937,9 @@ public void stop(Future<Void> stopFuture) {
                     System.clearProperty(propertyWithProfilePrefix(portPropertyName));
                 }
             }
+            if (portPropertiesToRestore != null && !portPropertiesToRestore.isEmpty()) {
+                System.getProperties().putAll(portPropertiesToRestore);
+            }
 
             final AtomicInteger remainingCount = new AtomicInteger(0);
             if (httpServer != null) {