public static void waitUntilNoActivityUpTo ( Jenkins jenkins , int timeout ) throws Exception { long startTime = System . currentTimeMillis ( ) ; int streak = 0 ; while ( true ) { Thread . sleep ( 10 ) ; if ( isSomethingHappening ( jenkins ) ) { streak = 0 ; } else { streak ++ ; } if ( streak > 5 ) { // the system is quiet for a while return ; } if ( System . currentTimeMillis ( ) - startTime > timeout ) { List < Queue . Executable > building = new ArrayList < Queue . Executable > ( ) ; for ( Computer c : jenkins . getComputers ( ) ) { for ( Executor e : c . getExecutors ( ) ) { if ( e . isBusy ( ) ) building . add ( e . getCurrentExecutable ( ) ) ; } for ( Executor e : c . getOneOffExecutors ( ) ) { if ( e . isBusy ( ) ) building . add ( e . getCurrentExecutable ( ) ) ; } } dumpThreads ( ) ; throw new AssertionError ( String . format ( "Jenkins is still doing something after %dms: queue=%s building=%s" , timeout , Arrays . asList ( jenkins . getQueue ( ) . getItems ( ) ) , building ) ) ; } } }
Waits until Hudson finishes building everything including those in the queue or fail the test if the specified timeout milliseconds is