From e4503046de1263148e1b56394144b1828bbfdac0 Mon Sep 17 00:00:00 2001
From: Nikolay Kim <fafhrd91@gmail.com>
Date: Tue, 17 Sep 2019 21:45:06 +0600
Subject: [PATCH] Do not override current System

---
 test-server/CHANGES.md |  5 +++
 test-server/Cargo.toml |  8 ++---
 test-server/src/lib.rs | 81 +++++++++++++++++++++---------------------
 3 files changed, 50 insertions(+), 44 deletions(-)

diff --git a/test-server/CHANGES.md b/test-server/CHANGES.md
index c3fe5b28..798dbf50 100644
--- a/test-server/CHANGES.md
+++ b/test-server/CHANGES.md
@@ -1,10 +1,15 @@
 # Changes
 
+## [0.2.5] - 2019-0917
 
 ### Changed
 
 * Update serde_urlencoded to "0.6.1"
 
+### Fixed
+
+* Do not override current `System`
+
 
 ## [0.2.4] - 2019-07-18
 
diff --git a/test-server/Cargo.toml b/test-server/Cargo.toml
index 22809c06..77301b0a 100644
--- a/test-server/Cargo.toml
+++ b/test-server/Cargo.toml
@@ -1,6 +1,6 @@
 [package]
 name = "actix-http-test"
-version = "0.2.4"
+version = "0.2.5"
 authors = ["Nikolay Kim <fafhrd91@gmail.com>"]
 description = "Actix http test server"
 readme = "README.md"
@@ -35,7 +35,7 @@ actix-rt = "0.2.2"
 actix-service = "0.4.1"
 actix-server = "0.6.0"
 actix-utils = "0.4.1"
-awc = "0.2.2"
+awc = "0.2.6"
 actix-connect = "0.2.2"
 
 base64 = "0.10"
@@ -56,5 +56,5 @@ tokio-timer = "0.2"
 openssl = { version="0.10", optional = true }
 
 [dev-dependencies]
-actix-web = "1.0.0"
-actix-http = "0.2.4"
+actix-web = "1.0.7"
+actix-http = "0.2.9"
diff --git a/test-server/src/lib.rs b/test-server/src/lib.rs
index aba53980..a2366bf4 100644
--- a/test-server/src/lib.rs
+++ b/test-server/src/lib.rs
@@ -103,8 +103,8 @@ pub struct TestServer;
 /// Test server controller
 pub struct TestServerRuntime {
     addr: net::SocketAddr,
-    rt: Runtime,
     client: Client,
+    system: System,
 }
 
 impl TestServer {
@@ -130,45 +130,47 @@ impl TestServer {
         });
 
         let (system, addr) = rx.recv().unwrap();
-        let mut rt = Runtime::new().unwrap();
 
-        let client = rt
-            .block_on(lazy(move || {
-                let connector = {
-                    #[cfg(feature = "ssl")]
-                    {
-                        use openssl::ssl::{SslConnector, SslMethod, SslVerifyMode};
+        let client = block_on(lazy(move || {
+            let connector = {
+                #[cfg(feature = "ssl")]
+                {
+                    use openssl::ssl::{SslConnector, SslMethod, SslVerifyMode};
 
-                        let mut builder =
-                            SslConnector::builder(SslMethod::tls()).unwrap();
-                        builder.set_verify(SslVerifyMode::NONE);
-                        let _ = builder.set_alpn_protos(b"\x02h2\x08http/1.1").map_err(
-                            |e| log::error!("Can not set alpn protocol: {:?}", e),
-                        );
-                        Connector::new()
-                            .conn_lifetime(time::Duration::from_secs(0))
-                            .timeout(time::Duration::from_millis(500))
-                            .ssl(builder.build())
-                            .finish()
-                    }
-                    #[cfg(not(feature = "ssl"))]
-                    {
-                        Connector::new()
-                            .conn_lifetime(time::Duration::from_secs(0))
-                            .timeout(time::Duration::from_millis(500))
-                            .finish()
-                    }
-                };
+                    let mut builder = SslConnector::builder(SslMethod::tls()).unwrap();
+                    builder.set_verify(SslVerifyMode::NONE);
+                    let _ = builder
+                        .set_alpn_protos(b"\x02h2\x08http/1.1")
+                        .map_err(|e| log::error!("Can not set alpn protocol: {:?}", e));
+                    Connector::new()
+                        .conn_lifetime(time::Duration::from_secs(0))
+                        .timeout(time::Duration::from_millis(500))
+                        .ssl(builder.build())
+                        .finish()
+                }
+                #[cfg(not(feature = "ssl"))]
+                {
+                    Connector::new()
+                        .conn_lifetime(time::Duration::from_secs(0))
+                        .timeout(time::Duration::from_millis(500))
+                        .finish()
+                }
+            };
 
-                Ok::<Client, ()>(Client::build().connector(connector).finish())
-            }))
-            .unwrap();
-        rt.block_on(lazy(
+            Ok::<Client, ()>(Client::build().connector(connector).finish())
+        }))
+        .unwrap();
+
+        block_on(lazy(
             || Ok::<_, ()>(actix_connect::start_default_resolver()),
         ))
         .unwrap();
-        System::set_current(system);
-        TestServerRuntime { addr, rt, client }
+
+        TestServerRuntime {
+            addr,
+            client,
+            system,
+        }
     }
 
     /// Get first available unused address
@@ -188,7 +190,7 @@ impl TestServerRuntime {
     where
         F: Future<Item = I, Error = E>,
     {
-        self.rt.block_on(fut)
+        block_on(fut)
     }
 
     /// Execute future on current core
@@ -197,7 +199,7 @@ impl TestServerRuntime {
         F: FnOnce() -> R,
         R: Future,
     {
-        self.rt.block_on(lazy(f))
+        block_on(lazy(f))
     }
 
     /// Execute function on current core
@@ -205,7 +207,7 @@ impl TestServerRuntime {
     where
         F: FnOnce() -> R,
     {
-        self.rt.block_on(lazy(|| Ok::<_, ()>(fut()))).unwrap()
+        block_on(lazy(|| Ok::<_, ()>(fut()))).unwrap()
     }
 
     /// Construct test server url
@@ -324,8 +326,7 @@ impl TestServerRuntime {
     {
         let url = self.url(path);
         let connect = self.client.ws(url).connect();
-        self.rt
-            .block_on(lazy(move || connect.map(|(_, framed)| framed)))
+        block_on(lazy(move || connect.map(|(_, framed)| framed)))
     }
 
     /// Connect to a websocket server
@@ -338,7 +339,7 @@ impl TestServerRuntime {
 
     /// Stop http server
     fn stop(&mut self) {
-        System::current().stop();
+        self.system.stop();
     }
 }