alexeyzimarev / MassTransit.EventStoreIntegration

EventStore persistence for MassTransit
Apache License 2.0
49 stars 14 forks source link

How to manually persist saga instance in specified state #1

Closed pblachut closed 7 years ago

pblachut commented 7 years ago

I wonder if it is possible to persist manually stream of events which will represent a saga instance in specified state?

I try to do some integration tests connected with sagas persisted in ES, here is my scenario:

  1. Prepare stream with events:
    • SagaInstanceTransitioned (Initial)
    • event1
    • SagaInstanceTransitioned (state1)
  2. Publish event2 which will change saga state from state1 to state2
  3. Verify if saga has changed the state (state2)

During publishing of event2 I receive error that event2 is not expected in Initial saga state (like the saga would not exist). I suppose that I`m missing some MT configuration (using RabbitMQ).

Can you give me some advice if such scenario is possible?

alexeyzimarev commented 7 years ago

I would not consider this as any thing related to the persistence. If you want to test your saga - you need to use test harnesses provided by MassTransit.

misiektg86 commented 7 years ago

@pblachut if you want to preinitialize your saga in integration test then you probably have to publish your messages through MT. This will add events to your saga repository stream.

pblachut commented 7 years ago

Regarding point no 2: I publish message on the bus which which should generate transition to state 2. It`s integration test and saga is not the only thing.

alexeyzimarev commented 7 years ago

This is how you test Automatonymous sagas: https://github.com/MassTransit/MassTransit/blob/develop/src/MassTransit.AutomatonymousIntegration.Tests/Testing_Specs.cs

But you do not need to test with persistence unless you absolutely need to, this will involve embedded ES and it will become too slow. In-memory persistence is just fine to test the saga logic.

alexeyzimarev commented 7 years ago

But looking at your initial post again (sorry I was reading from mobile) I can conclude that the stream name does not match, you can also check there.

pblachut commented 7 years ago

Thanks for your response. Stream name was good, problem is in the state of the bus.

I have changed my test to setup SUT by send all messages on the bus (instead manually persistance saga state to ES). It is not perfect situation (in the test I check handling of two messages) but based on links which you have sent it will be hard to get better results. Thanks!