diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 398b910..d563665 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -49,13 +49,10 @@ jobs: - name: Create a copy of `.env.example` run: just dotenv - - name: Generate Synapse Configuration - run: | - just gen_synapse_conf - - name: Use Test Homeserver run: | - sudo cp -f ./crates/test/fixtures/synapse/homeserver.yaml ./docker/synapse/homeserver.yaml + mkdir -p ./docker/synapse/media_stroe + cp -f ./crates/test/fixtures/synapse/* ./docker/synapse/homeserver.yaml - name: Run Docker Containers run: | @@ -77,14 +74,12 @@ jobs: - name: Retrieve Admin Access Token run: | just get_access_token - export COMMUNE_SYNAPSE_ADMIN_TOKEN=$(cat ./access_token.txt) - echo "COMMUNE_SYNAPSE_ADMIN_TOKEN=${COMMUNE_SYNAPSE_ADMIN_TOKEN}" >> $GITHUB_ENV - name: E2E Tests env: COMMUNE_SYNAPSE_ADMIN_TOKEN: ${{ env.COMMUNE_SYNAPSE_ADMIN_TOKEN }} run: | - cargo test -p test -- --test-threads=1 + just e2e -- --show-output - name: Print Logs if: always() diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 0b18fa0..c9657b1 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -63,26 +63,6 @@ You must run Docker services as for development. In order to avoid messing up the development environment, its recommended to use the synapse setup from `crates/test/fixtures/synapse` replacing it with `docker/synapse`. -The only difference should be the `database` section, which uses SQLite instead. - -```diff -database: -+ name: psycopg2 -+ args: -+ database: /data/homeserver.db -- name: psycopg2 -- txn_limit: 10000 -- allow_unsafe_locale: true -- args: -- user: synapse_user -- password: secretpassword -- database: synapse -- host: localhost -- port: 5432 -- cp_min: 5 -- cp_max: 10 -``` - > Make sure the `.env` file is created from the contents on `.env.example` ### Application Layout diff --git a/crates/test/fixtures/synapse/homeserver.yaml b/crates/test/fixtures/synapse/homeserver.yaml index 17fc85f..11fe33b 100644 --- a/crates/test/fixtures/synapse/homeserver.yaml +++ b/crates/test/fixtures/synapse/homeserver.yaml @@ -21,9 +21,17 @@ listeners: - names: [client, federation] compress: false database: - name: sqlite3 + name: psycopg2 + txn_limit: 10000 + allow_unsafe_locale: true args: - database: /data/homeserver.db + user: synapse_user + password: secretpassword + database: synapse + host: localhost + port: 5432 + cp_min: 5 + cp_max: 10 log_config: "/data/matrix.localhost.log.config" media_store_path: /data/media_store registration_shared_secret: "m@;wYOUOh0f:CH5XA65sJB1^q01~DmIriOysRImot,OR_vzN&B" @@ -70,4 +78,5 @@ rc_invites: per_user: per_second: 1000 burst_count: 1000 + # vim:ft=yaml diff --git a/crates/test/fixtures/synapse/matrix.localhost.log.config b/crates/test/fixtures/synapse/matrix.localhost.log.config index 832f0fa..1fda721 100644 --- a/crates/test/fixtures/synapse/matrix.localhost.log.config +++ b/crates/test/fixtures/synapse/matrix.localhost.log.config @@ -2,38 +2,34 @@ version: 1 formatters: precise: - format: '%(asctime)s - %(name)s - %(lineno)d - %(levelname)s - %(request)s - %(message)s' - handlers: - + file: + class: logging.handlers.TimedRotatingFileHandler + formatter: precise + filename: /data/homeserver.log + when: midnight + backupCount: 3 + encoding: utf8 + + buffer: + class: synapse.logging.handlers.PeriodicallyFlushingMemoryHandler + target: file + capacity: 10 console: class: logging.StreamHandler formatter: precise loggers: - # This is just here so we can leave `loggers` in the config regardless of whether - # we configure other loggers below (avoid empty yaml dict error). - _placeholder: - level: "INFO" - - - synapse.storage.SQL: # beware: increasing this to DEBUG will make synapse log sensitive # information such as access tokens. level: INFO - - - - root: level: INFO - - handlers: [console] -disable_existing_loggers: false \ No newline at end of file +disable_existing_loggers: false diff --git a/crates/test/src/matrix/events.rs b/crates/test/src/matrix/events.rs new file mode 100644 index 0000000..433ecda --- /dev/null +++ b/crates/test/src/matrix/events.rs @@ -0,0 +1,39 @@ +#[cfg(test)] +mod tests { + use std::sync::Once; + + use matrix::{ + admin::resources::room::{MessagesQuery, OrderBy}, + ruma_common::{RoomId, ServerName}, + ruma_events::AnyStateEvent, + }; + use rand::Rng; + use tokio::sync::OnceCell; + + #[tokio::test] + async fn send_room_message() { + let Test { client, .. } = TEST.get_or_init(util::init).await; + + // first join + let result = join_helper().await; + let rooms: Vec<_> = result.iter().map(|r| &r.0).collect(); + tracing::info!(?rooms, "joining all guests"); + + // check whether all guests are in the room and joined the expected room + for (room_id, guests, resps) in result { + let mut resp = AdminRoomService::get_members(&admin, &room_id) + .await + .unwrap(); + resp.members.sort(); + + assert!(resps.iter().all(|r| r.is_ok())); + let resps: Vec<_> = resps.into_iter().flatten().collect(); + + assert!(resps.iter().all(|r| r.room_id == *room_id)); + + for guest in guests { + assert!(resp.members.contains(&guest)); + } + } + } +} diff --git a/docker/.gitkeep b/docker/.gitkeep deleted file mode 100644 index e69de29..0000000 diff --git a/docker/synapse/.gitkeep b/docker/synapse/.gitkeep deleted file mode 100644 index e69de29..0000000 diff --git a/docker/synapse/media_store/.gitkeep b/docker/synapse/media_store/.gitkeep deleted file mode 100644 index e69de29..0000000 diff --git a/fixtures/synapse/homeserver.yaml b/fixtures/synapse/homeserver.yaml deleted file mode 100644 index 7769a09..0000000 --- a/fixtures/synapse/homeserver.yaml +++ /dev/null @@ -1,46 +0,0 @@ -# Configuration file for Synapse. -# -# This is a YAML file: see [1] for a quick introduction. Note in particular -# that *indentation is important*: all the elements of a list or dictionary -# should have the same indentation. -# -# [1] https://docs.ansible.com/ansible/latest/reference_appendices/YAMLSyntax.html -# -# For more information on how to configure Synapse, including a complete accounting of -# each option, go to docs/usage/configuration/config_documentation.md or -# https://matrix-org.github.io/synapse/latest/usage/configuration/config_documentation.html -server_name: "matrix.localhost" -pid_file: /data/homeserver.pid -listeners: - - port: 8008 - tls: false - type: http - x_forwarded: true - bind_addresses: ['::', '0.0.0.0'] - resources: - - names: [client, federation] - compress: false -database: - name: psycopg2 - txn_limit: 10000 - allow_unsafe_locale: true - args: - user: synapse_user - password: secretpassword - database: synapse - host: localhost - port: 5432 - cp_min: 5 - cp_max: 10 -log_config: "/data/matrix.localhost.log.config" -media_store_path: /data/media_store -registration_shared_secret: "m@;wYOUOh0f:CH5XA65sJB1^q01~DmIriOysRImot,OR_vzN&B" -report_stats: true -macaroon_secret_key: "XND.g+P_7wz.Yx:i6js.Eh;=jG*#uWBIe;X2OoX78^E,LVJ;8c" -form_secret: "pS7pR@AFJD~BtUAqH^ku5Kenz1X^Hol0E_+xhwvohOrkx;sMoO" -signing_key_path: "/data/matrix.localhost.signing.key" -trusted_key_servers: - - server_name: "matrix.org" - - -# vim:ft=yaml \ No newline at end of file diff --git a/fixtures/synapse/matrix.localhost.log.config b/fixtures/synapse/matrix.localhost.log.config deleted file mode 100644 index 832f0fa..0000000 --- a/fixtures/synapse/matrix.localhost.log.config +++ /dev/null @@ -1,39 +0,0 @@ -version: 1 - -formatters: - precise: - - format: '%(asctime)s - %(name)s - %(lineno)d - %(levelname)s - %(request)s - %(message)s' - - -handlers: - - - console: - class: logging.StreamHandler - formatter: precise - -loggers: - # This is just here so we can leave `loggers` in the config regardless of whether - # we configure other loggers below (avoid empty yaml dict error). - _placeholder: - level: "INFO" - - - - synapse.storage.SQL: - # beware: increasing this to DEBUG will make synapse log sensitive - # information such as access tokens. - level: INFO - - - - -root: - level: INFO - - - handlers: [console] - - -disable_existing_loggers: false \ No newline at end of file diff --git a/fixtures/synapse/matrix.localhost.signing.key b/fixtures/synapse/matrix.localhost.signing.key deleted file mode 100644 index 090b449..0000000 --- a/fixtures/synapse/matrix.localhost.signing.key +++ /dev/null @@ -1 +0,0 @@ -ed25519 a_VKUD FXu3HoEKJdiMh1e+3dW8kO/P8ldSdNzdV+/vg9wdowE