fix(process): make process.start non-detached by default
Co-Authored-By: Virgil <virgil@lethean.io>
This commit is contained in:
parent
c60f355b25
commit
8f359bb004
2 changed files with 23 additions and 6 deletions
|
|
@ -70,15 +70,10 @@ func (s *Service) handleStart(ctx context.Context, opts core.Options) core.Resul
|
|||
return core.Result{Value: core.E("process.start", "command is required", nil), OK: false}
|
||||
}
|
||||
|
||||
detach := true
|
||||
if opts.Has("detach") {
|
||||
detach = opts.Bool("detach")
|
||||
}
|
||||
|
||||
runOpts := RunOptions{
|
||||
Command: command,
|
||||
Dir: opts.String("dir"),
|
||||
Detach: detach,
|
||||
Detach: opts.Bool("detach"),
|
||||
}
|
||||
if r := opts.Get("args"); r.OK {
|
||||
runOpts.Args = optionStrings(r.Value)
|
||||
|
|
|
|||
|
|
@ -126,6 +126,28 @@ func TestService_HandleStart_Good(t *testing.T) {
|
|||
t.Fatal("process should honor detached=false context cancellation")
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("defaults to non-detached", func(t *testing.T) {
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
|
||||
start := c.Action("process.start").Run(ctx, framework.NewOptions(
|
||||
framework.Option{Key: "command", Value: "sleep"},
|
||||
framework.Option{Key: "args", Value: []string{"60"}},
|
||||
))
|
||||
require.True(t, start.OK)
|
||||
|
||||
id := start.Value.(string)
|
||||
proc, err := svc.Get(id)
|
||||
require.NoError(t, err)
|
||||
|
||||
cancel()
|
||||
|
||||
select {
|
||||
case <-proc.Done():
|
||||
case <-time.After(2 * time.Second):
|
||||
t.Fatal("process should honor context cancellation by default")
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func TestService_HandleStart_Bad(t *testing.T) {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue