Skip to content

Commit

Permalink
feat(core): revert scheduler to not manage errors in handler
Browse files Browse the repository at this point in the history
  • Loading branch information
wdavidw committed Mar 1, 2021
1 parent a887ebe commit c6ebce7
Show file tree
Hide file tree
Showing 12 changed files with 193 additions and 162 deletions.
4 changes: 2 additions & 2 deletions packages/core/lib/actions/execute/wait.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/core/lib/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions packages/core/lib/schedulers/native.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/core/src/actions/execute/wait.coffee.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ console.info(`Command succeed, the file "/tmp/sth" now exists: ${status}`)
while true
attempts++
log message: "Start attempt ##{attempts}", level: 'DEBUG'
commands = await await utils.promise.array_filter commands, (command) =>
commands = await utils.promise.array_filter commands, (command) =>
{status: success} = await @execute
command: command
code: config.code or 0
Expand Down
6 changes: 3 additions & 3 deletions packages/core/src/schedulers/native.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@ module.exports = (handlers, options = {}) ->
result = await item.handler.call()
state.running = false
item.resolve.call null, result
state.output.push result if item.options.output
state.output.push result if options.managed or item.options.managed
setImmediate -> scheduler.pump()
catch error
state.running = false
item.reject.call null, error
state.error = error unless state.stack.length is 0
state.error = error if options.managed or item.options.managed
setImmediate -> scheduler.pump()
unshift: (handlers, options={}) ->
options.pump ?= true
Expand Down Expand Up @@ -81,7 +81,7 @@ module.exports = (handlers, options = {}) ->
prom
if handlers
if handlers.length
scheduler.push handlers, output: true
scheduler.push handlers, managed: true
else
resolve []
promise.catch (->) # Handle strict unhandled rejections
Expand Down
4 changes: 3 additions & 1 deletion packages/core/test/actions/assert.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,15 @@ describe 'actions.assert', ->
.should.be.rejectedWith
code: 'NIKITA_ASSERT_UNTRUE'

it 'multiple actions', ->
it 'multiple actions, all resolve true', ->
nikita.assert [
-> true
,
-> new Promise (resolve) -> resolve true
]
.should.be.fulfilled()

it 'multiple actions, one resolve false', ->
nikita.assert [
-> true
,
Expand Down
19 changes: 10 additions & 9 deletions packages/core/test/plugins/metadata/relax.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,22 @@ describe 'plugins.metadata.relax', ->
error.message.should.eql 'Dont worry, be happy'

it 'handler return rejected promise', ->
nikita.call ({context}) ->
{error} = await nikita.call ({context}) ->
context.call ({context}) -> # with parent
context.call metadata: relax: true, ->
throw Error 'Dont cry, laugh outloud'
throw Error 'catchme'
error.message.should.eql 'catchme'

it 'does not depend on the sibling position, fix #282', ->
# Error thrown in last child
{error} = await nikita metadata: relax: true, ->
@call -> throw Error 'catchme'
error.message.should.eql 'catchme'
# # Error thrown in last child
# {error} = await nikita metadata: relax: true, ->
# @call -> throw Error 'catchme'
# error.message.should.eql 'catchme'
# Error not thrown in last child
{error} = await nikita metadata: relax: true, ->
result = await nikita metadata: relax: true, ->
@call -> throw Error 'catchme'
@call -> true
error.message.should.eql 'catchme'
@call -> 'getme'
result.should.eql 'getme'

it.skip 'sync with error throw in child', ->
nikita
Expand Down
65 changes: 65 additions & 0 deletions packages/core/test/scheduler/creation.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@

{tags} = require '../test'
schedule = require '../../src/schedulers/native'

describe 'scheduler.instance', ->
return unless tags.api

describe 'usage', ->

it 'is a promise', ->
schedule()
.should.be.a.Promise()

describe 'resolve', ->

it 'accept handlers in its arguments', ->
schedule([
-> new Promise (accept) -> setImmediate accept 1
-> new Promise (accept) -> accept 2
])
.should.be.resolvedWith [1, 2]

it 'accept empty array', ->
schedule([])
.should.be.resolvedWith []

it 'accept null', ->
schedule([])
.should.be.resolvedWith []

it 'not affected by push', ->
scheduler = schedule()
scheduler.push [
-> new Promise (accept) -> setImmediate accept 1
-> new Promise (accept) -> accept 2
]
scheduler.push -> new Promise (accept) -> accept 3
scheduler
.should.be.resolvedWith []

describe 'error', ->

it 'first', ->
schedule([
-> new Promise (accept, reject) -> reject Error 'catchme'
-> new Promise (accept) -> setImmediate accept 1
-> new Promise (accept) -> setImmediate accept 2
])
.should.be.rejectedWith 'catchme'

it 'middle', ->
schedule([
-> new Promise (accept, reject) -> reject Error 'catchme'
-> new Promise (accept) -> setImmediate accept 1
-> new Promise (accept) -> setImmediate accept 2
])
.should.be.rejectedWith 'catchme'

it 'last', ->
schedule([
-> new Promise (accept) -> setImmediate accept 1
-> new Promise (accept) -> setImmediate accept 2
-> new Promise (accept, reject) -> reject Error 'catchme'
])
.should.be.rejectedWith 'catchme'
94 changes: 0 additions & 94 deletions packages/core/test/scheduler/flow.coffee

This file was deleted.

48 changes: 0 additions & 48 deletions packages/core/test/scheduler/instance.coffee

This file was deleted.

Loading

0 comments on commit c6ebce7

Please sign in to comment.