Skip to content

Commit 6fa9ccf

Browse files
Fix bug in calling child flow func call
1 parent bf94b1c commit 6fa9ccf

6 files changed

Lines changed: 83 additions & 6 deletions

File tree

pkg/runtimes/dupher/isolate.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,8 +153,8 @@ func (i *Isolate) stepMaybePanic() (bool, []platforms.Event, error) {
153153
return done(), events, nil
154154

155155
case Exit:
156-
i.pc++
157-
return done(), nil, nil
156+
i.pc = len(i.instructions)
157+
return true, nil, nil
158158

159159
case Jump:
160160
i.pc = instr.Loc

pkg/runtimes/dupher/isolate_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,6 @@ func TestIsolate(t *testing.T) {
158158
wantEvents: 0,
159159
wantVars: map[string]any{"__return__": 42},
160160
},
161-
{wantDone: false, wantPC: 2, wantEvents: 0},
162161
{
163162
wantDone: true,
164163
wantPC: 3,

pkg/runtimes/dupher/worker_test.go

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -700,6 +700,49 @@ func VoidCallerFlowSpec() {
700700
},
701701
},
702702
},
703+
{
704+
name: "child_flow_join_suspend",
705+
flowName: "JoinCallerFlow",
706+
source: map[string]string{
707+
"fetchchild.ds.go": `package main
708+
709+
import (
710+
"github.com/RainingComputers/deepslate/prelude"
711+
"time"
712+
)
713+
714+
func FetchChildSpec(url string) int {
715+
var result int = 0
716+
for {
717+
data, err := prelude.HttpRequest("GET", url, map[string]string{}, []byte{})
718+
_ = data
719+
_ = err
720+
result = 42
721+
if result == 42 {
722+
return result
723+
}
724+
prelude.Sleep(1 * time.Second)
725+
}
726+
}
727+
`,
728+
"joincaller.ds.go": `package main
729+
730+
func JoinCallerFlowSpec() {
731+
url := "http://localhost:18766/health"
732+
value := FetchChildSpec(url)
733+
_ = value
734+
}
735+
`,
736+
},
737+
steps: []workerTestStep{
738+
{
739+
sleep: 3 * time.Second,
740+
wantVars: map[string]any{
741+
"value": 42,
742+
},
743+
},
744+
},
745+
},
703746
{
704747
name: "select_default",
705748
flowName: "SelectDefaultFlow",

pkg/runtimes/dython/deepslate/isolate.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,8 @@ def done() -> bool:
122122
return done(), events
123123

124124
elif isinstance(instr, Exit):
125-
self._pc += 1
126-
return done(), None
125+
self._pc = len(self._instructions)
126+
return True, None
127127

128128
elif isinstance(instr, Jump):
129129
self._pc = instr.loc

pkg/runtimes/dython/deepslate/tests/test_isolate.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,6 @@
152152
want_events=0,
153153
want_vars={"__return__": 42},
154154
),
155-
IsolateTestStep(want_done=False, want_pc=2, want_events=0),
156155
IsolateTestStep(want_done=True, want_pc=3),
157156
],
158157
),

pkg/runtimes/dython/deepslate/tests/test_worker.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -721,6 +721,42 @@ async def select_second_parent_flow() -> None:
721721
],
722722
want_traces=[],
723723
),
724+
WorkerTestCase(
725+
name="child_flow_join_suspend",
726+
flow_name="join_caller",
727+
source={
728+
"suspend_child.py": """\
729+
from deepslate import flow, http_request, sleep, DSError
730+
731+
732+
@flow
733+
async def suspend_child(url: str) -> bytes:
734+
resp: bytes | DSError = b""
735+
while True:
736+
resp = http_request("GET", url, {}, b"")
737+
if isinstance(resp, bytes):
738+
return resp
739+
sleep(2.0)
740+
""",
741+
"join_caller.py": """\
742+
from deepslate import flow
743+
from .suspend_child import suspend_child
744+
745+
746+
@flow
747+
async def join_caller() -> None:
748+
url: str = "http://localhost:18769/health"
749+
raw: bytes = suspend_child(url)
750+
""",
751+
},
752+
steps=[
753+
WorkerTestStep(
754+
sleep=2.0,
755+
want_vars={"raw": b'{"Status": "healthy", "Code": 200}'},
756+
),
757+
],
758+
want_traces=[],
759+
),
724760
],
725761
ids=lambda t: t.name,
726762
)

0 commit comments

Comments
 (0)