I had an issue in my batch class, it was picking the same data to process when it is already run for the same earlier.
If the data is processed once, that batch should not pick that data again in the query in the start() method. Fixed this with a flag in the table and filtering out in start() method on the basis of this flag.
I am trying to check if the fix is working using the unit test class with test case having a call like this.
Database.executeBatch(new MyBatch());
Database.executeBatch(new MyBatch());
But the both instances start simantaneously and picking the data in the start method. I need to run them sequentially. I have tried adding loop in these two statements which have time delay with something like this:
Database.executeBatch(new MyBatch());
Integer start = System.Now().millisecond();
while(System.Now().millisecond()< start+10){
}
Database.executeBatch(new MyBatch());
But both calls were happening after the completion of the loop. How to run them one after completion of another?