looplab / eventhorizon

Event Sourcing for Go!
Apache License 2.0
1.57k stars 196 forks source link

fix(eventstore/mongodb): pass context with transaction to inTx handler #386

Closed klowdo closed 2 years ago

klowdo commented 2 years ago

Description

pass context with transaction to eventHandlerInTX

Affected Components

Related Issues

Solution and Design

passes the txCtx with transaction to handler instead of empty context

Steps to test and verify

In handler that is assigned WithEventHandlerInTX write this below and you should get no session without this fix

func (c *myHandler)  HandleEvent(ctx context.Context, e eh.Event) error{
  session := mongodb.SessionFromContext(ctx)
  if session  == nil {
    fmt.Println("no session")
  } else {
     fmt.Printf("session: %v", session.ID())
  }
}
coveralls commented 2 years ago

Coverage Status

Coverage increased (+0.07%) to 68.813% when pulling 441b029a01cd8621fa47091adf780749e4f99432 on klowdo:main into d9133a08eca7f4009fb9f22907bb3199dafdca2d on looplab:main.