Skip to content

Commit

Permalink
Merge pull request #3 from erikdesjardins/delay-before-poll
Browse files Browse the repository at this point in the history
Delay before polling to try to avoid 500s
  • Loading branch information
erikdesjardins committed May 5, 2018
2 parents bf100b9 + 7554041 commit b9026e2
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 4 deletions.
7 changes: 4 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,15 +173,15 @@ module.exports = function deploy(options) {
.then(function poll() {
// https://docs.microsoft.com/en-us/windows/uwp/monetize/get-status-for-an-app-submission
// https://docs.microsoft.com/en-us/windows/uwp/monetize/get-status-for-a-flight-submission
return request
return sleep(30000).then(() => request
.get(appAndFlight + '/submissions/' + submissionInfo.id + '/status')
.set('Authorization', 'Bearer ' + accessToken)
.then(function(response) {
// https://github.com/Microsoft/StoreBroker/blob/master/Documentation/USAGE.md#status-progression
var status = response.body.status;
if (status === 'PendingCommit' || status === 'CommitStarted') {
// try again
return sleep(30000).then(poll);
return poll();
} else if (
status !== 'PreProcessing' &&
// anything other than PreProcessing is unlikely,
Expand All @@ -193,6 +193,7 @@ module.exports = function deploy(options) {
}
}, function(err) {
throw new Error('Failed to poll for commit status: ' + (err.response.body.code || err.response.status));
});
})
);
});
};
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "edge-extension-deploy",
"version": "1.0.0",
"version": "1.0.1",
"description": "Deploy Edge extensions to the Windows Store.",
"main": "index.js",
"scripts": {
Expand Down
29 changes: 29 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,18 @@ test.beforeEach(t => {
throw new Error('No mocked endpoint for: ' + match);
}
}]);

const oldSetTimeout = global.setTimeout;
t.context.oldSetTimeout = oldSetTimeout;
global.setTimeout = function shortSetTimeout(fn, delay, ...args) {
return oldSetTimeout(fn, delay / 1000, ...args);
};
});

test.afterEach(t => {
t.context.mock.unset();

global.setTimeout = t.context.oldSetTimeout;
});

test.serial('missing fields', async t => {
Expand Down Expand Up @@ -326,6 +334,27 @@ test.serial('bad commit status after polling 2', async t => {
t.is(t.context.requests.length, 8);
});

test.serial('bad commit status after multiple polling', async t => {
t.context.responses = [
{ access_token: 'q' },
{},
{ fileUploadUrl: 'https://mockfileupload.url', applicationPackages: [] },
{},
{},
{},
{ status: 'PendingCommit' },
{ status: 'CommitStarted' },
{ status: 'CommitFailed', statusDetails: 'statusDetails' }
];

await t.throws(
deploy({ tenantId: 'q', clientId: 'q', clientSecret: 'q', appId: 'q', appx: new EmptyStream() }),
'Failed: CommitFailed "statusDetails"',
);

t.is(t.context.requests.length, 9);
});

test.serial('full publish, no pending submission', async t => {
t.context.responses = [
{ access_token: 'myAccessToken' },
Expand Down

0 comments on commit b9026e2

Please sign in to comment.