aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_lsp_server/tests
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2019-02-14 17:43:45 +0000
committerAleksey Kladov <[email protected]>2019-02-14 18:11:07 +0000
commitbf352cd2511775a331d77dee261b64bd8359dacb (patch)
treeba7d988ebef437d5a9d7beac048b5ac0dbd2fe9c /crates/ra_lsp_server/tests
parent10bf61b83b2600ed3cb7e7825f1cd0ee83e9b7e7 (diff)
automatically wait for worker threads
closes #817
Diffstat (limited to 'crates/ra_lsp_server/tests')
-rw-r--r--crates/ra_lsp_server/tests/heavy_tests/support.rs17
1 files changed, 5 insertions, 12 deletions
diff --git a/crates/ra_lsp_server/tests/heavy_tests/support.rs b/crates/ra_lsp_server/tests/heavy_tests/support.rs
index eee85f8c8..11f94b4ab 100644
--- a/crates/ra_lsp_server/tests/heavy_tests/support.rs
+++ b/crates/ra_lsp_server/tests/heavy_tests/support.rs
@@ -17,7 +17,7 @@ use lsp_types::{
17use serde::Serialize; 17use serde::Serialize;
18use serde_json::{to_string_pretty, Value}; 18use serde_json::{to_string_pretty, Value};
19use tempfile::TempDir; 19use tempfile::TempDir;
20use thread_worker::{WorkerHandle, Worker}; 20use thread_worker::Worker;
21use test_utils::{parse_fixture, find_mismatch}; 21use test_utils::{parse_fixture, find_mismatch};
22 22
23use ra_lsp_server::{ 23use ra_lsp_server::{
@@ -45,13 +45,12 @@ pub struct Server {
45 messages: RefCell<Vec<RawMessage>>, 45 messages: RefCell<Vec<RawMessage>>,
46 dir: TempDir, 46 dir: TempDir,
47 worker: Option<Worker<RawMessage, RawMessage>>, 47 worker: Option<Worker<RawMessage, RawMessage>>,
48 watcher: Option<WorkerHandle>,
49} 48}
50 49
51impl Server { 50impl Server {
52 fn new(dir: TempDir, files: Vec<(PathBuf, String)>) -> Server { 51 fn new(dir: TempDir, files: Vec<(PathBuf, String)>) -> Server {
53 let path = dir.path().to_path_buf(); 52 let path = dir.path().to_path_buf();
54 let (worker, watcher) = thread_worker::spawn::<RawMessage, RawMessage, _>( 53 let worker = Worker::<RawMessage, RawMessage>::spawn(
55 "test server", 54 "test server",
56 128, 55 128,
57 move |mut msg_receiver, mut msg_sender| { 56 move |mut msg_receiver, mut msg_sender| {
@@ -63,7 +62,6 @@ impl Server {
63 dir, 62 dir,
64 messages: Default::default(), 63 messages: Default::default(),
65 worker: Some(worker), 64 worker: Some(worker),
66 watcher: Some(watcher),
67 }; 65 };
68 66
69 for (path, text) in files { 67 for (path, text) in files {
@@ -117,7 +115,7 @@ impl Server {
117 } 115 }
118 fn send_request_(&self, r: RawRequest) -> Value { 116 fn send_request_(&self, r: RawRequest) -> Value {
119 let id = r.id; 117 let id = r.id;
120 self.worker.as_ref().unwrap().send(RawMessage::Request(r)).unwrap(); 118 self.worker.as_ref().unwrap().sender().send(RawMessage::Request(r)).unwrap();
121 while let Some(msg) = self.recv() { 119 while let Some(msg) = self.recv() {
122 match msg { 120 match msg {
123 RawMessage::Request(req) => panic!("unexpected request: {:?}", req), 121 RawMessage::Request(req) => panic!("unexpected request: {:?}", req),
@@ -157,24 +155,19 @@ impl Server {
157 } 155 }
158 } 156 }
159 fn recv(&self) -> Option<RawMessage> { 157 fn recv(&self) -> Option<RawMessage> {
160 recv_timeout(&self.worker.as_ref().unwrap().out).map(|msg| { 158 recv_timeout(&self.worker.as_ref().unwrap().receiver()).map(|msg| {
161 self.messages.borrow_mut().push(msg.clone()); 159 self.messages.borrow_mut().push(msg.clone());
162 msg 160 msg
163 }) 161 })
164 } 162 }
165 fn send_notification(&self, not: RawNotification) { 163 fn send_notification(&self, not: RawNotification) {
166 self.worker.as_ref().unwrap().send(RawMessage::Notification(not)).unwrap(); 164 self.worker.as_ref().unwrap().sender().send(RawMessage::Notification(not)).unwrap();
167 } 165 }
168} 166}
169 167
170impl Drop for Server { 168impl Drop for Server {
171 fn drop(&mut self) { 169 fn drop(&mut self) {
172 self.send_request::<Shutdown>(()); 170 self.send_request::<Shutdown>(());
173 let receiver = self.worker.take().unwrap().shutdown();
174 while let Some(msg) = recv_timeout(&receiver) {
175 drop(msg);
176 }
177 self.watcher.take().unwrap().shutdown().unwrap();
178 } 171 }
179} 172}
180 173