|
7 | 7 | import { fail } from 'assert';
|
8 | 8 | import { createSandbox, SinonStub } from 'sinon';
|
9 | 9 | import { MockTestOrgData, testSetup } from '@salesforce/core/lib/testSetup';
|
10 |
| -import { AuthInfo, Connection } from '@salesforce/core'; |
| 10 | +import { AuthInfo, Connection, PollingClient } from '@salesforce/core'; |
11 | 11 | import { expect } from 'chai';
|
12 |
| -import { sleep } from '@salesforce/kit'; |
| 12 | +import { Duration, sleep } from '@salesforce/kit'; |
13 | 13 | import { ComponentSet } from '../../src';
|
14 | 14 | import { MetadataTransfer } from '../../src/client/metadataTransfer';
|
15 | 15 | import { MetadataRequestStatus, MetadataTransferResult, RequestStatus } from '../../src/client/types';
|
@@ -163,7 +163,68 @@ describe('MetadataTransfer', () => {
|
163 | 163 | expect(listenerStub.callCount).to.equal(1);
|
164 | 164 | });
|
165 | 165 |
|
166 |
| - it('should wait for polling function to return before queing another', async () => { |
| 166 | + it('should calculate polling frequency based on source components, 0 -> 1000', async () => { |
| 167 | + const pollingClientStub = env.stub(PollingClient, 'create').resolves(PollingClient.prototype); |
| 168 | + env.stub(PollingClient.prototype, 'subscribe').resolves({ status: RequestStatus.Canceled, done: true }); |
| 169 | + const { checkStatus } = operation.lifecycle; |
| 170 | + checkStatus.resolves({ status: RequestStatus.Canceled, done: true }); |
| 171 | + |
| 172 | + operation.onCancel(() => listenerStub()); |
| 173 | + await operation.pollStatus(); |
| 174 | + |
| 175 | + expect(pollingClientStub.calledOnce).to.be.true; |
| 176 | + expect((pollingClientStub.firstCall.args[0] as { frequency: number }).frequency).to.deep.equal( |
| 177 | + Duration.milliseconds(1000) |
| 178 | + ); |
| 179 | + }); |
| 180 | + |
| 181 | + it('should calculate polling frequency based on source components, 10 -> 100', async () => { |
| 182 | + // @ts-ignore protected member access |
| 183 | + env.stub(operation.components, 'getSourceComponents').returns({ |
| 184 | + // eslint-disable-next-line @typescript-eslint/ban-ts-comment |
| 185 | + // @ts-ignore only override length attribute |
| 186 | + toArray: () => { |
| 187 | + return { length: 10 }; |
| 188 | + }, |
| 189 | + }); |
| 190 | + const pollingClientStub = env.stub(PollingClient, 'create').resolves(PollingClient.prototype); |
| 191 | + env.stub(PollingClient.prototype, 'subscribe').resolves({ status: RequestStatus.Canceled, done: true }); |
| 192 | + const { checkStatus } = operation.lifecycle; |
| 193 | + checkStatus.resolves({ status: RequestStatus.Canceled, done: true }); |
| 194 | + |
| 195 | + operation.onCancel(() => listenerStub()); |
| 196 | + await operation.pollStatus({ frequency: undefined, timeout: Duration.minutes(60) }); |
| 197 | + |
| 198 | + expect(pollingClientStub.calledOnce).to.be.true; |
| 199 | + expect((pollingClientStub.firstCall.args[0] as { frequency: number }).frequency).to.deep.equal( |
| 200 | + Duration.milliseconds(100) |
| 201 | + ); |
| 202 | + }); |
| 203 | + |
| 204 | + it('should calculate polling frequency based on source components, 2520 -> 2520', async () => { |
| 205 | + // @ts-ignore protected member access |
| 206 | + env.stub(operation.components, 'getSourceComponents').returns({ |
| 207 | + // eslint-disable-next-line @typescript-eslint/ban-ts-comment |
| 208 | + // @ts-ignore only override length attribute |
| 209 | + toArray: () => { |
| 210 | + return { length: 2520 }; |
| 211 | + }, |
| 212 | + }); |
| 213 | + const pollingClientStub = env.stub(PollingClient, 'create').resolves(PollingClient.prototype); |
| 214 | + env.stub(PollingClient.prototype, 'subscribe').resolves({ status: RequestStatus.Canceled, done: true }); |
| 215 | + const { checkStatus } = operation.lifecycle; |
| 216 | + checkStatus.resolves({ status: RequestStatus.Canceled, done: true }); |
| 217 | + |
| 218 | + operation.onCancel(() => listenerStub()); |
| 219 | + await operation.pollStatus(undefined, 60); |
| 220 | + |
| 221 | + expect(pollingClientStub.calledOnce).to.be.true; |
| 222 | + expect((pollingClientStub.firstCall.args[0] as { frequency: number }).frequency).to.deep.equal( |
| 223 | + Duration.milliseconds(2520) |
| 224 | + ); |
| 225 | + }); |
| 226 | + |
| 227 | + it('should wait for polling function to return before queuing another', async () => { |
167 | 228 | const { checkStatus } = operation.lifecycle;
|
168 | 229 | const checkStatusRuntime = 50;
|
169 | 230 | const callOrder: string[] = [];
|
|
0 commit comments