mirror of
https://github.com/chatmail/core.git
synced 2026-07-03 22:14:58 +03:00
Compare commits
6 Commits
simon/test
...
link2xt/no
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
cde0fb32e6 | ||
|
|
f1bbd676c6 | ||
|
|
d924637830 | ||
|
|
6aa044a70a | ||
|
|
8a827495ef | ||
|
|
e290a7b852 |
7
.github/workflows/node-tests.yml
vendored
7
.github/workflows/node-tests.yml
vendored
@@ -21,14 +21,17 @@ jobs:
|
||||
runs-on: ${{ matrix.os }}
|
||||
strategy:
|
||||
matrix:
|
||||
os: [ubuntu-latest, macos-latest, windows-latest]
|
||||
os: [ubuntu-latest, macos-14, windows-latest]
|
||||
node: ["18", "20"]
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
show-progress: false
|
||||
- uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version: "18"
|
||||
node-version: ${{ matrix.node }}
|
||||
- if: matrix.os == 'macos-14'
|
||||
run: sudo xcode-select --switch /Applications/Xcode_15.3.app/Contents/Developer
|
||||
- name: System info
|
||||
run: |
|
||||
rustc -vV
|
||||
|
||||
@@ -152,13 +152,6 @@ impl CommandApi {
|
||||
tokio::time::sleep(std::time::Duration::from_secs_f64(delay)).await
|
||||
}
|
||||
|
||||
/// Emit the test checkpoint event, used for tests.
|
||||
/// Returns a unique id of the emitted `TestCheckpointEvent`.
|
||||
async fn trigger_checkpoint_event(&self, account_id: u32) -> Result<usize> {
|
||||
let ctx = self.get_context(account_id).await?;
|
||||
Ok(ctx.emit_test_checkpoint_event().await)
|
||||
}
|
||||
|
||||
// ---------------------------------------------
|
||||
// Misc top level functions
|
||||
// ---------------------------------------------
|
||||
|
||||
@@ -259,13 +259,6 @@ pub enum EventType {
|
||||
/// If `chat_id` is set to None, then all currently visible chats need to be rerendered, and all not-visible items need to be cleared from cache if the UI has a cache.
|
||||
#[serde(rename_all = "camelCase")]
|
||||
ChatlistItemChanged { chat_id: Option<u32> },
|
||||
|
||||
/// Tests can trigger this event and then wait for it, to make sure all events before it were consumed.
|
||||
/// Useful for tests that test whether a specific event is emitted,
|
||||
TestCheckpointEvent {
|
||||
/// unique id to recognize the event
|
||||
id: usize,
|
||||
},
|
||||
}
|
||||
|
||||
impl From<CoreEventType> for EventType {
|
||||
@@ -377,7 +370,6 @@ impl From<CoreEventType> for EventType {
|
||||
chat_id: chat_id.map(|id| id.to_u32()),
|
||||
},
|
||||
CoreEventType::ChatlistChanged => ChatlistChanged,
|
||||
CoreEventType::TestCheckpointEvent { id } => TestCheckpointEvent { id },
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -61,7 +61,6 @@ class EventType(str, Enum):
|
||||
WEBXDC_INSTANCE_DELETED = "WebxdcInstanceDeleted"
|
||||
CHATLIST_CHANGED = "ChatlistChanged"
|
||||
CHATLIST_ITEM_CHANGED = "ChatlistItemChanged"
|
||||
TEST_CHECKPOINT_EVENT = "TestCheckpointEvent"
|
||||
|
||||
|
||||
class ChatId(IntEnum):
|
||||
|
||||
@@ -6,12 +6,10 @@ import logging
|
||||
import os
|
||||
import subprocess
|
||||
import sys
|
||||
from queue import Queue
|
||||
from queue import Empty, Queue
|
||||
from threading import Event, Thread
|
||||
from typing import Any, Iterator, Optional
|
||||
|
||||
from .const import EventType
|
||||
|
||||
|
||||
class JsonRpcError(Exception):
|
||||
pass
|
||||
@@ -192,11 +190,12 @@ class Rpc:
|
||||
|
||||
def clear_all_events(self, account_id: int):
|
||||
"""Removes all queued-up events for a given account. Useful for tests."""
|
||||
id = self.trigger_checkpoint_event(account_id)
|
||||
while True:
|
||||
event = self.wait_for_event(account_id)
|
||||
if event.kind == EventType.TEST_CHECKPOINT_EVENT and event.id == id:
|
||||
break
|
||||
queue = self.get_queue(account_id)
|
||||
try:
|
||||
while True:
|
||||
queue.get_nowait()
|
||||
except Empty:
|
||||
pass
|
||||
|
||||
def __getattr__(self, attr: str):
|
||||
return RpcMethod(self, attr)
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
#define NAPI_VERSION 4
|
||||
#define NAPI_EXPERIMENTAL
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
@@ -288,9 +288,6 @@ pub struct InnerContext {
|
||||
|
||||
/// True if account has subscribed to push notifications via IMAP.
|
||||
pub(crate) push_subscribed: AtomicBool,
|
||||
|
||||
/// Counter for the id for the test checkpoint event that is used by tests.
|
||||
pub(crate) test_event_checkpoint_counter: Mutex<usize>,
|
||||
}
|
||||
|
||||
/// The state of ongoing process.
|
||||
@@ -448,7 +445,6 @@ impl Context {
|
||||
debug_logging: std::sync::RwLock::new(None),
|
||||
push_subscriber,
|
||||
push_subscribed: AtomicBool::new(false),
|
||||
test_event_checkpoint_counter: Mutex::new(0),
|
||||
};
|
||||
|
||||
let ctx = Context {
|
||||
@@ -1366,15 +1362,6 @@ impl Context {
|
||||
wal_fname.push("-wal");
|
||||
dbfile.with_file_name(wal_fname)
|
||||
}
|
||||
|
||||
/// Emit the test checkpoint event, used for tests.
|
||||
/// Returns a unique id of the emitted `TestCheckpointEvent`.
|
||||
pub async fn emit_test_checkpoint_event(&self) -> usize {
|
||||
let mut counter = self.inner.test_event_checkpoint_counter.lock().await;
|
||||
*counter = counter.wrapping_add(1);
|
||||
self.emit_event(EventType::TestCheckpointEvent { id: *counter });
|
||||
*counter
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns core version as a string.
|
||||
|
||||
@@ -302,11 +302,4 @@ pub enum EventType {
|
||||
/// ID of the changed chat
|
||||
chat_id: Option<ChatId>,
|
||||
},
|
||||
|
||||
/// Tests can trigger this event and then wait for it, to make sure all events before it were consumed.
|
||||
/// Useful for tests that test whether a specific event is emitted,
|
||||
TestCheckpointEvent {
|
||||
/// unique id to recognize the event
|
||||
id: usize,
|
||||
},
|
||||
}
|
||||
|
||||
@@ -785,17 +785,6 @@ impl TestContext {
|
||||
|
||||
chat_id
|
||||
}
|
||||
|
||||
/// Clears event queue.
|
||||
/// Works by emitting a `TestCheckpointEvent` and consuming all events until.
|
||||
/// times out after 10 seconds.
|
||||
pub async fn clear_events(&self) {
|
||||
let event_id = self.emit_test_checkpoint_event().await;
|
||||
self.evtracker.get_matching(|ev| match ev {
|
||||
EventType::TestCheckpointEvent { id } => event_id == *id,
|
||||
_ => false
|
||||
}).await;
|
||||
}
|
||||
}
|
||||
|
||||
impl Deref for TestContext {
|
||||
|
||||
Reference in New Issue
Block a user