-
Notifications
You must be signed in to change notification settings - Fork 65
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #690 from codeforequity-at/develop
Botium Core 1.13.1
- Loading branch information
Showing
7 changed files
with
1,598 additions
and
953 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,134 @@ | ||
const path = require('path') | ||
const assert = require('chai').assert | ||
const BotDriver = require('../../').BotDriver | ||
const Capabilities = require('../../').Capabilities | ||
|
||
const echoConnector = (numErrors, errorText) => ({ queueBotSays }) => { | ||
let errors = 0 | ||
return { | ||
UserSays (msg) { | ||
if (errors >= numErrors) { | ||
const botMsg = { sender: 'bot', sourceData: msg.sourceData, messageText: msg.messageText } | ||
queueBotSays(botMsg) | ||
} else { | ||
errors++ | ||
return Promise.reject(errorText) | ||
} | ||
} | ||
} | ||
} | ||
|
||
describe('convo.retries', function () { | ||
beforeEach(async function () { | ||
this.init = async (numErrors, errorText, errorPatterns, numRetries) => { | ||
const myCaps = { | ||
[Capabilities.PROJECTNAME]: 'convo.retry', | ||
[Capabilities.CONTAINERMODE]: echoConnector(numErrors, errorText), | ||
RETRY_CONVO_MINTIMEOUT: 10, | ||
RETRY_CONVO_ONERROR_REGEXP: errorPatterns | ||
} | ||
if (!isNaN(numRetries)) { | ||
myCaps.RETRY_CONVO_NUMRETRIES = numRetries | ||
} | ||
this.driver = new BotDriver(myCaps) | ||
this.compiler = this.driver.BuildCompiler() | ||
this.container = await this.driver.Build() | ||
await this.container.Start() | ||
} | ||
}) | ||
afterEach(async function () { | ||
await this.container.Stop() | ||
await this.container.Clean() | ||
}) | ||
|
||
it('should fail without retry', async function () { | ||
await this.init(1, 'myerror') | ||
|
||
this.compiler.ReadScript(path.resolve(__dirname, 'convos'), '1step.convo.txt') | ||
try { | ||
await this.compiler.convos[0].Run(this.container) | ||
} catch (err) { | ||
assert.isTrue(err.message.indexOf('myerror') >= 0) | ||
return | ||
} | ||
assert.fail('should have failed without retry') | ||
}) | ||
it('should succeed after one retry with default numRetries', async function () { | ||
await this.init(1, 'myerror', 'myerror') | ||
|
||
this.compiler.ReadScript(path.resolve(__dirname, 'convos'), '1step.convo.txt') | ||
await this.compiler.convos[0].Run(this.container) | ||
}) | ||
it('should succeed after one retry with joker regex', async function () { | ||
await this.init(1, 'myerror', null, 1) | ||
|
||
this.compiler.ReadScript(path.resolve(__dirname, 'convos'), '1step.convo.txt') | ||
await this.compiler.convos[0].Run(this.container) | ||
}) | ||
it('should fail after one retry with default settings', async function () { | ||
await this.init(2, 'myerror', 'myerror') | ||
|
||
this.compiler.ReadScript(path.resolve(__dirname, 'convos'), '1step.convo.txt') | ||
try { | ||
await this.compiler.convos[0].Run(this.container) | ||
} catch (err) { | ||
assert.isTrue(err.message.indexOf('myerror') >= 0) | ||
return | ||
} | ||
assert.fail('should have failed after first retry') | ||
}) | ||
it('should succeed after many retries', async function () { | ||
await this.init(5, 'myerror', 'myerror', 5) | ||
|
||
this.compiler.ReadScript(path.resolve(__dirname, 'convos'), '1step.convo.txt') | ||
await this.compiler.convos[0].Run(this.container) | ||
}) | ||
it('should succeed after too less retries', async function () { | ||
await this.init(5, 'myerror', 'myerror', 4) | ||
|
||
this.compiler.ReadScript(path.resolve(__dirname, 'convos'), '1step.convo.txt') | ||
try { | ||
await this.compiler.convos[0].Run(this.container) | ||
} catch (err) { | ||
assert.isTrue(err.message.indexOf('myerror') >= 0) | ||
return | ||
} | ||
assert.fail('should have failed after four retries') | ||
}) | ||
it('should succeed after one retry with regexp pattern', async function () { | ||
await this.init(1, 'myerror', /myeRRor/i) | ||
|
||
this.compiler.ReadScript(path.resolve(__dirname, 'convos'), '1step.convo.txt') | ||
await this.compiler.convos[0].Run(this.container) | ||
}) | ||
it('should fail after one retry with unmatched regexp pattern', async function () { | ||
await this.init(1, 'myerror', /myeRRor1/i) | ||
|
||
this.compiler.ReadScript(path.resolve(__dirname, 'convos'), '1step.convo.txt') | ||
try { | ||
await this.compiler.convos[0].Run(this.container) | ||
} catch (err) { | ||
assert.isTrue(err.message.indexOf('myerror') >= 0) | ||
return | ||
} | ||
assert.fail('should have failed with unmatched retry pattern') | ||
}) | ||
it('should succeed after one retry with regexp pattern array', async function () { | ||
await this.init(1, 'myerror', [/myeRRor/i, /myeRRor1/i]) | ||
|
||
this.compiler.ReadScript(path.resolve(__dirname, 'convos'), '1step.convo.txt') | ||
await this.compiler.convos[0].Run(this.container) | ||
}) | ||
it('should fail after one retry with unmatched regexp pattern array', async function () { | ||
await this.init(1, 'myerror', [/myeRRor1/i, /myeRRor2/i]) | ||
|
||
this.compiler.ReadScript(path.resolve(__dirname, 'convos'), '1step.convo.txt') | ||
try { | ||
await this.compiler.convos[0].Run(this.container) | ||
} catch (err) { | ||
assert.isTrue(err.message.indexOf('myerror') >= 0) | ||
return | ||
} | ||
assert.fail('should have failed with unmatched retry pattern') | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters