Skip to content

Commit

Permalink
Fix: Don't wait when rep status is none (#871)
Browse files Browse the repository at this point in the history
  • Loading branch information
Conrad Chan authored Nov 28, 2018
1 parent 258f3f5 commit 893e724
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 7 deletions.
12 changes: 7 additions & 5 deletions src/lib/RepStatus.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import EventEmitter from 'events';
import { get, appendAuthParams } from './util';
import { STATUS_SUCCESS, STATUS_VIEWABLE } from './constants';
import { STATUS_SUCCESS, STATUS_VIEWABLE, STATUS_PENDING, STATUS_NONE } from './constants';
import PreviewError from './PreviewError';
import Timer from './Timer';
import { ERROR_CODE, LOAD_METRIC } from './events';
Expand Down Expand Up @@ -142,19 +142,21 @@ class RepStatus extends EventEmitter {
this.resolve();
break;

case 'none':
case 'pending':
case STATUS_NONE:
case STATUS_PENDING:
// If we are doing some logging, log that the file needed conversion
if (this.logger) {
this.logger.setUnConverted();
}

this.emit('conversionpending');

// Check status again after delay
// Check status again after delay or
// If status is none, request immediately since conversion
// won't kick off until representation is requested
this.statusTimeout = setTimeout(() => {
this.updateStatus();
}, STATUS_UPDATE_INTERVAL_MS);
}, status === STATUS_NONE ? 0 : STATUS_UPDATE_INTERVAL_MS);
break;

default:
Expand Down
13 changes: 12 additions & 1 deletion src/lib/__tests__/RepStatus-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ describe('lib/RepStatus', () => {
expect(repStatus.emit).to.be.calledWith('conversionpending');
});

it('should update status after a timeout', () => {
it('should update status after a timeout and update interval when pending', () => {
const clock = sinon.useFakeTimers();
repStatus.logger = false;
sandbox.mock(repStatus).expects('updateStatus');
Expand All @@ -261,6 +261,17 @@ describe('lib/RepStatus', () => {
clock.restore();
});

it('should update status immediately after a timeout when none', () => {
const clock = sinon.useFakeTimers();
repStatus.logger = false;
sandbox.mock(repStatus).expects('updateStatus');
repStatus.representation.status.state = 'none';

repStatus.handleResponse();
clock.tick(1);
clock.restore();
});

it('should stop a convert time Timer on success converting', () => {
repStatus.representation.status.state = STATUS_SUCCESS;
const tag = Timer.createTag(fileId, LOAD_METRIC.convertTime);
Expand Down
3 changes: 2 additions & 1 deletion src/lib/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,10 @@ export const ORIGINAL_REP_NAME = 'ORIGINAL';
export const PRELOAD_REP_NAME = 'jpg';

export const STATUS_ERROR = 'error';
export const STATUS_NONE = 'none';
export const STATUS_PENDING = 'pending';
export const STATUS_SUCCESS = 'success';
export const STATUS_VIEWABLE = 'viewable';
export const STATUS_PENDING = 'pending';

// X-Rep-Hints for Representations API
export const X_REP_HINT_BASE = '[3d][pdf][text][mp3]';
Expand Down

0 comments on commit 893e724

Please sign in to comment.