mirror of
https://github.com/chatmail/core.git
synced 2026-05-19 06:46:32 +03:00
deltachat-rpc-server: spawn request handlers
This commit is contained in:
@@ -5,6 +5,8 @@
|
|||||||
### Changes
|
### Changes
|
||||||
|
|
||||||
### Fixes
|
### Fixes
|
||||||
|
- deltachat-rpc-server: do not block stdin while processing the request. #4041
|
||||||
|
deltachat-rpc-server now reads the next request as soon as previous request handler is spawned.
|
||||||
|
|
||||||
### API-Changes
|
### API-Changes
|
||||||
- Remove `MimeMessage::from_bytes()` public interface. #4033
|
- Remove `MimeMessage::from_bytes()` public interface. #4033
|
||||||
|
|||||||
@@ -85,6 +85,11 @@ impl CommandApi {
|
|||||||
|
|
||||||
#[rpc(all_positional, ts_outdir = "typescript/generated")]
|
#[rpc(all_positional, ts_outdir = "typescript/generated")]
|
||||||
impl CommandApi {
|
impl CommandApi {
|
||||||
|
/// Test function.
|
||||||
|
async fn sleep(&self, delay: f64) {
|
||||||
|
tokio::time::sleep(std::time::Duration::from_secs_f64(delay)).await
|
||||||
|
}
|
||||||
|
|
||||||
// ---------------------------------------------
|
// ---------------------------------------------
|
||||||
// Misc top level functions
|
// Misc top level functions
|
||||||
// ---------------------------------------------
|
// ---------------------------------------------
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
from unittest.mock import MagicMock
|
from unittest.mock import MagicMock
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
import asyncio
|
||||||
|
|
||||||
from deltachat_rpc_client import EventType, events
|
from deltachat_rpc_client import EventType, events
|
||||||
from deltachat_rpc_client.rpc import JsonRpcError
|
from deltachat_rpc_client.rpc import JsonRpcError
|
||||||
@@ -13,6 +14,17 @@ async def test_system_info(rpc) -> None:
|
|||||||
assert "deltachat_core_version" in system_info
|
assert "deltachat_core_version" in system_info
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.asyncio()
|
||||||
|
async def test_sleep(rpc) -> None:
|
||||||
|
"""Test that long-running task does not block short-running task from completion."""
|
||||||
|
sleep_5_task = asyncio.create_task(rpc.sleep(5.0))
|
||||||
|
sleep_3_task = asyncio.create_task(rpc.sleep(3.0))
|
||||||
|
done, pending = await asyncio.wait([sleep_5_task, sleep_3_task], return_when=asyncio.FIRST_COMPLETED)
|
||||||
|
assert sleep_3_task in done
|
||||||
|
assert sleep_5_task in pending
|
||||||
|
sleep_5_task.cancel()
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.asyncio()
|
@pytest.mark.asyncio()
|
||||||
async def test_email_address_validity(rpc) -> None:
|
async def test_email_address_validity(rpc) -> None:
|
||||||
valid_addresses = [
|
valid_addresses = [
|
||||||
|
|||||||
@@ -51,7 +51,10 @@ async fn main() -> Result<()> {
|
|||||||
let mut lines = BufReader::new(stdin).lines();
|
let mut lines = BufReader::new(stdin).lines();
|
||||||
while let Some(message) = lines.next_line().await? {
|
while let Some(message) = lines.next_line().await? {
|
||||||
log::trace!("RPC recv {}", message);
|
log::trace!("RPC recv {}", message);
|
||||||
session.handle_incoming(&message).await;
|
let session = session.clone();
|
||||||
|
tokio::spawn(async move {
|
||||||
|
session.handle_incoming(&message).await;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
log::info!("EOF reached on stdin");
|
log::info!("EOF reached on stdin");
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|||||||
Reference in New Issue
Block a user