Skip to content

Introduce names for FiniteMachine instances#73

Open
raw-bin wants to merge 1 commit intopiotrmurach:masterfrom
raw-bin:add_name
Open

Introduce names for FiniteMachine instances#73
raw-bin wants to merge 1 commit intopiotrmurach:masterfrom
raw-bin:add_name

Conversation

@raw-bin
Copy link

@raw-bin raw-bin commented Aug 8, 2021

Describe the change

This PR introduces the ability to specify an optional name for new FiniteMachine instances.

Why are we doing this?

Currently transition logs don't specify the FiniteMachine for which event transitions happen. This makes it hard to understand or post process the logs.

Benefits

It will now be possible to disambiguate event transitions that occur in the context of different FiniteMachine instances.

Drawbacks

None.

Requirements

  • Tests written & passing locally? (NOTE: No new tests were added but existing tests were suitably updated)
  • Code style checked?
  • Rebased with master branch?
  • Documentation updated?
  • Changelog updated?

Copy link
Owner

@piotrmurach piotrmurach left a comment

Choose a reason for hiding this comment

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

Thank you for submitting this PR! Things are looking good. I added few comments. Most importantly, we need another test for when uuid gets generated.

fsm.stop(1, 2)
output.rewind
expect(output.read).to match(/Transition: @event=stop @with=\[1,2\] yellow -> red/)
expect(output.read).to match(/Transition: @machine=TrafficLights @event=stop @with=\[1,2\] yellow -> red/)

Choose a reason for hiding this comment

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

Metrics/LineLength: Line is too long. [110/80]

fsm.slow
output.rewind
expect(output.read).to match(/Transition: @event=slow green -> yellow/)
expect(output.read).to match(/Transition: @machine=TrafficLights @event=slow green -> yellow/)

Choose a reason for hiding this comment

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

Metrics/LineLength: Line is too long. [98/80]

logger.report_transition('TrafficLights', :go, :red, :green)

expect(log).to have_received(:info).with("Transition: @event=go red -> green")
expect(log).to have_received(:info).with("Transition: @machine=TrafficLights @event=go red -> green")

Choose a reason for hiding this comment

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

Metrics/LineLength: Line is too long. [105/80]

Copy link
Owner

@piotrmurach piotrmurach left a comment

Choose a reason for hiding this comment

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

Thank you for working on the suggestions. We still need another test for when the name isn't specified to ensure generating short UUID works correctly.


it "logs transitions" do
fsm = FiniteMachine.new log_transitions: true do
fsm = FiniteMachine.new name: "TrafficLights", log_transitions: true do
Copy link
Owner

Choose a reason for hiding this comment

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

We need a test case when the name is not specified. I'd probably keep this test as it was without the name and test the short UUID generation. Let me know if you need any pointers on how to test this.

Copy link
Author

Choose a reason for hiding this comment

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

Understood. I'll give it a shot and reach out if I run into trouble. Thanks.

Copy link
Author

Choose a reason for hiding this comment

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

Hi @piotrmurach: Just wanted to chime in and let you know that I got distracted but will get back to this in the next couple of days. Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants