From e6087db69c3e9e7364bcca8b62dad64317ff5502 Mon Sep 17 00:00:00 2001 From: holger krekel Date: Sat, 18 May 2024 17:54:12 +0200 Subject: [PATCH] bertter debugging --- .../src/deltachat_rpc_client/const.py | 1 + .../src/deltachat_rpc_client/rpc.py | 2 +- .../tests/run-iroh-example.py | 75 +++++++++++++++++++ src/context.rs | 4 +- 4 files changed, 79 insertions(+), 3 deletions(-) create mode 100644 deltachat-rpc-client/tests/run-iroh-example.py diff --git a/deltachat-rpc-client/src/deltachat_rpc_client/const.py b/deltachat-rpc-client/src/deltachat_rpc_client/const.py index b0566e03d..4bfc6c232 100644 --- a/deltachat-rpc-client/src/deltachat_rpc_client/const.py +++ b/deltachat-rpc-client/src/deltachat_rpc_client/const.py @@ -62,6 +62,7 @@ class EventType(str, Enum): CHATLIST_CHANGED = "ChatlistChanged" CHATLIST_ITEM_CHANGED = "ChatlistItemChanged" CONFIG_SYNCED = "ConfigSynced" + WEBXDC_REALTIME_DATA = "WebxdcRealtimeData" class ChatId(IntEnum): diff --git a/deltachat-rpc-client/src/deltachat_rpc_client/rpc.py b/deltachat-rpc-client/src/deltachat_rpc_client/rpc.py index fc8dba557..9d4fe6552 100644 --- a/deltachat-rpc-client/src/deltachat_rpc_client/rpc.py +++ b/deltachat-rpc-client/src/deltachat_rpc_client/rpc.py @@ -177,7 +177,7 @@ class Rpc: account_id = event["contextId"] queue = self.get_queue(account_id) event = event["event"] - logging.debug("account_id=%d got an event %s", account_id, event) + print("account_id=%d got an event %s" % (account_id, event), file=sys.stderr) queue.put(event) except Exception: # Log an exception if the event loop dies. diff --git a/deltachat-rpc-client/tests/run-iroh-example.py b/deltachat-rpc-client/tests/run-iroh-example.py new file mode 100644 index 000000000..afe506162 --- /dev/null +++ b/deltachat-rpc-client/tests/run-iroh-example.py @@ -0,0 +1,75 @@ +#!/usr/bin/env python3 +""" +Example echo bot without using hooks +""" + +import pytest + +import time +import os +import sys +import logging +import random +import itertools +import sys + +from deltachat_rpc_client import DeltaChat, EventType, SpecialContactId + +@pytest.fixture(scope="session", autouse=True) +def _chatmailenv(): + os.environ["CHATMAIL_DOMAIN"] = "nine.testrun.org" + +@pytest.fixture() +def path_to_webxdc(): + return "../test-data/webxdc/chess.xdc" + + +def test_basic_iroh_jsonrpc(acfactory, path_to_webxdc): + ac1, ac2 = acfactory.get_online_accounts(2) + ac1.create_chat(ac2) + ac2.create_chat(ac1) + acfactory.send_message(from_account=ac1, to_account=ac2, text="ping0") + snapshot = ac2.get_message_by_id(ac2.wait_for_incoming_msg_event().msg_id).get_snapshot() + assert snapshot.text == "ping0" + + def log(msg): + print() + print("*" * 80 + "\n" + msg + "\n", file=sys.stderr) + print() + + # share a webxdc app between ac1 and ac2 + ac1_webxdc_msg = acfactory.send_message( + from_account=ac1, to_account=ac2, text="play", + file=path_to_webxdc) + ac2_webxdc_msg = ac2.get_message_by_id(ac2.wait_for_incoming_msg_event().msg_id) + snapshot = ac2_webxdc_msg.get_snapshot() + assert snapshot.text == "play" + + # send iroh announcements + log("sending ac1 -> ac2 realtime advertisement") + ac1._rpc.send_webxdc_realtime_advertisement(ac1.id, ac1_webxdc_msg.id) + acfactory.send_message(from_account=ac1, to_account=ac2, text="ping1") + log("sending ac2 -> ac1 realtime advertisement") + ac2._rpc.send_webxdc_realtime_advertisement(ac2.id, ac2_webxdc_msg.id) + acfactory.send_message(from_account=ac2, to_account=ac1, text="ping2") + snapshot = ac2.get_message_by_id(ac2.wait_for_incoming_msg_event().msg_id).get_snapshot() + assert snapshot.text == "ping1" + snapshot = ac1.get_message_by_id(ac1.wait_for_incoming_msg_event().msg_id).get_snapshot() + assert snapshot.text == "ping2" + + # send realtime data + for i in range(2): + print("sleeping waiting") + time.sleep(1) + + log("sending realtime data ac1 -> ac2") + ac1._rpc.send_webxdc_realtime_data(ac1.id, ac1_webxdc_msg.id, [13, 15, 17]) + log("ac2: waiting for realtime data") + while 1: + event = ac2.wait_for_event() + if event.kind == EventType.WEBXDC_REALTIME_DATA: + assert 0 + else: + log(f"ignoring {event.kind}") + + assert 0, "fail" diff --git a/src/context.rs b/src/context.rs index 2fdc7fd87..b6da83a98 100644 --- a/src/context.rs +++ b/src/context.rs @@ -457,8 +457,8 @@ impl Context { }; tracing_subscriber::registry() - .with(tracing_subscriber::fmt::layer().with_writer(std::io::stdout)) - .with(DeltaLayer(ctx.clone())) + .with(tracing_subscriber::fmt::layer().with_writer(std::io::stderr)) + // .with(DeltaLayer(ctx.clone())) .with( EnvFilter::builder() .with_default_directive(tracing_subscriber::filter::LevelFilter::DEBUG.into())