mirror of
https://github.com/joshuadavidthomas/django-language-server.git
synced 2025-09-27 20:42:14 +00:00
add integration tests for retries, fix bugs that surfaced (#18)
This commit is contained in:
parent
a2ebd0dc8f
commit
8636a7f198
3 changed files with 91 additions and 26 deletions
|
@ -1,10 +1,13 @@
|
|||
use anyhow::{Context, Result};
|
||||
use async_trait::async_trait;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::{path::Path, time::Duration};
|
||||
use std::{
|
||||
path::{Path, PathBuf},
|
||||
time::Duration,
|
||||
};
|
||||
use tokio::io::{AsyncBufReadExt, AsyncWriteExt, BufReader};
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
#[derive(Clone, Copy, Debug)]
|
||||
pub(crate) struct ConnectionConfig {
|
||||
max_retries: u32,
|
||||
initial_delay_ms: u64,
|
||||
|
@ -103,6 +106,7 @@ pub struct Message<T> {
|
|||
pub struct Client {
|
||||
connection: Box<dyn ConnectionTrait>,
|
||||
message_id: u64,
|
||||
socket_path: PathBuf,
|
||||
}
|
||||
|
||||
impl Client {
|
||||
|
@ -111,6 +115,7 @@ impl Client {
|
|||
Ok(Self {
|
||||
connection,
|
||||
message_id: 0,
|
||||
socket_path: path.to_owned(),
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -378,16 +383,21 @@ mod client_tests {
|
|||
value: String,
|
||||
}
|
||||
|
||||
fn create_test_client(mock_conn: MockConnection) -> Client {
|
||||
Client {
|
||||
connection: Box::new(mock_conn),
|
||||
message_id: 0,
|
||||
socket_path: PathBuf::from("/test/socket"),
|
||||
}
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn test_successful_message_exchange() -> Result<()> {
|
||||
let mock_conn = MockConnection::new(vec![Ok(
|
||||
r#"{"id":1,"content":{"value":"response"}}"#.to_string()
|
||||
)]);
|
||||
|
||||
let mut client = Client {
|
||||
connection: Box::new(mock_conn),
|
||||
message_id: 0,
|
||||
};
|
||||
let mut client = create_test_client(mock_conn);
|
||||
|
||||
let request = TestMessage {
|
||||
value: "test".to_string(),
|
||||
|
@ -403,10 +413,7 @@ mod client_tests {
|
|||
async fn test_connection_error() {
|
||||
let mock_conn = MockConnection::new(vec![Err(anyhow::anyhow!("Connection error"))]);
|
||||
|
||||
let mut client = Client {
|
||||
connection: Box::new(mock_conn),
|
||||
message_id: 0,
|
||||
};
|
||||
let mut client = create_test_client(mock_conn);
|
||||
|
||||
let request = TestMessage {
|
||||
value: "test".to_string(),
|
||||
|
@ -422,10 +429,7 @@ mod client_tests {
|
|||
r#"{"id":2,"content":{"value":"response"}}"#.to_string()
|
||||
)]);
|
||||
|
||||
let mut client = Client {
|
||||
connection: Box::new(mock_conn),
|
||||
message_id: 0,
|
||||
};
|
||||
let mut client = create_test_client(mock_conn);
|
||||
|
||||
let request = TestMessage {
|
||||
value: "test".to_string(),
|
||||
|
@ -443,10 +447,7 @@ mod client_tests {
|
|||
async fn test_invalid_json_response() {
|
||||
let mock_conn = MockConnection::new(vec![Ok("invalid json".to_string())]);
|
||||
|
||||
let mut client = Client {
|
||||
connection: Box::new(mock_conn),
|
||||
message_id: 0,
|
||||
};
|
||||
let mut client = create_test_client(mock_conn);
|
||||
|
||||
let request = TestMessage {
|
||||
value: "test".to_string(),
|
||||
|
@ -462,10 +463,7 @@ mod client_tests {
|
|||
Ok(r#"{"id":2,"content":{"value":"response2"}}"#.to_string()),
|
||||
]);
|
||||
|
||||
let mut client = Client {
|
||||
connection: Box::new(mock_conn),
|
||||
message_id: 0,
|
||||
};
|
||||
let mut client = create_test_client(mock_conn);
|
||||
|
||||
let request1 = TestMessage {
|
||||
value: "test1".to_string(),
|
||||
|
|
|
@ -24,10 +24,11 @@ impl Server {
|
|||
fn start_with_options(python_path: &str, args: &[&str], use_module: bool) -> Result<Self> {
|
||||
let temp_dir = tempdir()?;
|
||||
|
||||
let path = {
|
||||
let socket_path = temp_dir.path().join("ipc.sock");
|
||||
socket_path
|
||||
};
|
||||
let path = args
|
||||
.windows(2)
|
||||
.find(|w| w[0] == "--ipc-path")
|
||||
.map(|w| PathBuf::from(w[1]))
|
||||
.unwrap_or_else(|| temp_dir.path().join("ipc.sock"));
|
||||
|
||||
let mut command = Command::new("python");
|
||||
if use_module {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue