Skip to content

Commit e3e1fb7

Browse files
committed
return error on empty join
Signed-off-by: Teo Koon Peng <[email protected]>
1 parent 6725752 commit e3e1fb7

File tree

3 files changed

+68
-1
lines changed

3 files changed

+68
-1
lines changed

src/diagram.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -431,6 +431,9 @@ pub enum DiagramError {
431431
#[error("response cannot be split")]
432432
NotSplittable,
433433

434+
#[error("empty join is not allowed")]
435+
EmptyJoin,
436+
434437
#[error(transparent)]
435438
CannotTransform(#[from] TransformError),
436439

src/diagram/join.rs

Lines changed: 60 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ mod tests {
7070
use smallvec::SmallVec;
7171
use test_log::test;
7272

73-
use crate::{diagram::testing::DiagramTestFixture, Diagram, JsonPosition};
73+
use crate::{diagram::testing::DiagramTestFixture, Diagram, DiagramError, JsonPosition};
7474

7575
#[test]
7676
fn test_join() {
@@ -155,4 +155,63 @@ mod tests {
155155
assert!(result[1] == 3 || result[1] == 6);
156156
assert!(result[0] != result[1]);
157157
}
158+
159+
#[test]
160+
fn test_empty_join() {
161+
let mut fixture = DiagramTestFixture::new();
162+
163+
fn get_split_value(pair: (JsonPosition, serde_json::Value)) -> serde_json::Value {
164+
pair.1
165+
}
166+
167+
fixture.registry.register_node_builder(
168+
"get_split_value".to_string(),
169+
"get_split_value".to_string(),
170+
|builder, _config: ()| builder.create_map_block(get_split_value),
171+
);
172+
173+
let diagram = Diagram::from_json(json!({
174+
"ops": {
175+
"start": {
176+
"type": "start",
177+
"next": "split",
178+
},
179+
"split": {
180+
"type": "split",
181+
"index": ["getSplitValue1", "getSplitValue2"]
182+
},
183+
"getSplitValue1": {
184+
"type": "node",
185+
"builder": "get_split_value",
186+
"next": "op1",
187+
},
188+
"op1": {
189+
"type": "node",
190+
"builder": "multiply3_uncloneable",
191+
"next": "terminate",
192+
},
193+
"getSplitValue2": {
194+
"type": "node",
195+
"builder": "get_split_value",
196+
"next": "op2",
197+
},
198+
"op2": {
199+
"type": "node",
200+
"builder": "multiply3_uncloneable",
201+
"next": "terminate",
202+
},
203+
"join": {
204+
"type": "join",
205+
"next": "terminate",
206+
},
207+
"terminate": {
208+
"type": "terminate",
209+
},
210+
}
211+
}))
212+
.unwrap();
213+
214+
let err = fixture.spawn_io_workflow(&diagram).unwrap_err();
215+
assert!(matches!(err, DiagramError::EmptyJoin));
216+
}
158217
}

src/diagram/workflow_builder.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,11 @@ fn connect_vertex<'a>(
231231
// join needs all incoming edges to be connected at once so it is done at the vertex level
232232
// instead of per edge level.
233233
DiagramOperation::Join(_) => {
234+
if target.in_edges.is_empty() {
235+
if target.in_edges.is_empty() {
236+
return Err(DiagramError::EmptyJoin);
237+
}
238+
}
234239
let outputs: Vec<DynOutput> = target
235240
.in_edges
236241
.iter()

0 commit comments

Comments
 (0)