aboutsummaryrefslogtreecommitdiff
path: root/crates/server/tests/heavy_tests
diff options
context:
space:
mode:
Diffstat (limited to 'crates/server/tests/heavy_tests')
-rw-r--r--crates/server/tests/heavy_tests/support.rs32
1 files changed, 18 insertions, 14 deletions
diff --git a/crates/server/tests/heavy_tests/support.rs b/crates/server/tests/heavy_tests/support.rs
index 731c2f51c..297dcd9ae 100644
--- a/crates/server/tests/heavy_tests/support.rs
+++ b/crates/server/tests/heavy_tests/support.rs
@@ -8,7 +8,7 @@ use std::{
8}; 8};
9 9
10use tempdir::TempDir; 10use tempdir::TempDir;
11use crossbeam_channel::{bounded, after, Sender, Receiver}; 11use crossbeam_channel::{unbounded, after, Sender, Receiver};
12use flexi_logger::Logger; 12use flexi_logger::Logger;
13use languageserver_types::{ 13use languageserver_types::{
14 Url, 14 Url,
@@ -54,7 +54,6 @@ pub fn project(fixture: &str) -> Server {
54 buf.push('\n'); 54 buf.push('\n');
55 } 55 }
56 flush!(); 56 flush!();
57
58 Server::new(tmp_dir, paths) 57 Server::new(tmp_dir, paths)
59} 58}
60 59
@@ -70,8 +69,8 @@ pub struct Server {
70impl Server { 69impl Server {
71 fn new(dir: TempDir, files: Vec<(PathBuf, String)>) -> Server { 70 fn new(dir: TempDir, files: Vec<(PathBuf, String)>) -> Server {
72 let path = dir.path().to_path_buf(); 71 let path = dir.path().to_path_buf();
73 let (client_sender, mut server_receiver) = bounded(1); 72 let (client_sender, mut server_receiver) = unbounded();
74 let (mut server_sender, client_receiver) = bounded(1); 73 let (mut server_sender, client_receiver) = unbounded();
75 let server = thread::spawn(move || main_loop(true, path, &mut server_receiver, &mut server_sender)); 74 let server = thread::spawn(move || main_loop(true, path, &mut server_receiver, &mut server_sender));
76 let res = Server { 75 let res = Server {
77 req_id: Cell::new(1), 76 req_id: Cell::new(1),
@@ -81,6 +80,7 @@ impl Server {
81 receiver: client_receiver, 80 receiver: client_receiver,
82 server: Some(server), 81 server: Some(server),
83 }; 82 };
83
84 for (path, text) in files { 84 for (path, text) in files {
85 res.send_notification(RawNotification::new::<DidOpenTextDocument>( 85 res.send_notification(RawNotification::new::<DidOpenTextDocument>(
86 &DidOpenTextDocumentParams { 86 &DidOpenTextDocumentParams {
@@ -179,15 +179,11 @@ impl Server {
179 } 179 }
180 } 180 }
181 fn recv(&self) -> Option<RawMessage> { 181 fn recv(&self) -> Option<RawMessage> {
182 let timeout = Duration::from_secs(5); 182 recv_timeout(&self.receiver)
183 let msg = select! { 183 .map(|msg| {
184 recv(&self.receiver, msg) => msg, 184 self.messages.borrow_mut().push(msg.clone());
185 recv(after(timeout)) => panic!("timed out"), 185 msg
186 }; 186 })
187 msg.map(|msg| {
188 self.messages.borrow_mut().push(msg.clone());
189 msg
190 })
191 } 187 }
192 fn send_notification(&self, not: RawNotification) { 188 fn send_notification(&self, not: RawNotification) {
193 self.sender.as_ref() 189 self.sender.as_ref()
@@ -201,7 +197,7 @@ impl Drop for Server {
201 { 197 {
202 self.send_request::<Shutdown>(666, ()); 198 self.send_request::<Shutdown>(666, ());
203 drop(self.sender.take().unwrap()); 199 drop(self.sender.take().unwrap());
204 while let Some(msg) = self.receiver.recv() { 200 while let Some(msg) = recv_timeout(&self.receiver) {
205 drop(msg); 201 drop(msg);
206 } 202 }
207 } 203 }
@@ -210,3 +206,11 @@ impl Drop for Server {
210 .join().unwrap().unwrap(); 206 .join().unwrap().unwrap();
211 } 207 }
212} 208}
209
210fn recv_timeout(receiver: &Receiver<RawMessage>) -> Option<RawMessage> {
211 let timeout = Duration::from_secs(5);
212 select! {
213 recv(receiver, msg) => msg,
214 recv(after(timeout)) => panic!("timed out"),
215 }
216}