#NEWLINE# @ when ( 'there are {num} {which} {state} tasks' ) #NEWLINE# def when_there_are_num_which_tasks( context , num , which , state ) : #NEWLINE# #INDENT# context . max_tasks = int ( num ) #NEWLINE# app_id = which_id ( context , which ) #NEWLINE# for _ in xrange ( 120 ) : #NEWLINE# #INDENT# app = context . marathon_client . get_app ( app_id , embed_tasks = True ) #NEWLINE# happy_count = len ( get_happy_tasks ( app , context . service , 'fake_nerve_ns' , context . system_paasta_config ) ) #NEWLINE# if ( state == 'healthy' ) : #NEWLINE# #INDENT# if ( happy_count >= context . max_tasks ) : #NEWLINE# #INDENT# return #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# if ( state == 'unhealthy' ) : #NEWLINE# #INDENT# if ( ( len ( app . tasks ) - happy_count ) >= context . max_tasks ) : #NEWLINE# #INDENT# return #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# time . sleep ( 0.5 ) #NEWLINE# #UNINDENT# raise Exception ( ( 'timed out waiting for %d %s tasks on %s; there are %d' % ( context . max_tasks , state , app_id , app . tasks ) ) )