diff --git a/tests/ociswrapper/ocis/ocis.go b/tests/ociswrapper/ocis/ocis.go index 06967395a5c..8ca3e1d7824 100644 --- a/tests/ociswrapper/ocis/ocis.go +++ b/tests/ociswrapper/ocis/ocis.go @@ -29,7 +29,7 @@ var EnvConfigs = []string{} var runningServices = make(map[string]int) func Start(envMap []string) { - StartService("", envMap) + StartService("", envMap) } func Stop() (bool, string) { @@ -57,10 +57,16 @@ func Restart(envMap []string) (bool, string) { } func IsOcisRunning() bool { - if runningServices["ocis"] > 0 { - return true - } - return false + if runningServices["ocis"] == 0 { + return false + } + + _, err := os.FindProcess(runningServices["ocis"]) + if err != nil { + delete(runningServices, "ocis") + return false + } + return true } func waitAllServices(startTime time.Time, timeout time.Duration) { @@ -239,7 +245,7 @@ func StartService(service string, envMap []string) { } for listservice, pid := range runningServices { - log.Println(fmt.Sprintf("Service started: %s with process and id: %v\n", listservice, pid)) + log.Println(fmt.Sprintf("Service started: %s with process and id: %v\n", listservice, pid)) } // Read the logs when the 'ocis server' command is running @@ -308,15 +314,11 @@ func StopService(service string) (bool, string) { pKillError := process.Signal(syscall.SIGINT) if pKillError != nil { return false, fmt.Sprintf("Failed to stop service with process id %d", pid) - } + } else { + delete(runningServices, service) - _, waitErr := process.Wait() - if waitErr != nil { - return false, fmt.Sprintf("Error waiting for process to exit: %v\n", waitErr) - } - delete(runningServices, service) + log.Println(fmt.Sprintf("oCIS service %s has been stopped successfully", service)) + } - // service takes 30s time to sync - time.Sleep(30 * time.Second) return true, fmt.Sprintf("Service %s stopped successfully", service) }