@@ -183,6 +183,46 @@ for (const reason of [null, undefined, error1]) {
183183} , `(reason: '${ reason } ') all pending writes should complete on abort` ) ;
184184}
185185
186+ for ( const reason of [ null , undefined , error1 ] ) {
187+ promise_test ( async t => {
188+ let rejectPull ;
189+ const pullPromise = new Promise ( ( _ , reject ) => {
190+ rejectPull = reject ;
191+ } ) ;
192+ let rejectCancel ;
193+ const cancelPromise = new Promise ( ( _ , reject ) => {
194+ rejectCancel = reject ;
195+ } ) ;
196+ const rs = recordingReadableStream ( {
197+ async pull ( ) {
198+ await Promise . race ( [
199+ pullPromise ,
200+ cancelPromise ,
201+ ] ) ;
202+ } ,
203+ cancel ( reason ) {
204+ rejectCancel ( reason ) ;
205+ } ,
206+ } ) ;
207+ const ws = new WritableStream ( ) ;
208+ const abortController = new AbortController ( ) ;
209+ const signal = abortController . signal ;
210+ const pipeToPromise = rs . pipeTo ( ws , { signal } ) ;
211+ pipeToPromise . catch ( ( ) => { } ) ; // Prevent unhandled rejection.
212+ await delay ( 0 ) ;
213+ abortController . abort ( reason ) ;
214+ rejectPull ( 'should not catch pull rejection' ) ;
215+ await delay ( 0 ) ;
216+ assert_equals ( rs . eventsWithoutPulls . length , 2 , 'cancel should have been called' ) ;
217+ assert_equals ( rs . eventsWithoutPulls [ 0 ] , 'cancel' , 'first event should be cancel' ) ;
218+ if ( reason !== undefined ) {
219+ await promise_rejects_exactly ( t , reason , pipeToPromise , 'pipeTo rejects with abort reason' ) ;
220+ } else {
221+ await promise_rejects_dom ( t , 'AbortError' , pipeToPromise , 'pipeTo rejects with AbortError' ) ;
222+ }
223+ } , `(reason: '${ reason } ') underlyingSource.cancel() should called when abort, even with pending pull` ) ;
224+ }
225+
186226promise_test ( t => {
187227const rs = new ReadableStream ( {
188228pull ( controller ) {
0 commit comments