@@ -84,7 +84,9 @@ export class ReadingCaseContract extends BaseCaseContract {
8484 this . initialContext . logger . maintainerDebug (
8585 `Verifying contract between '${ this . currentContract . description . consumerName } ' and '${ this . currentContract . description . providerName } '. There are '${ this . currentContract . examples . length } ' examples` ,
8686 ) ;
87- const finishedIndicators = [ ] ;
87+ const interactionFinishedIndicators : Promise < unknown > [ ] = [ ] ;
88+ const interactionFinishers : Array < ( ) => void > = [ ] ;
89+
8890 this . currentContract . examples . forEach ( ( example , index ) => {
8991 if ( example . result !== 'VERIFIED' ) {
9092 throw new CaseCoreError (
@@ -96,11 +98,20 @@ export class ReadingCaseContract extends BaseCaseContract {
9698 this . initialContext . logger . maintainerDebug (
9799 `Preparing test framework's callback for: ${ names . mockName } ` ,
98100 ) ;
99- let exampleFinished : ( ) => void ;
100101
101- finishedIndicators . push (
102- new Promise < void > ( ( resolve ) => {
103- exampleFinished = resolve ;
102+ interactionFinishedIndicators . push (
103+ new Promise < void > ( ( resolve , reject ) => {
104+ const timeout = setTimeout ( ( ) => {
105+ this . initialContext . logger . error (
106+ `Timeout in interaction[${ index } ]` ,
107+ ) ;
108+ reject ( new Error ( names . mockName ) ) ;
109+ } , 30000 ) ;
110+
111+ interactionFinishers [ index ] = ( ) => {
112+ clearTimeout ( timeout ) ;
113+ resolve ( ) ;
114+ } ;
104115 } ) ,
105116 ) ;
106117 runTestCb ( names . mockName , ( ) =>
@@ -134,16 +145,20 @@ export class ReadingCaseContract extends BaseCaseContract {
134145 ) ;
135146 } )
136147 . finally ( ( ) => {
148+ this . initialContext . logger . deepMaintainerDebug (
149+ `Interaction[${ index } ] type of finisher` ,
150+ interactionFinishers [ index ] ,
151+ ) ;
137152 this . initialContext . logger . maintainerDebug (
138153 `Interaction[${ index } ] completed: ${ names . mockName } ` ,
139154 ) ;
140- exampleFinished ( ) ;
155+ interactionFinishers [ index ] ?. ( ) ;
141156 } ) ,
142157 ) ;
143158 } ) ;
144159 let publishFinished : ( ) => void ;
145-
146- finishedIndicators . push (
160+ const publishFinishedIndicators = [ ] ;
161+ publishFinishedIndicators . push (
147162 new Promise < void > ( ( resolve ) => {
148163 publishFinished = resolve ;
149164 } ) ,
@@ -156,20 +171,25 @@ export class ReadingCaseContract extends BaseCaseContract {
156171 this . initialContext . logger . maintainerDebug (
157172 'Test callback for ending record' ,
158173 ) ;
159- return this . endRecord ( ) . finally ( ( ) => {
160- this . initialContext . logger . maintainerDebug (
161- `Publishing contract callback completed` ,
162- ) ;
163- publishFinished ( ) ;
164- } ) ;
174+ return Promise . allSettled ( interactionFinishedIndicators )
175+ . then ( ( ) => this . endRecord ( ) )
176+ . finally ( ( ) => {
177+ this . initialContext . logger . maintainerDebug (
178+ `Publishing contract callback completed` ,
179+ ) ;
180+ publishFinished ( ) ;
181+ } ) ;
165182 } ,
166183 ) ;
167184 if (
168185 this . initialContext [ '_case:currentRun:context:internals' ] &&
169186 this . initialContext [ '_case:currentRun:context:internals' ]
170187 . asyncVerification
171188 ) {
172- return Promise . all ( finishedIndicators ) . then ( ( ) => { } ) ;
189+ return Promise . all ( [
190+ ...interactionFinishedIndicators ,
191+ ...publishFinishedIndicators ,
192+ ] ) . then ( ( ) => { } ) ;
173193 }
174194 return undefined ;
175195 }
0 commit comments