Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrap event::Cucumber in Event to allow metadata #145

Merged
merged 29 commits into from
Oct 26, 2021
Merged

Conversation

ilslv
Copy link
Member

@ilslv ilslv commented Oct 22, 2021

Synopsis

Despite there is no use for it now, it can become useful later. For example in implementation of JUnit Writer.

Solution

Pair DateTime with every Cucumber event to avoid breaking API in the future.

Checklist

  • Created PR:
    • In draft mode
    • Name contains Draft: prefix
    • Name contains issue reference
    • Has assignee
  • Documentation is updated (if required)
  • Tests are updated (if required)
  • Changes conform code style
  • CHANGELOG entry is added (if required)
  • FCM (final commit message) is posted
    • and approved
  • Review is completed and changes are approved
  • Before merge:
    • Milestone is set
    • PR's name and description are correct and up-to-date
    • Draft: prefix is removed
    • All temporary labels are removed

This PR is nominated at RU RustCon Contest

@ilslv ilslv added the enhancement Improvement of existing features or bugfix label Oct 22, 2021
@ilslv ilslv added this to the 0.10 milestone Oct 22, 2021
@ilslv ilslv self-assigned this Oct 22, 2021
@ilslv
Copy link
Member Author

ilslv commented Oct 22, 2021

FCM

Wrap `event::Cucumber` into `Event` to support optional metadata (#145)

- add `timestamps` Cargo feature injecting timestamps into `Event`s

@ilslv ilslv marked this pull request as ready for review October 25, 2021 05:15
Copy link
Member

@tyranron tyranron left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ilslv I think we can go with a better design. Ping me tomorrow to discuss this in a talk.

LocalBoxStream<'static, parser::Result<event::Cucumber<W>>>;
type EventStream = LocalBoxStream<
'static,
(parser::Result<event::Cucumber<W>>, DateTime<Utc>),
Copy link
Member

@tyranron tyranron Oct 25, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMHO, this is not very good decision, now we have the code base polluted with those tuples and signatures became worse.

I see here two ways:

  1. Attach DateTime directly to events types and errors.
  2. Instead of (T, DateTime) pairs have DateTimed<T> wrapper, which encapsulates the stuff and provides obvious interface to inner values.

With the option 2, we will need to only change type signatures, without touching any code. Furthermore, this way we can hide it completely behind a feature gate, so it can be used only for those Writers which really need it.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tyranron

Attach DateTime directly to events types and errors.

As all events are nested enums, we'll have to put DateTime in every variant of the Cucumber event

pub enum Cucumber<World> {
    /// [`Cucumber`] execution being started.
    Started(DateTime<Utc>),

    /// [`Feature`] event.
    Feature(DateTime<Utc>, Arc<gherkin::Feature>, Feature<World>),

    /// [`Cucumber`] execution being finished.
    Finished(DateTime<Utc>),
}

Matching over it will be very painful.

Instead of (T, DateTime) pairs have DateTimed wrapper, which encapsulates the stuff and provides obvious interface to inner values.

👍

With the option 2, we will need to only change type signatures, without touching any code.

Not really, especially in case of writer::Normalized. There we store only event::Step and path to it: Feature, Option<Rule>, Scenario. Then we rebuild it with Cucumber::scenario(feat, rule, sc, ev) when it's time to emit it. But it's pretty easy to store DateTimes of those events and already done in this PR.

Furthermore, this way we can hide it completely behind a feature gate, so it can be used only for those Writers which really need it.

I'm not sure we should. This will cause Writer trait to be different in cases when feature is on or off (same for Runner)

pub trait Writer<World> {
    type Cli: StructOptInternal;

    async fn handle_event(
        &mut self,
        ev: parser::Result<event::Cucumber<World>>,
        #[cfg(feature = "event_datetime")] // I don't think it's pleasant API to use
        at: DateTime<Utc>,
        cli: &Self::Cli,
    );
}

@ilslv ilslv changed the title Pair DateTime with every Cucumber event Wrap event::Cucumber in Event to add metadata Oct 26, 2021
@ilslv ilslv requested a review from tyranron October 26, 2021 14:03
@tyranron tyranron changed the title Wrap event::Cucumber in Event to add metadata Wrap event::Cucumber in Event to allow metadata Oct 26, 2021
@ilslv ilslv changed the title Wrap event::Cucumber in Event to allow metadata Wrap event::Cucumber in Event to add metadata Oct 26, 2021
@ilslv ilslv changed the title Wrap event::Cucumber in Event to add metadata Wrap event::Cucumber in Event to allow metadata Oct 26, 2021
Copy link
Member

@tyranron tyranron left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A little bit of bikesheddings, but generally, that's it!

@ilslv good job 👍

@tyranron tyranron merged commit dadf8ec into main Oct 26, 2021
@tyranron tyranron deleted the add-datetime-to-events branch October 26, 2021 16:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Improvement of existing features or bugfix
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants