diff options
author | piegames <git@piegames.de> | 2021-09-29 11:41:35 +0200 |
---|---|---|
committer | piegames <git@piegames.de> | 2021-10-26 22:13:22 +0200 |
commit | 4bf7da5720c6de80251f2dbef13eac79a0fe4959 (patch) | |
tree | d352f0d3cdcfbf49eb0aa829956d9da936170ae7 /nixos/tests/matrix-appservice-irc.nix | |
parent | f34e8105cb8f5f26e009a1ab4154112467d99672 (diff) | |
download | nixpkgs-4bf7da5720c6de80251f2dbef13eac79a0fe4959.tar nixpkgs-4bf7da5720c6de80251f2dbef13eac79a0fe4959.tar.gz nixpkgs-4bf7da5720c6de80251f2dbef13eac79a0fe4959.tar.bz2 nixpkgs-4bf7da5720c6de80251f2dbef13eac79a0fe4959.tar.lz nixpkgs-4bf7da5720c6de80251f2dbef13eac79a0fe4959.tar.xz nixpkgs-4bf7da5720c6de80251f2dbef13eac79a0fe4959.tar.zst nixpkgs-4bf7da5720c6de80251f2dbef13eac79a0fe4959.zip |
nixos/tests/matrix-appservice-irc: Fix test
Migrate from the python matrix SDK to Matrix NIO
Diffstat (limited to 'nixos/tests/matrix-appservice-irc.nix')
-rw-r--r-- | nixos/tests/matrix-appservice-irc.nix | 94 |
1 files changed, 54 insertions, 40 deletions
diff --git a/nixos/tests/matrix-appservice-irc.nix b/nixos/tests/matrix-appservice-irc.nix index 264142a9066..cf1fae16312 100644 --- a/nixos/tests/matrix-appservice-irc.nix +++ b/nixos/tests/matrix-appservice-irc.nix @@ -25,7 +25,7 @@ import ./make-test-python.nix ({ pkgs, ... }: "bind_address" = ""; "port" = 8448; "resources" = [ - { "compress" = true; "names" = [ "client" "webclient" ]; } + { "compress" = true; "names" = [ "client" ]; } { "compress" = false; "names" = [ "federation" ]; } ]; "tls" = false; @@ -85,45 +85,60 @@ import ./make-test-python.nix ({ pkgs, ... }: client = { pkgs, ... }: { environment.systemPackages = [ (pkgs.writers.writePython3Bin "do_test" - { libraries = [ pkgs.python3Packages.matrix-client ]; } '' + { libraries = [ pkgs.python3Packages.matrix-nio ]; } '' import socket - from matrix_client.client import MatrixClient + from nio import AsyncClient, RoomMessageText from time import sleep - - matrix = MatrixClient("${homeserverUrl}") - matrix.register_with_password(username="alice", password="foobar") - - irc = socket.socket(socket.AF_INET, socket.SOCK_STREAM) - irc.connect(("ircd", 6667)) - irc.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1) - irc.send(b"USER bob bob bob :bob\n") - irc.send(b"NICK bob\n") - - m_room = matrix.join_room("#irc_#test:homeserver") - irc.send(b"JOIN #test\n") - - # plenty of time for the joins to happen - sleep(10) - - m_room.send_text("hi from matrix") - irc.send(b"PRIVMSG #test :hi from irc \r\n") - - print("Waiting for irc message...") - while True: - buf = irc.recv(10000) - if b"hi from matrix" in buf: - break - - print("Waiting for matrix message...") - - - def callback(room, e): - if "hi from irc" in e['content']['body']: - exit(0) - - - m_room.add_listener(callback, "m.room.message") - matrix.listen_forever() + import asyncio + + + async def run(): + matrix = AsyncClient("${homeserverUrl}") + await matrix.register("alice", "foobar") + + irc = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + irc.connect(("ircd", 6667)) + irc.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1) + irc.send(b"USER bob bob bob :bob\n") + irc.send(b"NICK bob\n") + + room_id = (await matrix.join("#irc_#test:homeserver")).room_id + irc.send(b"JOIN #test\n") + + # plenty of time for the joins to happen + sleep(10) + + # Exchange messages + await matrix.room_send( + room_id=room_id, + message_type="m.room.message", + content={ + "msgtype": "m.text", + "body": "hi from matrix" + } + ) + irc.send(b"PRIVMSG #test :hi from irc \r\n") + + print("Waiting for irc message...") + while True: + buf = irc.recv(10000) + if b"hi from matrix" in buf: + print("Got IRC message") + break + + print("Waiting for matrix message...") + + async def callback(room, e): + if "hi from irc" in e.body: + print("Got Matrix message") + await matrix.close() + exit(0) # Actual exit point + + matrix.add_event_callback(callback, RoomMessageText) + await matrix.sync_forever() + exit(1) # Unreachable + + asyncio.run(run()) '' ) ]; @@ -158,7 +173,6 @@ import ./make-test-python.nix ({ pkgs, ... }: homeserver.wait_for_open_port(8448) with subtest("ensure messages can be exchanged"): - client.succeed("do_test") + client.succeed("do_test >&2") ''; - }) |