Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chore: unregister pending threads on destroy #173

Merged
merged 1 commit into from
Apr 14, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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