ProcessKillRunnableTest
Tags:elm-unspecced
`Process.kill` stops a process that is waiting in the scheduler's queue to run, not only one
waiting on a task.
The parent spawns a child, kills it, and does the same with a second child:
- `queuedChild` runs to completion before the parent's kill, because spawning makes the
parent yield, so "survived queued" is logged (a control);
- `runnableChild` starts with `Process.spawn` itself, so it yields too and is queued to run
again when the parent kills it, and "survived runnable" must never be logged.
The parent then sleeps for 50 ms and logs "done".
Tagged `elm-unspecced`: whether `survived queued` is logged, and `survived runnable` is not,
depends on how processes interleave after `Process.spawn`, which A Standard Definition of Elm?
leaves open (ruling A78). The test records what Elm 0.19.1 does.Results
elm-0.19.1
passran in 124 msOutput
Compiled in DEV mode. Follow the advice at https://elm-lang.org/0.19.1/optimize for better performance and smaller assets. kill: "survived queued" kill: "done"
elm-0.19.2
passran in 131 msOutput
Compiled in DEV mode. Follow the advice at https://elm-lang.org/0.19.2/optimize for better performance and smaller assets. kill: "survived queued" kill: "done"
elm-0.19.3
passran in 100 msOutput
Compiled in DEV mode. Follow the advice at https://elm-lang.org/0.19.3/optimize for better performance and smaller assets. kill: "survived queued" kill: "done"
lamdera-1.5.0
passran in 147 msOutput
kill: "survived queued" kill: "done"
Discussions
Discuss this test·Search the discussions on GitHub
Discussions are on GitHub; one about this test has [t:elm-core/ProcessKillRunnableTest] in its title.
Source
The -- CHECK: lines give the expected output.
module ProcessKillRunnableTest exposing (main)
{-| `Process.kill` stops a process that is waiting in the scheduler's queue to run, not only one
waiting on a task.
The parent spawns a child, kills it, and does the same with a second child:
- `queuedChild` runs to completion before the parent's kill, because spawning makes the
parent yield, so "survived queued" is logged (a control);
- `runnableChild` starts with `Process.spawn` itself, so it yields too and is queued to run
again when the parent kills it, and "survived runnable" must never be logged.
The parent then sleeps for 50 ms and logs "done".
Tagged `elm-unspecced`: whether `survived queued` is logged, and `survived runnable` is not,
depends on how processes interleave after `Process.spawn`, which A Standard Definition of Elm?
leaves open (ruling A78). The test records what Elm 0.19.1 does.
-}
-- TAGS: elm-unspecced
-- MODE-GUARD: a Char equality must give the same answer as under --optimize
-- NO-SKIP: an edge case every compiler must run
-- CHECK: kill: "survived queued"
-- CHECK: kill: "done"
-- CHECK-NOT: survived runnable
import Process
import Task
survive : String -> Task.Task Never ()
survive tag =
let
_ =
Debug.log "kill" ("survived " ++ tag)
in
Task.succeed ()
queuedChild : Task.Task Never ()
queuedChild =
Task.succeed () |> Task.andThen (\_ -> survive "queued")
runnableChild : Task.Task Never ()
runnableChild =
Process.spawn (Task.succeed ()) |> Task.andThen (\_ -> survive "runnable")
spawnAndKill : Task.Task Never () -> Task.Task Never ()
spawnAndKill child =
Process.spawn child |> Task.andThen Process.kill
main : Program () () ()
main =
Platform.worker
{ init =
\_ ->
( ()
, spawnAndKill queuedChild
|> Task.andThen (\_ -> spawnAndKill runnableChild)
|> Task.andThen (\_ -> Process.sleep 50)
|> Task.perform (\_ -> ())
)
, update =
\_ model ->
let
_ =
Debug.log "kill" "done"
in
( model, Cmd.none )
, subscriptions = \_ -> Sub.none
}