Skip to content

Commit

Permalink
fix: pollStatusAndAuth uses the sandbox process id rather than sandbo…
Browse files Browse the repository at this point in the history
…x info id
  • Loading branch information
shetzel committed Oct 4, 2023
1 parent 6a78a03 commit 0bf1680
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 14 deletions.
4 changes: 1 addition & 3 deletions src/org/org.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1346,9 +1346,7 @@ export class Org extends AsyncOptionalCreatable<Org.Options> {
let waitingOnAuth = false;
const pollingClient = await PollingClient.create({
poll: async (): Promise<StatusResult> => {
const sandboxProcessObj = await this.querySandboxProcessBySandboxInfoId(
options.sandboxProcessObj.SandboxInfoId
);
const sandboxProcessObj = await this.querySandboxProcessById(options.sandboxProcessObj.Id);
// check to see if sandbox can authenticate via sandboxAuth endpoint
const sandboxInfo = await this.sandboxSignupComplete(sandboxProcessObj);
if (sandboxInfo) {
Expand Down
63 changes: 52 additions & 11 deletions test/unit/org/orgTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1068,11 +1068,11 @@ describe('Org Tests', () => {
'SELECT Id, Status, SandboxName, SandboxInfoId, LicenseType, CreatedDate, CopyProgress, SandboxOrganization, SourceId, Description, EndDate FROM SandboxProcess WHERE %s ORDER BY CreatedDate DESC';
let lifecycleSpy: SinonSpy;
let queryStub: SinonStub;
let pollStatusAndAuthStub: SinonStub;
let pollStatusAndAuthSpy: SinonSpy;

beforeEach(async () => {
queryStub = stubMethod($$.SANDBOX, prod.getConnection().tooling, 'query');
pollStatusAndAuthStub = stubMethod($$.SANDBOX, prod, 'pollStatusAndAuth').resolves(statusResult.records[0]);
pollStatusAndAuthSpy = spyMethod($$.SANDBOX, prod, 'pollStatusAndAuth');
lifecycleSpy = spyMethod($$.SANDBOX, Lifecycle.prototype, 'emit');
});

Expand All @@ -1087,7 +1087,7 @@ describe('Org Tests', () => {
const error = err as SfError;
expect(error.name).to.equal('SandboxCreateNotCompleteError');
expect(queryStub.firstCall.firstArg).to.equal(format(expectedSoql, `Id='${sbxProcessId}'`));
expect(pollStatusAndAuthStub.called).to.be.false;
expect(pollStatusAndAuthSpy.called).to.be.false;
expect(lifecycleSpy.calledWith(SandboxEvents.EVENT_RESUME, statusResult.records[0])).to.be.true;
expect(lifecycleSpy.calledWith(SandboxEvents.EVENT_ASYNC_RESULT, statusResult.records[0])).to.be.true;
}
Expand All @@ -1104,7 +1104,7 @@ describe('Org Tests', () => {
const error = err as SfError;
expect(error.name).to.equal('SandboxCreateNotCompleteError');
expect(queryStub.firstCall.firstArg).to.equal(format(expectedSoql, `SandboxName='${sbxName}'`));
expect(pollStatusAndAuthStub.called).to.be.false;
expect(pollStatusAndAuthSpy.called).to.be.false;
expect(lifecycleSpy.calledWith(SandboxEvents.EVENT_RESUME, statusResult.records[0])).to.be.true;
expect(lifecycleSpy.calledWith(SandboxEvents.EVENT_ASYNC_RESULT, statusResult.records[0])).to.be.true;
}
Expand All @@ -1126,7 +1126,7 @@ describe('Org Tests', () => {
const error = err as SfError;
expect(error.name).to.equal('SandboxCreateNotCompleteError');
expect(queryStub.firstCall.firstArg).to.equal(format(expectedSoql, `SandboxName='${sbxName}'`));
expect(pollStatusAndAuthStub.called).to.be.false;
expect(pollStatusAndAuthSpy.called).to.be.false;
expect(lifecycleSpy.calledWith(SandboxEvents.EVENT_RESUME, pendingSbxProcess)).to.be.true;
expect(lifecycleSpy.calledWith(SandboxEvents.EVENT_ASYNC_RESULT, pendingSbxProcess)).to.be.true;

Expand All @@ -1141,16 +1141,57 @@ describe('Org Tests', () => {
}
});

it('should resume a sandbox process and poll', async () => {
it('should resume a sandbox process by ID and poll by ID', async () => {
queryStub.resolves(statusResult);
const querySbxProcessIdSpy = spyMethod($$.SANDBOX, prod, 'querySandboxProcessById');
const sbxProcessId = statusResult.records[0].Id;

const result = await prod.resumeSandbox({ SandboxProcessObjId: sbxProcessId }, { wait: Duration.minutes(1) });
try {
await shouldThrow(
prod.resumeSandbox(
{ SandboxProcessObjId: sbxProcessId },
{ wait: Duration.milliseconds(500), interval: Duration.milliseconds(100) }
)
);
} catch (err) {
// Expect a client timed out error
const error = err as SfError;
expect(error.name).to.equal('PollingClientTimeout');
expect(queryStub.firstCall.firstArg).to.equal(format(expectedSoql, `Id='${sbxProcessId}'`));
expect(queryStub.secondCall.firstArg).to.equal(format(expectedSoql, `Id='${sbxProcessId}'`));
expect(pollStatusAndAuthSpy.called).to.be.true;
expect(querySbxProcessIdSpy.called).to.be.true;
expect(querySbxProcessIdSpy.firstCall.firstArg).to.equal(statusResult.records[0].Id);
expect(lifecycleSpy.calledWith(SandboxEvents.EVENT_RESUME, statusResult.records[0])).to.be.true;
expect(lifecycleSpy.calledWith(SandboxEvents.EVENT_STATUS)).to.be.true;
}
});

it('should resume a sandbox process by Name and poll by ID', async () => {
queryStub.resolves(statusResult);
const querySbxProcessIdSpy = spyMethod($$.SANDBOX, prod, 'querySandboxProcessById');
const sbxProcessId = statusResult.records[0].Id;
const sbxName = statusResult.records[0].SandboxName;

expect(queryStub.firstCall.firstArg).to.equal(format(expectedSoql, `Id='${sbxProcessId}'`));
expect(pollStatusAndAuthStub.called).to.be.true;
expect(lifecycleSpy.calledWith(SandboxEvents.EVENT_RESUME, statusResult.records[0])).to.be.true;
expect(result).to.deep.equal(statusResult.records[0]);
try {
await shouldThrow(
prod.resumeSandbox(
{ SandboxName: sbxName },
{ wait: Duration.milliseconds(500), interval: Duration.milliseconds(100) }
)
);
} catch (err) {
// Expect a client timed out error
const error = err as SfError;
expect(error.name).to.equal('PollingClientTimeout');
expect(queryStub.firstCall.firstArg).to.equal(format(expectedSoql, `SandboxName='${sbxName}'`));
expect(queryStub.secondCall.firstArg).to.equal(format(expectedSoql, `Id='${sbxProcessId}'`));
expect(pollStatusAndAuthSpy.called).to.be.true;
expect(querySbxProcessIdSpy.called).to.be.true;
expect(querySbxProcessIdSpy.firstCall.firstArg).to.equal(statusResult.records[0].Id);
expect(lifecycleSpy.calledWith(SandboxEvents.EVENT_RESUME, statusResult.records[0])).to.be.true;
expect(lifecycleSpy.calledWith(SandboxEvents.EVENT_STATUS)).to.be.true;
}
});
});

Expand Down

2 comments on commit 0bf1680

@svc-cli-bot
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Logger Benchmarks - ubuntu-latest

Benchmark suite Current: 0bf1680 Previous: d3e22b9 Ratio
Child logger creation 467723 ops/sec (±1.28%) 451704 ops/sec (±1.00%) 0.97
Logging a string on root logger 457572 ops/sec (±10.23%) 404015 ops/sec (±15.69%) 0.88
Logging an object on root logger 292299 ops/sec (±12.07%) 297073 ops/sec (±10.13%) 1.02
Logging an object with a message on root logger 225815 ops/sec (±12.02%) 200285 ops/sec (±9.47%) 0.89
Logging an object with a redacted prop on root logger 211008 ops/sec (±16.26%) 238942 ops/sec (±13.78%) 1.13
Logging a nested 3-level object on root logger 4348 ops/sec (±202.34%) 6819 ops/sec (±188.97%) 1.57

This comment was automatically generated by workflow using github-action-benchmark.

@svc-cli-bot
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Logger Benchmarks - windows-latest

Benchmark suite Current: 0bf1680 Previous: d3e22b9 Ratio
Child logger creation 385727 ops/sec (±3.69%) 367792 ops/sec (±8.56%) 0.95
Logging a string on root logger 494376 ops/sec (±9.07%) 456835 ops/sec (±15.45%) 0.92
Logging an object on root logger 334002 ops/sec (±15.86%) 316220 ops/sec (±18.97%) 0.95
Logging an object with a message on root logger 255001 ops/sec (±12.99%) 239758 ops/sec (±23.52%) 0.94
Logging an object with a redacted prop on root logger 234076 ops/sec (±18.85%) 232064 ops/sec (±18.42%) 0.99
Logging a nested 3-level object on root logger 5801 ops/sec (±189.68%) 7015 ops/sec (±188.57%) 1.21

This comment was automatically generated by workflow using github-action-benchmark.

Please sign in to comment.