Skip to content

Commit

Permalink
Merge pull request #41 from bocasti/refine-error-handling-in-parallel…
Browse files Browse the repository at this point in the history
…-node

make sure the activation is in state error when input is invalid for paral…
  • Loading branch information
noha authored Jun 11, 2024
2 parents d735f24 + 1685a7c commit 117d02c
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 16 deletions.
13 changes: 13 additions & 0 deletions source/FingerBoard-Core-Tests/FBFlowTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,19 @@ FBFlowTest >> testNodeWithIdError [
raise: FBNodeNotFound
]

{ #category : #tests }
FBFlowTest >> testParallelNodeEmptyList [
| flow instance |
flow := FBFlow parallelFlowOpen.
instance := flow newInstance.
instance executeWith: { }.
self assert: instance atEnd.
self assert: instance state equals: #done.
"there should be one activation per node. The flow should have stopped at the parallel node because the collection was empty"
self assert: instance activations size equals: 2.

]

{ #category : #tests }
FBFlowTest >> testParallelNodeJoined [
| flow instance |
Expand Down
5 changes: 0 additions & 5 deletions source/FingerBoard-Core/FBActivation.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,6 @@ FBActivation >> events [
^ self flowInstance eventsOfActivation: self
]

{ #category : #accessing }
FBActivation >> instance [
^ executor flowInstance
]

{ #category : #'as yet unclassified' }
FBActivation >> isDone [
^ state = #done
Expand Down
5 changes: 5 additions & 0 deletions source/FingerBoard-Core/FBBaseActivation.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,11 @@ FBBaseActivation >> initialize [
state := #created
]

{ #category : #accessing }
FBBaseActivation >> instance [
^ executor flowInstance
]

{ #category : #accessing }
FBBaseActivation >> node [
^ node
Expand Down
7 changes: 1 addition & 6 deletions source/FingerBoard-Core/FBParallelExecutor.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,7 @@ FBParallelExecutor >> step [
transition := pending removeFirst.
values := transition source lastValueIn: self.
activation := self newActivation: transition.
(values isCollection and: [ values isSequenceable ]) ifFalse: [
self addEvent: (FBNodeActivationErrored new
activation: activation;
activationError:
'Input for parallel execution has to be a collection.').
^ self ].
activation initializeValues: list size.
lastValue := values at: index.
activation argument: lastValue.
self activate: activation.
Expand Down
16 changes: 11 additions & 5 deletions source/FingerBoard-Core/FBParallelNodeBehavior.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,15 @@ Class {
}

{ #category : #execution }
FBParallelNodeBehavior >> execute [
activation flowInstance pushExecutor: (FBParallelExecutor new
node: activation node;
list: activation argument ).
activation value: activation argument
FBParallelNodeBehavior >> execute [

(activation argument isCollection and: [
activation argument isSequenceable ]) ifFalse: [
FBError signal:
'Input for parallel execution has to be a non empty collection.' ].
activation argument size > 0 ifFalse: [ ^ self ].
activation flowInstance pushExecutor: (FBParallelExecutor new
node: activation node;
list: activation argument).
activation value: activation argument
]

0 comments on commit 117d02c

Please sign in to comment.