matrix-org / matrix-org/matrix-rust-sdk

testing: use more the `EventFactory` to get rid of `sync_timeline_event!` and `EventBuilder`

Open
#3,716 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

good first issue help wanted
Dominant language
Rust
Stars
2.3k
Forks
500
Avg merge
1d 16h
Merged PRs (30d)
106

Description

The `EventBuilder` struct/methods and `sync_timeline_event!` macros are used all over the place, but they're quite verbose and not the easier to use, when usually tests want simple things ("a plain text message with that content sent from this user") and don't care about low-level Matrix details.

So as to improve this, I've added an `EventFactory` struct that makes it easier to write such events, by chaining calls, and taking care of the fields that always need to be set (if necessary).

It would be great to fully get rid of `EventBuilder` and `sync_timeline_event!`, so we don't have three ways of defining test events, but a single one. I've started migrating in a few PRs, but I think this is a great way to get accointed with the code base by making relatively simple changes:

- look at a use of `EventBuilder` or `sync_timeline_event!`
- consider if it can be replaced by using an `EventFactory` instead
- if yes, do the replacement
- some tests do already have an `EventFactory`, often called `factory`, or a plain `f` in the code; reuse those if present, or follow that same naming convention for new uses.
- if no: consider adding new methods/helpers to the `EventFactory`. This might be a bit more involved, so if you're chasing the good first issue part of this issue, then I'd recommend doing the plain replacements instead, aka the previous bullet item.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Search the repository for EventBuilder and sync_timeline_event!, then inspect nearby uses of EventFactory, including existing factory or f variables. Replace straightforward test-event construction with EventFactory while preserving each test's behavior; the migration is done when these older helpers are no longer needed for the covered uses.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
testing-qa
Issue type
Refactor
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.