File tree Expand file tree Collapse file tree 2 files changed +29
-7
lines changed
packages/polly-request-presigner/src Expand file tree Collapse file tree 2 files changed +29
-7
lines changed Original file line number Diff line number Diff line change @@ -93,4 +93,17 @@ describe("getSignedUrl", () => {
93
93
expect ( mockPresign ) . toBeCalled ( ) ;
94
94
expect ( mockPresign . mock . calls [ 0 ] [ 1 ] ) . toMatchObject ( options ) ;
95
95
} ) ;
96
- } ) ;
96
+
97
+ it ( "should not throw if it's called concurrently" , async ( ) => {
98
+ const mockPresigned = "a presigned url" ;
99
+ mockPresign . mockReturnValue ( mockPresigned ) ;
100
+ const client = new PollyClient ( clientParams ) ;
101
+ const command = new SynthesizeSpeechCommand ( {
102
+ Text : "hello world, this is alex" ,
103
+ OutputFormat : "mp3" ,
104
+ VoiceId : "Kimberly" ,
105
+ } ) ;
106
+ const commands = [ command , command ] ;
107
+ return expect ( Promise . all ( commands . map ( ( command ) => getSignedUrl ( client , command ) ) ) ) . resolves . toBeInstanceOf ( Array ) ;
108
+ } ) ;
109
+ } ) ;
Original file line number Diff line number Diff line change @@ -51,19 +51,28 @@ export const getSignedUrl = async (
51
51
} as any ;
52
52
} ;
53
53
54
- client . middlewareStack . addRelativeTo ( presignInterceptMiddleware , {
55
- name : "presignInterceptMiddleware" ,
56
- relation : "before" ,
57
- toMiddleware : "awsAuthMiddleware" ,
58
- } ) ;
54
+ const middlewareName = "presignInterceptMiddleware" ;
55
+ try {
56
+ client . middlewareStack . addRelativeTo ( presignInterceptMiddleware , {
57
+ name : middlewareName ,
58
+ relation : "before" ,
59
+ toMiddleware : "awsAuthMiddleware" ,
60
+ } ) ;
61
+ } catch ( e ) {
62
+ if ( e . message ! . includes ( `Duplicated middleware name '${ middlewareName } '` ) ) {
63
+ // Swallow if the interceptor is already added. See https://github.com/aws/aws-sdk-js-v3/issues/2417
64
+ } else {
65
+ throw e ;
66
+ }
67
+ }
59
68
60
69
let presigned : HttpRequest ;
61
70
try {
62
71
const output = await client . send ( command ) ;
63
72
//@ts -ignore the output is faked, so it's not actually OutputType
64
73
presigned = output . presigned ;
65
74
} finally {
66
- client . middlewareStack . remove ( "presignInterceptMiddleware" ) ;
75
+ client . middlewareStack . remove ( middlewareName ) ;
67
76
}
68
77
69
78
return formatUrl ( presigned ) ;
You can’t perform that action at this time.
0 commit comments