@@ -510,22 +510,30 @@ describe("event-queue outbox", () => {
510510 expect ( loggerMock . callsLengths ( ) . error ) . toEqual ( 0 ) ;
511511 } ) ;
512512
513- it ( "req reject should be caught for send" , async ( ) => {
513+ it ( "req reject should be caught for send and rollback transaction " , async ( ) => {
514514 const service = await cds . connect . to ( "NotificationService" ) ;
515515 const outboxedService = cds . outboxed ( service ) . tx ( context ) ;
516+ const lockId = cds . utils . uuid ( ) ;
516517 await outboxedService . send ( "rejectEvent" , {
517518 to : "to" ,
518519 subject : "subject" ,
519520 body : "body" ,
521+ lockId,
520522 } ) ;
521523 await commitAndOpenNew ( ) ;
522524 await testHelper . selectEventQueueAndExpectOpen ( tx , { expectedLength : 1 } ) ;
523525
526+ await commitAndOpenNew ( ) ;
524527 await processEventQueue ( tx . context , "CAP_OUTBOX" , service . name ) ;
525528 await commitAndOpenNew ( ) ;
526- const [ event ] = await testHelper . selectEventQueueAndReturn ( tx , {
527- expectedLength : 1 ,
528- additionalColumns : [ "error" ] ,
529+
530+ const [ event ] = await cds . tx ( { } , async ( tx ) => {
531+ const lock = await tx . run ( SELECT . one . from ( "sap.eventqueue.Lock" ) . where ( { code : lockId } ) ) ;
532+ expect ( lock ) . toBeUndefined ( ) ;
533+ return await testHelper . selectEventQueueAndReturn ( tx , {
534+ expectedLength : 1 ,
535+ additionalColumns : [ "error" ] ,
536+ } ) ;
529537 } ) ;
530538 expect ( event . status ) . toEqual ( EventProcessingStatus . Error ) ;
531539 expect ( JSON . parse ( event . error ) ) . toEqual (
@@ -542,16 +550,22 @@ describe("event-queue outbox", () => {
542550 it ( "req reject should cause an error for emit" , async ( ) => {
543551 const service = await cds . connect . to ( "NotificationService" ) ;
544552 const outboxedService = cds . outboxed ( service ) . tx ( context ) ;
553+ const lockId = cds . utils . uuid ( ) ;
545554 await outboxedService . emit ( "rejectEvent" , {
546555 to : "to" ,
547556 subject : "subject" ,
548557 body : "body" ,
558+ lockId,
549559 } ) ;
550560 await commitAndOpenNew ( ) ;
551561 await testHelper . selectEventQueueAndExpectOpen ( tx , { expectedLength : 1 } ) ;
552562
553- await processEventQueue ( tx . context , "CAP_OUTBOX" , service . name ) ;
554563 await commitAndOpenNew ( ) ;
564+ await processEventQueue ( tx . context , "CAP_OUTBOX" , service . name ) ;
565+ await cds . tx ( { } , async ( tx ) => {
566+ const lock = await tx . run ( SELECT . one . from ( "sap.eventqueue.Lock" ) . where ( { code : lockId } ) ) ;
567+ expect ( lock ) . toBeUndefined ( ) ;
568+ } ) ;
555569 await testHelper . selectEventQueueAndExpectError ( tx , { expectedLength : 1 } ) ;
556570 expect ( loggerMock . callsLengths ( ) . error ) . toEqual ( 1 ) ;
557571 expect ( loggerMock . calls ( ) . error ) . toMatchSnapshot ( ) ;
@@ -566,7 +580,9 @@ describe("event-queue outbox", () => {
566580 body : "body" ,
567581 } ) ;
568582 await commitAndOpenNew ( ) ;
569- await testHelper . selectEventQueueAndExpectOpen ( tx , { expectedLength : 1 } ) ;
583+ await cds . tx ( { } , async ( tx ) => {
584+ await testHelper . selectEventQueueAndExpectOpen ( tx , { expectedLength : 1 } ) ;
585+ } ) ;
570586
571587 await processEventQueue ( tx . context , "CAP_OUTBOX" , service . name ) ;
572588 await commitAndOpenNew ( ) ;
@@ -582,10 +598,12 @@ describe("event-queue outbox", () => {
582598 to : "to" ,
583599 subject : "subject" ,
584600 body : "body" ,
601+ lockId : cds . utils . uuid ( ) ,
585602 } ) ;
586603 await commitAndOpenNew ( ) ;
587604 await testHelper . selectEventQueueAndExpectOpen ( tx , { expectedLength : 1 } ) ;
588605
606+ await commitAndOpenNew ( ) ;
589607 await processEventQueue ( tx . context , "CAP_OUTBOX" , service . name ) ;
590608 await commitAndOpenNew ( ) ;
591609 await testHelper . selectEventQueueAndExpectError ( tx , { expectedLength : 1 } ) ;
0 commit comments