#NEWLINE# @ access . token #NEWLINE# @ describeRoute ( Description ( 'Test progress contexts from the web' ) . param ( 'test' , 'Name of test to run.  These include "success" and "failure".' , required = False ) . param ( 'duration' , 'Duration of the test in seconds' , required = False , dataType = 'int' ) ) #NEWLINE# def testProgress( self , params ) : #NEWLINE# #INDENT# test = params . get ( 'test' , 'success' ) #NEWLINE# duration = int ( params . get ( 'duration' , 10 ) ) #NEWLINE# startTime = time . time ( ) #NEWLINE# with ProgressContext ( True , user = self . getCurrentUser ( ) , title = 'Progress Test' , message = 'Progress Message' , total = duration ) as ctx : #NEWLINE# #INDENT# for current in range ( duration ) : #NEWLINE# #INDENT# if self . stop : #NEWLINE# #INDENT# break #NEWLINE# #UNINDENT# ctx . update ( current = current ) #NEWLINE# wait = ( ( ( startTime + current ) + 1 ) - time . time ( ) ) #NEWLINE# if ( wait > 0 ) : #NEWLINE# #INDENT# time . sleep ( wait ) #NEWLINE# #UNINDENT# #UNINDENT# if ( test == 'error' ) : #NEWLINE# #INDENT# raise RestException ( 'Progress error test.' )