@@ -72,7 +72,7 @@ export function createReplaneServerMock(handler: ReplaneServerMockHandler) {
7272 } ) ;
7373 }
7474
75- const body = JSON . parse ( await req . json ( ) ) as StartReplicationStreamBody ;
75+ const body = ( await req . json ( ) ) as StartReplicationStreamBody ;
7676
7777 if ( ! Array . isArray ( body . currentConfigs ) ) {
7878 return new Response ( "Invalid request" , { status : 400 } ) ;
@@ -198,48 +198,68 @@ export class MockReplaneServerController {
198198export class MockReplaneServerConnection {
199199 private readonly _events = new Channel < ReplicationStreamRecord > ( ) ;
200200 private readonly _signal ?: AbortSignal ;
201+ private _closed = false ;
201202
202203 constructor (
203- private readonly body : StartReplicationStreamBody ,
204+ private readonly _body : StartReplicationStreamBody ,
204205 signal ?: AbortSignal
205206 ) {
206207 this . _signal = signal ;
207208
208209 // Close the channel when the signal is aborted
209210 if ( signal ) {
210- signal . addEventListener ( "abort" , ( ) => {
211+ if ( signal . aborted ) {
212+ this . _closed = true ;
211213 this . _events . close ( ) ;
212- } ) ;
214+ } else {
215+ signal . addEventListener ( "abort" , ( ) => {
216+ this . _closed = true ;
217+ this . _events . close ( ) ;
218+ } ) ;
219+ }
213220 }
214221 }
215222
216223 get signal ( ) : AbortSignal | undefined {
217224 return this . _signal ;
218225 }
219226
227+ get hasSignal ( ) : boolean {
228+ return this . _signal !== undefined ;
229+ }
230+
220231 get aborted ( ) : boolean {
221- return this . _signal ?. aborted ?? false ;
232+ return this . _closed || ( this . _signal ?. aborted ?? false ) ;
233+ }
234+
235+ get closed ( ) : boolean {
236+ return this . _closed ;
222237 }
223238
224239 get events ( ) : AsyncIterable < ReplicationStreamRecord > {
225240 return this . _events ;
226241 }
227242
243+ get requestBody ( ) : StartReplicationStreamBody {
244+ return this . _body ;
245+ }
246+
228247 async push ( event : ReplicationStreamRecord ) {
229- if ( this . _signal ?. aborted ) {
248+ if ( this . _closed || this . _signal ?. aborted ) {
230249 return ;
231250 }
232251 await this . _events . push ( event ) ;
233252 }
234253
235254 async throw ( error : Error ) {
236- if ( this . _signal ?. aborted ) {
255+ if ( this . _closed || this . _signal ?. aborted ) {
237256 return ;
238257 }
239258 await this . _events . throw ( error ) ;
240259 }
241260
242261 close ( ) {
262+ this . _closed = true ;
243263 this . _events . close ( ) ;
244264 }
245265}
0 commit comments