Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 16 additions & 18 deletions force-app/main/default/classes/AsyncTest.cls
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,12 @@
* PMD False Positives:
* - ApexAssertionsShouldIncludeMessage: IMO not all assertions need a message
* - EmptyStatementBlock: It is test class, some methods are just to create jobs placeholders
* - NcssTypeCount: It is a library and all of its tests live in ONE test class
* - NcssCount: It is a library and all of its tests live in ONE test class
**/
@SuppressWarnings('PMD.ApexAssertionsShouldIncludeMessage,PMD.EmptyStatementBlock')
@SuppressWarnings(
'PMD.ApexAssertionsShouldIncludeMessage,PMD.EmptyStatementBlock,PMD.NcssTypeCount,PMD.NcssCount'
)
@IsTest
@TestVisible
private class AsyncTest implements Database.Batchable<SObject> {
Expand Down Expand Up @@ -3178,14 +3182,8 @@ private class AsyncTest implements Database.Batchable<SObject> {

@IsTest
private static void shouldDeleteOnlyOldNonFailedResultsWhenOnlyOthersRetentionIsSet() {
AsyncResult__c oldCompleted = insertAsyncResultWithAge(
QueueableManager.STATUS_COMPLETED,
31
);
AsyncResult__c oldSkipped = insertAsyncResultWithAge(
QueueableManager.STATUS_SKIPPED_DEPENDENCY,
31
);
insertAsyncResultWithAge(QueueableManager.STATUS_COMPLETED, 31);
insertAsyncResultWithAge(QueueableManager.STATUS_SKIPPED_DEPENDENCY, 31);
AsyncResult__c veryOldFailed = insertAsyncResultWithAge(
QueueableManager.STATUS_FAILED,
400
Expand Down Expand Up @@ -3214,18 +3212,12 @@ private class AsyncTest implements Database.Batchable<SObject> {

@IsTest
private static void shouldApplySeparateRetentionCutoffsPerTrack() {
AsyncResult__c failedPastCutoff = insertAsyncResultWithAge(
QueueableManager.STATUS_FAILED,
100
);
insertAsyncResultWithAge(QueueableManager.STATUS_FAILED, 100);
AsyncResult__c failedWithinCutoff = insertAsyncResultWithAge(
QueueableManager.STATUS_FAILED,
60
);
AsyncResult__c completedPastCutoff = insertAsyncResultWithAge(
QueueableManager.STATUS_COMPLETED,
60
);
insertAsyncResultWithAge(QueueableManager.STATUS_COMPLETED, 60);
AsyncResult__c completedWithinCutoff = insertAsyncResultWithAge(
QueueableManager.STATUS_COMPLETED,
10
Expand Down Expand Up @@ -4060,7 +4052,7 @@ private class AsyncTest implements Database.Batchable<SObject> {
@IsTest
private static void shouldInjectQueueableMockIntoAChunkPage() {
List<Account> accounts = createAccounts(2);
Id mockJobId = '707000000000001AAA';
Id mockJobId = fakeId(AsyncApexJob.SObjectType, 1);
AsyncMock.whenQueueable('chunk-page')
.thenReturn(new AsyncMock.MockQueueableContext().setJobId(mockJobId));

Expand Down Expand Up @@ -4669,6 +4661,12 @@ private class AsyncTest implements Database.Batchable<SObject> {
return accounts;
}

private static Id fakeId(Schema.SObjectType sObjectType, Integer index) {
String prefix = sObjectType.getDescribe(SObjectDescribeOptions.DEFERRED).getKeyPrefix();
String suffix = String.valueOf(index);
return Id.valueOf(prefix + '0'.repeat(15 - prefix.length() - suffix.length()) + suffix);
}

private static List<Account> accountsWithOneFailingRecord() {
List<Account> accounts = new List<Account>{
new Account(Name = 'ok first'),
Expand Down
3 changes: 2 additions & 1 deletion force-app/main/default/classes/queue/QueueableJob.cls
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,8 @@ public abstract class QueueableJob implements Queueable, Comparable {
private String getFullClassName(Object job) {
String result;
try {
DateTime typeCheck = (DateTime) job;
// A failed cast is the only way to read the runtime type with its namespace
String.valueOf((DateTime) job);
} catch (System.TypeException expectedTypeException) {
String message = expectedTypeException.getMessage()
.substringAfter('Invalid conversion from runtime type ');
Expand Down
Loading