Hi Johan, Could it be that your jobFinised() method returns true since job == null, which could be the case shortly before/while the job is even being created? Ie it could be a race condition at the start of the job (and by adding a 5sec sleep you give it enough time to start + finish).
Cheers, Stefan On 19.12.17, 17:34, "Johan Ruttens" <[email protected]> wrote: >Hi, > >I'm working on a (Adobe AEM) integration test, where the test methods >depend on a job being finished, before the methods can be executed with >success. > >The scenario of the job is a follows: >1. Copy a page to be used as a test resource (using the PageManager.copy >method) >2. Trigger a job (using the JobManager.add method) >3. The job will alter some properties on the AEM page >4. Wait until the job has finished >5. Execute the tests to check if the properties have been changed >correctly. > > >The problem is that the integration tests sometimes succeed and sometimes >they do not succeed (i.e. properties are not changed correctly). >I suspect this is caused by the way we check if the job is finished: > > >@Test > public void testIfPageIsCorrectTranslated() throws LoginException, >RepositoryException, InterruptedException, WCMException { > boolean finished = false; > while (!finished) { > Job runningJob = jobManager.getJobById(job.getId()); > finished = jobFinised(runningJob); > } >............ > >} > >..... > >private boolean jobFinised(final Job job) { > return job == null || job.getJobState().equals(Job.JobState.SUCCEEDED) > || job.getJobState().equals(Job.JobState.ERROR) || >job.getJobState().equals(Job.JobState.STOPPED); >} > > >When I add a Thread.sleep(5000) after the while loop, all the tests >succeed >all of the time. > > >Thanks for the help.
