Skip to content

Do not call callbacks twice in async boot scripts#260

Merged
bajtos merged 1 commit intostrongloop:2.xfrom
lehni:feature/async-boot-scripts-2.x
Aug 17, 2017
Merged

Do not call callbacks twice in async boot scripts#260
bajtos merged 1 commit intostrongloop:2.xfrom
lehni:feature/async-boot-scripts-2.x

Conversation

@lehni
Copy link
Copy Markdown
Contributor

@lehni lehni commented Aug 15, 2017

Description

As discussed in #252 (comment), we need to make sure that a boot script that both returns a promise and calls the callback method does not trigger two calls of the callback method passed to boot.execute().

Related issues

Checklist

  • New tests added or existing tests modified to cover all changes
  • Code conforms with the style
    guide

@slnode
Copy link
Copy Markdown

slnode commented Aug 15, 2017

Can one of the admins verify this patch? To accept patch and trigger a build add comment ".ok\W+to\W+test."

@slnode
Copy link
Copy Markdown

slnode commented Aug 15, 2017

Can one of the admins verify this patch?

2 similar comments
@slnode
Copy link
Copy Markdown

slnode commented Aug 15, 2017

Can one of the admins verify this patch?

@slnode
Copy link
Copy Markdown

slnode commented Aug 15, 2017

Can one of the admins verify this patch?

Copy link
Copy Markdown
Member

@bajtos bajtos left a comment

Choose a reason for hiding this comment

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

Thank you for the pull request!

count++;
expect(count).to.eql(1);
process.nextTick(function() {
done();
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think this is rather brittle as it relies on boot.execute to make the second call of the callback before process.nextTick is run.

Fortunately, mocha detects the situation when the done callback was called twice and fails the test with a helpful error: Error: done() called multiple times.

I am proposing to simplify this test to simply pass done as the callback of boot.execute.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Ok, let me test this.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

You're right! I adjusted the PR accordingly now.

@bajtos
Copy link
Copy Markdown
Member

bajtos commented Aug 16, 2017

@slnode ok to test

});

it('should only call the callback once', function(done) {
boot.execute(app, simpleAppInstructions(), done);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Perhaps add a comment explaining that mocha fails the test when the callback was called multiple times?

@bajtos bajtos merged commit ded190e into strongloop:2.x Aug 17, 2017
@bajtos
Copy link
Copy Markdown
Member

bajtos commented Aug 17, 2017

Landed, thank you for the contribution! 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants