Skip to content

Commit

Permalink
test: update ut for log => warning changes
Browse files Browse the repository at this point in the history
  • Loading branch information
mshanemc committed Nov 21, 2023
1 parent 930aec6 commit c6e2fae
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 13 deletions.
5 changes: 2 additions & 3 deletions src/shared/remoteSourceTrackingService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -329,11 +329,10 @@ export class RemoteSourceTrackingService {
lc.emitWarning(
`Polling for ${
outstandingSourceMembers.size
} timed out after ${pollAttempts} attempts (last ${consecutiveEmptyResults} were empty).
} SourceMembers timed out after ${pollAttempts} attempts (last ${consecutiveEmptyResults} were empty).
Missing SourceMembers:
${formatSourceMemberWarnings(outstandingSourceMembers)}
`
${formatSourceMemberWarnings(outstandingSourceMembers)}`
),
lc.emitTelemetry({
eventName: 'sourceMemberPollingTimeout',
Expand Down
28 changes: 18 additions & 10 deletions test/unit/remoteSourceTracking.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { writeFile, mkdir, readFile } from 'node:fs/promises';
import { existsSync } from 'node:fs';
import { sep, dirname } from 'node:path';
import { MockTestOrgData, instantiateContext, stubContext, restoreContext } from '@salesforce/core/lib/testSetup';
import { Messages, Org } from '@salesforce/core';
import { Messages, Org, Lifecycle } from '@salesforce/core';
import * as kit from '@salesforce/kit';
import { expect } from 'chai';
import { ComponentStatus } from '@salesforce/source-deploy-retrieve';
Expand Down Expand Up @@ -471,10 +471,20 @@ describe('remoteSourceTrackingService', () => {
});

describe('timeout handling', () => {
const lc = Lifecycle.getInstance();
const warns = new Set<string>();
lc.onWarning((w) => {
warns.add(w);
return Promise.resolve();
});

beforeEach(() => {
warns.clear();
});

it('should stop if the computed pollingTimeout is exceeded', async () => {
// @ts-ignore
const queryStub = $$.SANDBOX.stub(remoteSourceTrackingService, 'querySourceMembersFrom').resolves([]);
const warnSpy = $$.SANDBOX.spy($$.TEST_LOGGER, 'warn');

// @ts-ignore
const trackSpy = $$.SANDBOX.stub(remoteSourceTrackingService, 'trackSourceMembers');
Expand All @@ -483,9 +493,9 @@ describe('remoteSourceTrackingService', () => {
await remoteSourceTrackingService.pollForSourceTracking(memberNames);
// changed from toolbelt because each query result goes to tracking
expect(trackSpy.callCount).to.equal(6);
expect(warnSpy.called).to.equal(true);
const expectedMsg = 'Polling for SourceMembers timed out after 6 attempts';
expect(warnSpy.calledWithMatch(expectedMsg)).to.equal(true);
expect(warns.size).to.be.greaterThan(0);
const expectedMsg = 'Polling for 3 SourceMembers timed out after 6 attempts';
expect(Array.from(warns).some((w) => w.includes(expectedMsg))).to.equal(true);
expect(queryStub.called).to.equal(true);
}).timeout(10000);

Expand All @@ -494,7 +504,6 @@ describe('remoteSourceTrackingService', () => {
$$.SANDBOX.stub(kit.env, 'getString').callsFake(() => '3');
// @ts-ignore
const queryStub = $$.SANDBOX.stub(remoteSourceTrackingService, 'querySourceMembersFrom').resolves([]);
const warnSpy = $$.SANDBOX.spy($$.TEST_LOGGER, 'warn');

// @ts-ignore
const trackSpy = $$.SANDBOX.stub(remoteSourceTrackingService, 'trackSourceMembers');
Expand All @@ -503,10 +512,9 @@ describe('remoteSourceTrackingService', () => {
await remoteSourceTrackingService.pollForSourceTracking(memberNames);
expect(trackSpy.called).to.equal(true);

expect(warnSpy.called).to.equal(true);
const expectedMsg = 'Polling for SourceMembers timed out after 3 attempts';
expect(warnSpy.calledWithMatch(expectedMsg)).to.equal(true);
expect(warnSpy.calledOnce).to.equal(true);
expect(warns.size).to.be.greaterThan(0);
const expectedMsg = 'Polling for 3 SourceMembers timed out after 3 attempts';
expect(Array.from(warns).some((w) => w.includes(expectedMsg))).to.equal(true);
expect(queryStub.called).to.equal(true);
});
});
Expand Down

0 comments on commit c6e2fae

Please sign in to comment.