diff options
author | bors[bot] <bors[bot]@users.noreply.github.com> | 2019-02-14 18:22:19 +0000 |
---|---|---|
committer | bors[bot] <bors[bot]@users.noreply.github.com> | 2019-02-14 18:22:19 +0000 |
commit | c530f04df51459d6d5f70c475e93127217f6e27f (patch) | |
tree | 2e9abadb6e64fed7738b5b3fbc2eb13787efdaca /crates/ra_lsp_server/tests/heavy_tests/support.rs | |
parent | 10bf61b83b2600ed3cb7e7825f1cd0ee83e9b7e7 (diff) | |
parent | e0b8942c56378b7966af39058f27b11a0d02890f (diff) |
Merge #833
833: automatically wait for worker threads r=matklad a=matklad
closes #817
Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates/ra_lsp_server/tests/heavy_tests/support.rs')
-rw-r--r-- | crates/ra_lsp_server/tests/heavy_tests/support.rs | 17 |
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::{ | |||
17 | use serde::Serialize; | 17 | use serde::Serialize; |
18 | use serde_json::{to_string_pretty, Value}; | 18 | use serde_json::{to_string_pretty, Value}; |
19 | use tempfile::TempDir; | 19 | use tempfile::TempDir; |
20 | use thread_worker::{WorkerHandle, Worker}; | 20 | use thread_worker::Worker; |
21 | use test_utils::{parse_fixture, find_mismatch}; | 21 | use test_utils::{parse_fixture, find_mismatch}; |
22 | 22 | ||
23 | use ra_lsp_server::{ | 23 | use 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 | ||
51 | impl Server { | 50 | impl 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 | ||
170 | impl Drop for Server { | 168 | impl 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 | ||