Ignore devstate when existing process name is not odo + delete devstate files with odo delete component (#7090)

* Ignore devstate when existing process name is not odo

* Delete orphan devstate files with odo delete component

* Update unit tests

* Create fake system

* Add unit tests for odo delete component

* Integration tests for odo dev

* Troubleshooting

* First process on Windows is 4

* Use go-ps lib for pidExists
This commit is contained in:
Philippe Martin
2023-09-20 14:20:53 +02:00
committed by GitHub
parent 1ab0178cef
commit 0f828ec99f
32 changed files with 1335 additions and 76 deletions

View File

@@ -133,6 +133,7 @@ type DevSessionOpts struct {
APIServerPort int
SyncGitDir bool
ShowLogs bool
VerboseLevel string
}
// StartDevMode starts a dev session with `odo dev`
@@ -174,6 +175,9 @@ func StartDevMode(options DevSessionOpts) (devSession DevSession, err error) {
if options.ShowLogs {
args = append(args, "--logs")
}
if options.VerboseLevel != "" {
args = append(args, "-v", options.VerboseLevel)
}
args = append(args, options.CmdlineArgs...)
cmd := Cmd("odo", args...)
cmd.Cmd.Stdin = c.Tty()
@@ -220,6 +224,10 @@ func (o DevSession) Kill() {
o.session.Kill()
}
func (o DevSession) PID() int {
return o.session.Command.Process.Pid
}
// Stop a Dev session cleanly (equivalent as hitting Ctrl-c)
func (o *DevSession) Stop() {
if o.session == nil {

View File

@@ -15,3 +15,7 @@ func terminateProc(session *gexec.Session) error {
}
func setSysProcAttr(command *exec.Cmd) {}
func GetFirstProcess() int {
return 1
}

View File

@@ -35,3 +35,7 @@ func setSysProcAttr(command *exec.Cmd) {
CreationFlags: syscall.CREATE_NEW_PROCESS_GROUP,
}
}
func GetFirstProcess() int {
return 4
}

View File

@@ -590,6 +590,36 @@ ComponentSettings:
})
})
When("killing odo dev and another process replaces it", func() {
var newDevSession helper.DevSession
BeforeEach(func() {
pid := devSession.PID()
devSession.Kill()
devSession.WaitEnd()
devstate := fmt.Sprintf(".odo/devstate.%d.json", pid)
newdevstate := fmt.Sprintf(".odo/devstate.%d.json", helper.GetFirstProcess())
helper.ReplaceString(
devstate,
fmt.Sprintf("\"pid\": %d", pid),
fmt.Sprintf("\"pid\": %d", helper.GetFirstProcess()))
err := os.Rename(devstate, newdevstate)
Expect(err).ToNot(HaveOccurred())
})
It("should restart a new session successfully", func() {
var err error
newDevSession, err = helper.StartDevMode(helper.DevSessionOpts{
VerboseLevel: "4",
})
Expect(err).ToNot(HaveOccurred())
logMsg := fmt.Sprintf("process %d exists but is not odo, ignoring", helper.GetFirstProcess())
Expect(newDevSession.ErrOut).Should(ContainSubstring(logMsg))
newDevSession.Stop()
newDevSession.WaitEnd()
})
})
When("stopping odo dev normally", func() {
BeforeEach(func() {
devSession.Stop()