Skip to content

Commit

Permalink
Chore: unregister pending threads on destroy (#173)
Browse files Browse the repository at this point in the history
  • Loading branch information
pramodsum authored Apr 14, 2018
1 parent 580e1d7 commit 0b93e82
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
6 changes: 1 addition & 5 deletions src/controllers/AnnotationModeController.js
Original file line number Diff line number Diff line change
Expand Up @@ -443,12 +443,8 @@ class AnnotationModeController extends EventEmitter {
const pageThreads = this.threads[pageNum].all() || [];
pageThreads.forEach((thread) => {
if (isPending(thread.state)) {
this.unregisterThread(thread);
hadPendingThreads = true;

/* eslint-disable no-console */
console.error('Pending annotation thread destroyed', thread.threadNumber);
/* eslint-enable no-console */

thread.destroy();
} else if (thread.isDialogVisible()) {
thread.hideDialog();
Expand Down
8 changes: 7 additions & 1 deletion src/controllers/__tests__/AnnotationModeController-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -512,14 +512,16 @@ describe('controllers/AnnotationModeController', () => {
beforeEach(() => {
stubs.isPending = sandbox.stub(util, 'isPending').returns(false);
stubs.isPending.withArgs(STATES.pending).returns(true);

sandbox.stub(controller, 'unregisterThread');
controller.registerThread(stubs.thread);
});

it('should destroy and return true if there are any pending threads', () => {
stubs.threadMock.expects('destroy');
const destroyed = controller.destroyPendingThreads();
expect(destroyed).to.be.true;
expect(controller.unregisterThread).to.be.called;
expect(controller.unregisterThread).to.be.called;
});

it('should not destroy and return false if there are no threads', () => {
Expand All @@ -528,6 +530,7 @@ describe('controllers/AnnotationModeController', () => {
stubs.isPending.returns(false);
const destroyed = controller.destroyPendingThreads();
expect(destroyed).to.be.false;
expect(controller.unregisterThread).to.not.be.called;
});

it('should not destroy and return false if the threads are not pending', () => {
Expand All @@ -537,6 +540,7 @@ describe('controllers/AnnotationModeController', () => {
stubs.threadMock.expects('hideDialog').never();
const destroyed = controller.destroyPendingThreads();
expect(destroyed).to.be.false;
expect(controller.unregisterThread).to.not.be.called;
});

it('should hide non-pending thread dialogs that are visible', () => {
Expand All @@ -546,6 +550,7 @@ describe('controllers/AnnotationModeController', () => {
stubs.threadMock.expects('hideDialog');
const destroyed = controller.destroyPendingThreads();
expect(destroyed).to.be.false;
expect(controller.unregisterThread).to.not.be.called;
});

it('should destroy only pending threads, and return true', () => {
Expand All @@ -568,6 +573,7 @@ describe('controllers/AnnotationModeController', () => {
const destroyed = controller.destroyPendingThreads();

expect(destroyed).to.be.true;
expect(controller.unregisterThread).to.be.called;
});
});

Expand Down

0 comments on commit 0b93e82

Please sign in to comment.