Skip to content

Commit

Permalink
fix: use autoFetchQuery for >2k test result records (#190)
Browse files Browse the repository at this point in the history
@W-9250725@
  • Loading branch information
AnanyaJha committed May 24, 2021
1 parent 15cb9fd commit 76037e5
Show file tree
Hide file tree
Showing 7 changed files with 103 additions and 56 deletions.
2 changes: 1 addition & 1 deletion packages/apex-node/src/streaming/streamingClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ export class StreamingClient {
testRunId: string
): Promise<ApexTestQueueItem> {
const queryApexTestQueueItem = `SELECT Id, Status, ApexClassId, TestRunResultId FROM ApexTestQueueItem WHERE ParentJobId = '${testRunId}'`;
const result = (await this.conn.tooling.query(
const result = (await this.conn.tooling.autoFetchQuery(
queryApexTestQueueItem
)) as ApexTestQueueItem;

Expand Down
8 changes: 5 additions & 3 deletions packages/apex-node/src/tests/asyncTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ export class AsyncTests {
message: nls.localize('retrievingTestRunSummary')
});

const testRunSummaryResults = (await this.connection.tooling.query(
const testRunSummaryResults = (await this.connection.tooling.autoFetchQuery(
testRunSummaryQuery
)) as ApexTestRunResult;

Expand Down Expand Up @@ -261,7 +261,9 @@ export class AsyncTests {
}

const queryPromises = queries.map(query => {
return this.connection.tooling.query(query) as Promise<ApexTestResult>;
return this.connection.tooling.autoFetchQuery(query) as Promise<
ApexTestResult
>;
});
const apexTestResults = await Promise.all(queryPromises);
return apexTestResults;
Expand Down Expand Up @@ -354,7 +356,7 @@ export class AsyncTests {
testRunId
});

const testQueueItems = await this.connection.tooling.query<
const testQueueItems = await this.connection.tooling.autoFetchQuery<
ApexTestQueueItemRecord
>(
`SELECT Id, Status FROM ApexTestQueueItem WHERE ParentJobId = '${testRunId}'`
Expand Down
4 changes: 2 additions & 2 deletions packages/apex-node/src/tests/codeCoverage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ export class CodeCoverage {

const perClassCodeCovQuery =
'SELECT ApexTestClassId, ApexClassOrTrigger.Id, ApexClassOrTrigger.Name, TestMethodName, NumLinesCovered, NumLinesUncovered, Coverage FROM ApexCodeCoverage WHERE ApexTestClassId IN (%s)';
const perClassCodeCovResuls = (await this.connection.tooling.query(
const perClassCodeCovResuls = (await this.connection.tooling.autoFetchQuery(
util.format(perClassCodeCovQuery, `${str}`)
)) as ApexCodeCoverage;
return perClassCodeCovResuls;
Expand Down Expand Up @@ -164,7 +164,7 @@ export class CodeCoverage {

const codeCoverageQuery =
'SELECT ApexClassOrTrigger.Id, ApexClassOrTrigger.Name, NumLinesCovered, NumLinesUncovered, Coverage FROM ApexCodeCoverageAggregate WHERE ApexClassorTriggerId IN (%s)';
const codeCoverageResuls = (await this.connection.tooling.query(
const codeCoverageResuls = (await this.connection.tooling.autoFetchQuery(
util.format(codeCoverageQuery, `${str}`)
)) as ApexCodeCoverageAggregate;
return codeCoverageResuls;
Expand Down
30 changes: 24 additions & 6 deletions packages/apex-node/test/streaming/streamingClient.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,10 @@ describe('Streaming API Client', () => {
});

it('should throw error if handler can not find test records', async () => {
const mockToolingQuery = sandboxStub.stub(mockConnection.tooling, 'query');
const mockToolingQuery = sandboxStub.stub(
mockConnection.tooling,
'autoFetchQuery'
);
mockToolingQuery.resolves({
done: true,
totalSize: 0,
Expand All @@ -180,7 +183,10 @@ describe('Streaming API Client', () => {
});

it('should not run a query if the subscribed test run id does not match the message test run id', async () => {
const mockToolingQuery = sandboxStub.stub(mockConnection.tooling, 'query');
const mockToolingQuery = sandboxStub.stub(
mockConnection.tooling,
'autoFetchQuery'
);
const streamClient = new StreamingClient(mockConnection);
streamClient.subscribedTestRunId = '707xx0000gtQ3jx3x5';
const streamHandlerResult = await streamClient.handler(testResultMsg);
Expand All @@ -201,7 +207,10 @@ describe('Streaming API Client', () => {
}
]
};
const mockToolingQuery = sandboxStub.stub(mockConnection.tooling, 'query');
const mockToolingQuery = sandboxStub.stub(
mockConnection.tooling,
'autoFetchQuery'
);
mockToolingQuery.resolves(queryResponse);
const streamClient = new StreamingClient(mockConnection);
streamClient.subscribedTestRunId = '707xx0000AGQ3jbQQD';
Expand Down Expand Up @@ -230,7 +239,10 @@ describe('Streaming API Client', () => {
]
};

const mockToolingQuery = sandboxStub.stub(mockConnection.tooling, 'query');
const mockToolingQuery = sandboxStub.stub(
mockConnection.tooling,
'autoFetchQuery'
);
mockToolingQuery.resolves(queryResponse);
const streamClient = new StreamingClient(mockConnection);
streamClient.subscribedTestRunId = '707xx0000AGQ3jbQQD';
Expand Down Expand Up @@ -280,7 +292,10 @@ describe('Streaming API Client', () => {
});

it('should report streamingProcessingTestRun progress', async () => {
const mockToolingQuery = sandboxStub.stub(mockConnection.tooling, 'query');
const mockToolingQuery = sandboxStub.stub(
mockConnection.tooling,
'autoFetchQuery'
);
mockToolingQuery.resolves({
done: true,
totalSize: 0,
Expand Down Expand Up @@ -310,7 +325,10 @@ describe('Streaming API Client', () => {
});

it('should report test queue progress', async () => {
const mockToolingQuery = sandboxStub.stub(mockConnection.tooling, 'query');
const mockToolingQuery = sandboxStub.stub(
mockConnection.tooling,
'autoFetchQuery'
);
mockToolingQuery.resolves({
done: true,
totalSize: 0,
Expand Down
76 changes: 48 additions & 28 deletions packages/apex-node/test/tests/asyncTests.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,10 @@ describe('Run Apex tests asynchronously', () => {
missingTimeTestData.summary.orgId = mockConnection.getAuthInfoFields().orgId;
missingTimeTestData.summary.username = mockConnection.getUsername();
const asyncTestSrv = new AsyncTests(mockConnection);
const mockToolingQuery = sandboxStub.stub(mockConnection.tooling, 'query');
const mockToolingQuery = sandboxStub.stub(
mockConnection.tooling,
'autoFetchQuery'
);
mockToolingQuery.onFirstCall().resolves({
done: true,
totalSize: 1,
Expand Down Expand Up @@ -235,7 +238,10 @@ describe('Run Apex tests asynchronously', () => {

it('should report progress for formatting async results', async () => {
const asyncTestSrv = new AsyncTests(mockConnection);
const mockToolingQuery = sandboxStub.stub(mockConnection.tooling, 'query');
const mockToolingQuery = sandboxStub.stub(
mockConnection.tooling,
'autoFetchQuery'
);
mockToolingQuery.onFirstCall().resolves({
done: true,
totalSize: 1,
Expand Down Expand Up @@ -298,7 +304,10 @@ describe('Run Apex tests asynchronously', () => {
skippedTestData.summary.orgId = mockConnection.getAuthInfoFields().orgId;
skippedTestData.summary.username = mockConnection.getUsername();
const asyncTestSrv = new AsyncTests(mockConnection);
const mockToolingQuery = sandboxStub.stub(mockConnection.tooling, 'query');
const mockToolingQuery = sandboxStub.stub(
mockConnection.tooling,
'autoFetchQuery'
);
mockToolingQuery.onFirstCall().resolves({
done: true,
totalSize: 1,
Expand Down Expand Up @@ -364,7 +373,10 @@ describe('Run Apex tests asynchronously', () => {
diagnosticResult.summary.orgId = mockConnection.getAuthInfoFields().orgId;
diagnosticResult.summary.username = mockConnection.getUsername();
const asyncTestSrv = new AsyncTests(mockConnection);
const mockToolingQuery = sandboxStub.stub(mockConnection.tooling, 'query');
const mockToolingQuery = sandboxStub.stub(
mockConnection.tooling,
'autoFetchQuery'
);
mockToolingQuery.onFirstCall().resolves({
done: true,
totalSize: 1,
Expand Down Expand Up @@ -420,7 +432,10 @@ describe('Run Apex tests asynchronously', () => {
diagnosticFailure.tests[0].diagnostic.exceptionStackTrace = undefined;
diagnosticFailure.tests[0].stackTrace = undefined;
const asyncTestSrv = new AsyncTests(mockConnection);
const mockToolingQuery = sandboxStub.stub(mockConnection.tooling, 'query');
const mockToolingQuery = sandboxStub.stub(
mockConnection.tooling,
'autoFetchQuery'
);
mockToolingQuery.onFirstCall().resolves({
done: true,
totalSize: 1,
Expand Down Expand Up @@ -471,7 +486,10 @@ describe('Run Apex tests asynchronously', () => {

it('should return an error if no test results are found', async () => {
const asyncTestSrv = new AsyncTests(mockConnection);
const mockToolingQuery = sandboxStub.stub(mockConnection.tooling, 'query');
const mockToolingQuery = sandboxStub.stub(
mockConnection.tooling,
'autoFetchQuery'
);
mockToolingQuery.onFirstCall().resolves({
done: true,
totalSize: 0,
Expand Down Expand Up @@ -542,8 +560,20 @@ describe('Run Apex tests asynchronously', () => {

it('should return formatted test results with code coverage', async () => {
const asyncTestSrv = new AsyncTests(mockConnection);
const mockToolingQuery = sandboxStub.stub(mockConnection.tooling, 'query');
mockToolingQuery.onCall(0).resolves({
const mockToolingAutoQuery = sandboxStub.stub(
mockConnection.tooling,
'autoFetchQuery'
);
sandboxStub.stub(mockConnection.tooling, 'query').resolves({
done: true,
totalSize: 1,
records: [
{
PercentCovered: '57'
}
]
} as ApexOrgWideCoverage);
mockToolingAutoQuery.onCall(0).resolves({
done: true,
totalSize: 1,
records: [
Expand All @@ -557,34 +587,24 @@ describe('Run Apex tests asynchronously', () => {
]
} as ApexTestRunResult);

mockToolingQuery.onCall(1).resolves({
mockToolingAutoQuery.onCall(1).resolves({
done: true,
totalSize: 6,
records: mixedTestResults
} as ApexTestResult);

mockToolingQuery.onCall(2).resolves({
mockToolingAutoQuery.onCall(2).resolves({
done: true,
totalSize: 3,
records: mixedPerClassCodeCoverage
} as ApexCodeCoverage);

mockToolingQuery.onCall(3).resolves({
mockToolingAutoQuery.onCall(3).resolves({
done: true,
totalSize: 3,
records: codeCoverageQueryResult
} as ApexCodeCoverageAggregate);

mockToolingQuery.onCall(4).resolves({
done: true,
totalSize: 1,
records: [
{
PercentCovered: '57'
}
]
} as ApexOrgWideCoverage);

const getTestResultData = await asyncTestSrv.formatAsyncResults(
pollResponse,
testRunId,
Expand Down Expand Up @@ -615,7 +635,7 @@ describe('Run Apex tests asynchronously', () => {
const asyncTestSrv = new AsyncTests(mockConnection);
const mockToolingQuery = sandboxStub.stub(
mockConnection.tooling,
'query'
'autoFetchQuery'
);
mockToolingQuery.onCall(0).resolves({
done: true,
Expand Down Expand Up @@ -714,7 +734,7 @@ describe('Run Apex tests asynchronously', () => {
it('should split into multiple queries if query is longer than char limit', async () => {
const mockToolingQuery = sandboxStub.stub(
mockConnection.tooling,
'query'
'autoFetchQuery'
);
mockToolingQuery.onFirstCall().resolves({
done: true,
Expand Down Expand Up @@ -775,7 +795,7 @@ describe('Run Apex tests asynchronously', () => {
it('should make a single api call if query is under char limit', async () => {
const mockToolingQuery = sandboxStub.stub(
mockConnection.tooling,
'query'
'autoFetchQuery'
);
mockToolingQuery.onFirstCall().resolves({
done: true,
Expand Down Expand Up @@ -823,7 +843,7 @@ describe('Run Apex tests asynchronously', () => {

const mockToolingQuery = sandboxStub.stub(
mockConnection.tooling,
'query'
'autoFetchQuery'
);
mockToolingQuery.onFirstCall().resolves({
done: true,
Expand Down Expand Up @@ -902,7 +922,7 @@ describe('Run Apex tests asynchronously', () => {

const mockToolingQuery = sandboxStub.stub(
mockConnection.tooling,
'query'
'autoFetchQuery'
);
mockToolingQuery.onFirstCall().resolves({
done: true,
Expand Down Expand Up @@ -965,7 +985,7 @@ describe('Run Apex tests asynchronously', () => {
it('should format single query correctly', async () => {
const mockToolingQuery = sandboxStub.stub(
mockConnection.tooling,
'query'
'autoFetchQuery'
);
const id = '7092M000000Vt94QAC';
mockToolingQuery.onFirstCall().resolves({
Expand Down Expand Up @@ -1175,7 +1195,7 @@ describe('Run Apex tests asynchronously', () => {
]
} as unknown) as ApexTestQueueItem;
sandboxStub
.stub(mockConnection.tooling, 'query')
.stub(mockConnection.tooling, 'autoFetchQuery')
//@ts-ignore
.resolves<ApexTestQueueItemRecord>(mockTestQueueItemRecord);
const toolingUpdateStub = sandboxStub.stub(
Expand Down
11 changes: 8 additions & 3 deletions packages/apex-node/test/tests/codeCoverage.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const $$ = testSetup();
let mockConnection: Connection;
let sandboxStub: SinonSandbox;
let toolingQueryStub: SinonStub;
let toolingAutoQueryStub: SinonStub;
const testData = new MockTestOrgData();

describe('Get code coverage results', () => {
Expand All @@ -38,6 +39,10 @@ describe('Get code coverage results', () => {
})
});
toolingQueryStub = sandboxStub.stub(mockConnection.tooling, 'query');
toolingAutoQueryStub = sandboxStub.stub(
mockConnection.tooling,
'autoFetchQuery'
);
});

afterEach(() => {
Expand Down Expand Up @@ -132,7 +137,7 @@ describe('Get code coverage results', () => {
uncoveredLines: [8, 9, 10]
}
];
toolingQueryStub.resolves({
toolingAutoQueryStub.resolves({
done: true,
totalSize: 3,
records: codeCoverageQueryResult
Expand Down Expand Up @@ -195,7 +200,7 @@ describe('Get code coverage results', () => {
}
}
];
toolingQueryStub.resolves({
toolingAutoQueryStub.resolves({
done: true,
totalSize: 3,
records: perClassCodeCovResult
Expand Down Expand Up @@ -269,7 +274,7 @@ describe('Get code coverage results', () => {
Coverage: { coveredLines: [1, 2, 3, 4, 5, 6], uncoveredLines: [7, 8] }
}
];
toolingQueryStub.resolves({
toolingAutoQueryStub.resolves({
done: true,
totalSize: 2,
records: perClassCodeCovResult
Expand Down
Loading

0 comments on commit 76037e5

Please sign in to comment.