Skip to content

Instantly share code, notes, and snippets.

@mickle00
Created September 23, 2014 20:24
Show Gist options
  • Save mickle00/70179703e885292793a0 to your computer and use it in GitHub Desktop.
Save mickle00/70179703e885292793a0 to your computer and use it in GitHub Desktop.
Showing that the Apex Flex Queue does not appear to work in the context of Unit Tests.
global class FlexQueueExample implements Database.Batchable<sObject>{
global Iterable<sObject> start(Database.BatchableContext BC) {
return new List<sObject> {};
}
global void execute(Database.BatchableContext BC, List<sObject> scope){}
global void finish(Database.BatchableContext BC){}
// Works in Execute Anonymous for Count <= 100
global static void run(Integer count){
for (integer i=0; i<count; i++){
database.executeBatch(new FlexQueueExample());
}
}
}
@isTest (seeAllData = false)
private class FlexQueueExampleTest {
//System.LimitException: Attempted to schedule too many concurrent batch jobs in this org (limit is 5).
private static testMethod void shouldBeAbleToUseFlexQueueInTests(){
FlexQueueExample.run(10);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment