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

bug: Fix OrchestratorRecognizer null checks #3074

Merged
merged 3 commits into from
Nov 17, 2020

Conversation

taicchoumsft
Copy link
Member

Closes #3073

Description

Fix the Orchestrator null check on Initialize() to be consistent at lines 156 and 299

Specific Changes

  • Change null check at line 299 to match line 156

Testing

Unit tests added to catch cases where either the orchestrator or labelResolver objects are not initialized before score is called (would have failed this test before).

rec.Initialize = sinon.fake();

let {dc, activity} = createTestDcAndActivity("hello");
rec.recognize(dc, activity)
Copy link
Contributor

Choose a reason for hiding this comment

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

Tests are a lot cleaner with async syntax.

it('Expect initialize is called when orchestrator obj is null', async () => {
        //if labelresolver is null, initialize() must be called
        const result = [
            {
                score : 0.9,
                label : {
                    name : "mockLabel"
                }
            }
        ];

        const mockResolver = new MockResolver(result);
        const testPaths = "test";

        const rec = new OrchestratorAdaptiveRecognizer(testPaths, testPaths, mockResolver);
        OrchestratorAdaptiveRecognizer.orchestrator = null;

        rec.Initialize = sinon.fake();

        const {dc, activity} = createTestDcAndActivity("hello");
        const res = await rec.recognize(dc, activity);
        assert(res);
       ...
});

Copy link
Member Author

@taicchoumsft taicchoumsft Nov 17, 2020

Choose a reason for hiding this comment

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

Thanks @joshgummersall, changed all usage of recognize to async syntax.


let {dc, activity} = createTestDcAndActivity("hello");
rec.recognize(dc, activity)
.catch(err => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Same here - in fact, you can do:

await assert.rejects(() => rec.recognize(dc, activity);

to ensure that rec.recognize fails.

Copy link
Member Author

Choose a reason for hiding this comment

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

awesome, thanks @joshgummersall. Addressed.

@coveralls
Copy link

coveralls commented Nov 17, 2020

Pull Request Test Coverage Report for Build 369070518

  • 0 of 1 (0.0%) changed or added relevant line in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.02%) to 84.782%

Changes Missing Coverage Covered Lines Changed/Added Lines %
libraries/botbuilder-ai-orchestrator/src/orchestratorAdaptiveRecognizer.ts 0 1 0.0%
Totals Coverage Status
Change from base Build 368669785: 0.02%
Covered Lines: 17305
Relevant Lines: 19491

💛 - Coveralls

@joshgummersall joshgummersall merged commit b8d2004 into main Nov 17, 2020
@joshgummersall joshgummersall deleted the tachou/fixOrchNullChecks branch November 17, 2020 23:56
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.

OrchestratorAdaptiveRecognizer Initialize not checking if resolver is null.
4 participants