@@ -318,6 +318,109 @@ describe("waitForBuildEndTime", () => {
318318 } ) ;
319319 expect ( test ) . to . equal ( buildReplies . pop ( ) . builds [ 0 ] ) ;
320320 } ) ;
321+
322+ it ( "waits after being rate limited and tries again" , async function ( ) {
323+ const buildID = "buildID" ;
324+ const nullArn =
325+ "arn:aws:logs:us-west-2:111122223333:log-group:null:log-stream:null" ;
326+ const cloudWatchLogsArn =
327+ "arn:aws:logs:us-west-2:111122223333:log-group:/aws/codebuild/CloudWatchLogGroup:log-stream:1234abcd-12ab-34cd-56ef-1234567890ab" ;
328+
329+ const buildReplies = [
330+ ( ) => {
331+ throw { message : "Rate exceeded" } ;
332+ } ,
333+ { builds : [ { id : buildID , logs : { cloudWatchLogsArn } } ] } ,
334+ {
335+ builds : [
336+ { id : buildID , logs : { cloudWatchLogsArn } , endTime : "endTime" }
337+ ]
338+ }
339+ ] ;
340+
341+ const sdk = help (
342+ ( ) => {
343+ //similar to the ret function in the helper, allows me to throw an error in a function or return a more standard reply
344+ let reply = buildReplies . shift ( ) ;
345+
346+ if ( typeof reply === "function" ) return reply ( ) ;
347+ return reply ;
348+ } ,
349+ ( ) => {
350+ if ( ! buildReplies . length ) {
351+ return { events : [ ] } ;
352+ }
353+
354+ return { events : [ { message : "got one" } ] } ;
355+ }
356+ ) ;
357+
358+ const test = await waitForBuildEndTime (
359+ { ...sdk , wait : 1 , backOff : 1 } ,
360+ {
361+ id : buildID ,
362+ logs : { cloudWatchLogsArn : nullArn }
363+ }
364+ ) ;
365+
366+ expect ( test . id ) . to . equal ( buildID ) ;
367+ } ) ;
368+
369+ it ( "dies after getting an error from the aws sdk that isn't rate limiting" , async function ( ) {
370+ const buildID = "buildID" ;
371+ const nullArn =
372+ "arn:aws:logs:us-west-2:111122223333:log-group:null:log-stream:null" ;
373+ const cloudWatchLogsArn =
374+ "arn:aws:logs:us-west-2:111122223333:log-group:/aws/codebuild/CloudWatchLogGroup:log-stream:1234abcd-12ab-34cd-56ef-1234567890ab" ;
375+
376+ const buildReplies = [
377+ ( ) => {
378+ throw { message : "Some AWS error" } ;
379+ } ,
380+ { builds : [ { id : buildID , logs : { cloudWatchLogsArn } } ] } ,
381+ {
382+ builds : [
383+ { id : buildID , logs : { cloudWatchLogsArn } , endTime : "endTime" }
384+ ]
385+ }
386+ ] ;
387+
388+ const sdk = help (
389+ ( ) => {
390+ //similar to the ret function in the helper
391+ //allows me to throw an error in a function or return a more standard reply
392+ let reply = buildReplies . shift ( ) ;
393+
394+ if ( typeof reply === "function" ) return reply ( ) ;
395+ return reply ;
396+ } ,
397+ ( ) => {
398+ if ( ! buildReplies . length ) {
399+ return { events : [ ] } ;
400+ }
401+
402+ return { events : [ { message : "got one" } ] } ;
403+ }
404+ ) ;
405+
406+ //run the thing and it should fail
407+ let didFail = false ;
408+
409+ try {
410+ await waitForBuildEndTime (
411+ { ...sdk , wait : 1 , backOff : 1 } ,
412+ {
413+ id : buildID ,
414+ logs : { cloudWatchLogsArn : nullArn }
415+ }
416+ ) ;
417+ } catch ( err ) {
418+ didFail = true ;
419+ expect ( err . message ) . to . equal ( "Some AWS error" ) ;
420+ }
421+
422+ expect ( didFail ) . to . equal ( true ) ;
423+ } ) ;
321424} ) ;
322425
323426function help ( builds , logs ) {
0 commit comments