mirror of https://github.com/dapr/cli.git
CLI run should detect that either daprd or the app has exited and clean up
This commit is contained in:
parent
324fa5bc57
commit
328a6f99f1
37
cmd/run.go
37
cmd/run.go
|
@ -111,6 +111,18 @@ var RunCmd = &cobra.Command{
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
go func() {
|
||||||
|
daprdErr := output.DaprCMD.Wait()
|
||||||
|
|
||||||
|
if daprdErr != nil {
|
||||||
|
print.FailureStatusEvent(os.Stdout, "The daprd process exited with error code: %s", daprdErr.Error())
|
||||||
|
|
||||||
|
} else {
|
||||||
|
print.SuccessStatusEvent(os.Stdout, "Exited Dapr successfully")
|
||||||
|
}
|
||||||
|
sigCh <- os.Interrupt
|
||||||
|
}()
|
||||||
|
|
||||||
if appPort <= 0 {
|
if appPort <= 0 {
|
||||||
// If app does not listen to port, we can check for Dapr's sidecar health before starting the app.
|
// If app does not listen to port, we can check for Dapr's sidecar health before starting the app.
|
||||||
// Otherwise, it creates a deadlock.
|
// Otherwise, it creates a deadlock.
|
||||||
|
@ -182,6 +194,17 @@ var RunCmd = &cobra.Command{
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
go func() {
|
||||||
|
appErr := output.AppCMD.Wait()
|
||||||
|
|
||||||
|
if appErr != nil {
|
||||||
|
print.FailureStatusEvent(os.Stdout, "The App process exited with error code: %s", appErr.Error())
|
||||||
|
} else {
|
||||||
|
print.SuccessStatusEvent(os.Stdout, "Exited App successfully")
|
||||||
|
}
|
||||||
|
sigCh <- os.Interrupt
|
||||||
|
}()
|
||||||
|
|
||||||
appRunning <- true
|
appRunning <- true
|
||||||
}()
|
}()
|
||||||
|
|
||||||
|
@ -219,14 +242,16 @@ var RunCmd = &cobra.Command{
|
||||||
<-sigCh
|
<-sigCh
|
||||||
print.InfoStatusEvent(os.Stdout, "\nterminated signal received: shutting down")
|
print.InfoStatusEvent(os.Stdout, "\nterminated signal received: shutting down")
|
||||||
|
|
||||||
err = output.DaprCMD.Process.Kill()
|
if output.DaprCMD.ProcessState == nil || !output.DaprCMD.ProcessState.Exited() {
|
||||||
if err != nil {
|
err = output.DaprCMD.Process.Kill()
|
||||||
print.FailureStatusEvent(os.Stdout, fmt.Sprintf("Error exiting Dapr: %s", err))
|
if err != nil {
|
||||||
} else {
|
print.FailureStatusEvent(os.Stdout, fmt.Sprintf("Error exiting Dapr: %s", err))
|
||||||
print.SuccessStatusEvent(os.Stdout, "Exited Dapr successfully")
|
} else {
|
||||||
|
print.SuccessStatusEvent(os.Stdout, "Exited Dapr successfully")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if output.AppCMD != nil {
|
if output.AppCMD != nil && (output.AppCMD.ProcessState == nil || !output.AppCMD.ProcessState.Exited()) {
|
||||||
err = output.AppCMD.Process.Kill()
|
err = output.AppCMD.Process.Kill()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
print.FailureStatusEvent(os.Stdout, fmt.Sprintf("Error exiting App: %s", err))
|
print.FailureStatusEvent(os.Stdout, fmt.Sprintf("Error exiting App: %s", err))
|
||||||
|
|
|
@ -41,6 +41,7 @@ func TestStandaloneInstall(t *testing.T) {
|
||||||
phase func(*testing.T)
|
phase func(*testing.T)
|
||||||
}{
|
}{
|
||||||
{"test install", testInstall},
|
{"test install", testInstall},
|
||||||
|
{"test run", testRun},
|
||||||
{"test uninstall", testUninstall},
|
{"test uninstall", testUninstall},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -269,3 +270,28 @@ func testInstall(t *testing.T) {
|
||||||
|
|
||||||
assert.Empty(t, configs)
|
assert.Empty(t, configs)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func testRun(t *testing.T) {
|
||||||
|
daprPath := getDaprPath()
|
||||||
|
|
||||||
|
output, err := spawn.Command(daprPath, "run", "--", "bash", "-c", "echo test")
|
||||||
|
t.Log(output)
|
||||||
|
require.NoError(t, err, "run failed")
|
||||||
|
assert.Contains(t, output, "Exited App successfully")
|
||||||
|
assert.Contains(t, output, "Exited Dapr successfully")
|
||||||
|
|
||||||
|
output, err = spawn.Command(daprPath, "run", "--", "bash", "-c", "exit 1")
|
||||||
|
t.Log(output)
|
||||||
|
require.NoError(t, err, "run failed")
|
||||||
|
assert.Contains(t, output, "The App process exited with error code: exit status 1")
|
||||||
|
assert.Contains(t, output, "Exited Dapr successfully")
|
||||||
|
|
||||||
|
|
||||||
|
// Test that the CLI exits on a daprd shutdown.
|
||||||
|
output, err = spawn.Command(daprPath, "run", "--dapr-http-port", "9999", "--", "bash", "-c", "curl -v http://localhost:9999/v1.0/shutdown; sleep 10; exit 1")
|
||||||
|
t.Log(output)
|
||||||
|
require.NoError(t, err, "run failed")
|
||||||
|
assert.Contains(t, output, "Exited App successfully", "App should be shutdown before it has a chance to return non-zero")
|
||||||
|
assert.Contains(t, output, "Exited Dapr successfully")
|
||||||
|
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue