-
Notifications
You must be signed in to change notification settings - Fork 77
fix: improve rollapp start handling #1430
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| package start | ||
|
|
||
| import ( | ||
| "context" | ||
| "errors" | ||
| "os/exec" | ||
| "testing" | ||
| "time" | ||
|
|
||
| "github.com/dymensionxyz/roller/utils/bash" | ||
| ) | ||
|
|
||
| func TestRunRollappCommandSuccess(t *testing.T) { | ||
| t.Cleanup(func() { execCmdFollowFunc = bashExecCmdFollowWrapper }) | ||
| execCmdFollowFunc = func(done chan<- error, ctx context.Context, cmd *exec.Cmd, _ map[string]string) error { | ||
| done <- nil | ||
| return nil | ||
| } | ||
|
Comment on lines
+15
to
+18
|
||
|
|
||
| ctx, cancel := context.WithTimeout(context.Background(), time.Second) | ||
| defer cancel() | ||
|
|
||
| if err := runRollappCommand(ctx, exec.Command("echo"), nil); err != nil { | ||
| t.Fatalf("expected no error, got %v", err) | ||
| } | ||
|
Comment on lines
+20
to
+25
|
||
| } | ||
|
|
||
| func TestRunRollappCommandReturnsProcessError(t *testing.T) { | ||
| t.Cleanup(func() { execCmdFollowFunc = bashExecCmdFollowWrapper }) | ||
| execCmdFollowFunc = func(done chan<- error, ctx context.Context, cmd *exec.Cmd, _ map[string]string) error { | ||
| return errors.New("boom") | ||
| } | ||
|
|
||
| ctx, cancel := context.WithTimeout(context.Background(), time.Second) | ||
| defer cancel() | ||
|
|
||
| err := runRollappCommand(ctx, exec.Command("echo"), nil) | ||
| if err == nil { | ||
| t.Fatalf("expected error, got nil") | ||
| } | ||
|
Comment on lines
+37
to
+40
|
||
| } | ||
|
|
||
| func TestRunRollappCommandSignals(t *testing.T) { | ||
| t.Cleanup(func() { execCmdFollowFunc = bashExecCmdFollowWrapper }) | ||
| execCmdFollowFunc = func(done chan<- error, ctx context.Context, cmd *exec.Cmd, _ map[string]string) error { | ||
| done <- errors.New("SIGTERM") | ||
| return nil | ||
| } | ||
|
|
||
| ctx, cancel := context.WithTimeout(context.Background(), time.Second) | ||
| defer cancel() | ||
|
|
||
| if err := runRollappCommand(ctx, exec.Command("echo"), nil); err == nil { | ||
| t.Fatalf("expected signal error") | ||
| } | ||
|
Comment on lines
+46
to
+55
|
||
| } | ||
|
|
||
| func TestRunRollappCommandContextCancelled(t *testing.T) { | ||
| t.Cleanup(func() { execCmdFollowFunc = bashExecCmdFollowWrapper }) | ||
| execCmdFollowFunc = func(done chan<- error, ctx context.Context, cmd *exec.Cmd, _ map[string]string) error { | ||
| select { | ||
| case <-ctx.Done(): | ||
| return ctx.Err() | ||
| } | ||
| } | ||
|
|
||
| ctx, cancel := context.WithCancel(context.Background()) | ||
| cancel() | ||
|
|
||
| if err := runRollappCommand(ctx, exec.Command("echo"), nil); err == nil { | ||
| t.Fatalf("expected context error") | ||
| } | ||
| } | ||
|
|
||
| func bashExecCmdFollowWrapper(done chan<- error, ctx context.Context, cmd *exec.Cmd, prompts map[string]string) error { | ||
| return bash.ExecCmdFollow(done, ctx, cmd, prompts) | ||
| } | ||
|
Comment on lines
+59
to
+77
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Logic error in channel handling: The function receives from signalChan (which is the done channel passed to execCmdFollowFunc) and execDone (which receives the return value from execCmdFollowFunc). However, when a signal is received, bash.ExecCmdFollow sends to signalChan and may still return an error. The current select will only read one value, potentially missing errors. Additionally, if signalChan receives nil (successful signal handling), the function returns nil without waiting for the execCmdFollowFunc to complete, which could lead to resource leaks.