From e3a51b229861cd6b9a8fbf41d1de5c75127cc9a2 Mon Sep 17 00:00:00 2001 From: wine93 Date: Sun, 13 Sep 2026 15:57:38 +0800 Subject: [PATCH] [fix][fs]: fix daemonzie --- cli/command/cache/start.go | 13 ++++--------- cli/command/cache/start_test.go | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 9 deletions(-) create mode 100644 cli/command/cache/start_test.go diff --git a/cli/command/cache/start.go b/cli/command/cache/start.go index b0154c9..5cf33b4 100644 --- a/cli/command/cache/start.go +++ b/cli/command/cache/start.go @@ -21,7 +21,6 @@ import ( "os" "os/exec" "path/filepath" - "time" "github.com/dingodb/dingocli/cli/cli" compmgr "github.com/dingodb/dingocli/internal/component" @@ -121,17 +120,13 @@ func runStart(cmd *cobra.Command, dingocli *cli.DingoCli, options startOptions) return err } - // forground mode, wait process exit - if options.daemonize { - time.Sleep(2 * time.Second) - fmt.Println("Successfully start dingo-cache") - return nil - } - - // wait process complete + // In daemon mode the parent exits only after the node reports readiness. if err := oscmd.Wait(); err != nil { return err } + if options.daemonize { + fmt.Println("Successfully start dingo-cache") + } return nil } diff --git a/cli/command/cache/start_test.go b/cli/command/cache/start_test.go new file mode 100644 index 0000000..ffdeb25 --- /dev/null +++ b/cli/command/cache/start_test.go @@ -0,0 +1,33 @@ +package cache + +import ( + "os" + "os/exec" + "path/filepath" + "testing" +) + +func TestRunStartPropagatesDaemonFailure(t *testing.T) { + err := runStart(nil, nil, startOptions{ + cacheBinary: "/bin/sh", cmdArgs: []string{"-c", "exit 7"}, daemonize: true, + }) + exitError, ok := err.(*exec.ExitError) + if !ok || exitError.ExitCode() != 7 { + t.Fatalf("expected daemon exit code 7, got %v", err) + } +} + +func TestRunStartWaitsForDaemonReadiness(t *testing.T) { + marker := filepath.Join(t.TempDir(), "ready") + err := runStart(nil, nil, startOptions{ + cacheBinary: "/bin/sh", + cmdArgs: []string{"-c", `sleep 3; touch "$1"`, "daemon", marker}, + daemonize: true, + }) + if err != nil { + t.Fatal(err) + } + if _, err := os.Stat(marker); err != nil { + t.Fatalf("returned before daemon was ready: %v", err) + } +}