File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -160,9 +160,18 @@ function requestAsEventEmitter(opts) {
160160 } ) ;
161161
162162 cacheReq . once ( 'request' , req => {
163+ let aborted = false ;
164+ req . once ( 'abort' , _ => {
165+ aborted = true ;
166+ } ) ;
167+
163168 req . once ( 'error' , err => {
164169 clearInterval ( progressInterval ) ;
165170
171+ if ( aborted ) {
172+ return ;
173+ }
174+
166175 const backoff = opts . retries ( ++ retryCount , err ) ;
167176
168177 if ( backoff ) {
Original file line number Diff line number Diff line change @@ -21,14 +21,43 @@ async function createAbortServer() {
2121 res . end ( ) ;
2222 } ) ;
2323 } ) ;
24+
25+ s . on ( '/redirect' , ( req , res ) => {
26+ res . writeHead ( 302 , {
27+ location : `${ s . url } /abort`
28+ } ) ;
29+ res . end ( ) ;
30+
31+ ee . emit ( 'sentRedirect' ) ;
32+
33+ setTimeout ( resolve , 3000 ) ;
34+ } ) ;
2435 } ) ;
2536
2637 await s . listen ( s . port ) ;
2738 ee . url = `${ s . url } /abort` ;
39+ ee . redirectUrl = `${ s . url } /redirect` ;
2840
2941 return ee ;
3042}
3143
44+ test ( 'cancel do not retry after cancelation' , async t => {
45+ const helper = await createAbortServer ( ) ;
46+
47+ const p = got ( helper . redirectUrl , {
48+ retries : _ => {
49+ t . fail ( 'Makes a new try after cancelation' ) ;
50+ }
51+ } ) ;
52+
53+ helper . on ( 'sentRedirect' , ( ) => {
54+ p . cancel ( ) ;
55+ } ) ;
56+
57+ await t . throws ( p , PCancelable . CancelError ) ;
58+ await t . notThrows ( helper . aborted , 'Request finished instead of aborting.' ) ;
59+ } ) ;
60+
3261test ( 'cancel in-progress request' , async t => {
3362 const helper = await createAbortServer ( ) ;
3463 const body = new Readable ( {
You can’t perform that action at this time.
0 commit comments