Skip to content
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

Test: TestInstallRunRestartStopRemove failed. #30

Open
lgylgy opened this issue Aug 31, 2015 · 10 comments · May be fixed by #268
Open

Test: TestInstallRunRestartStopRemove failed. #30

lgylgy opened this issue Aug 31, 2015 · 10 comments · May be fixed by #268

Comments

@lgylgy
Copy link

lgylgy commented Aug 31, 2015

Hi,

I have a problem with the TestInstallRunRestartStopRemove test in service_test.go. The test systematically fails:

 [go] ok          github.com/kardianos/osext      0.140s
 [go] --- FAIL: TestInstallRunRestartStopRemove (0.04s)
 [go]     service_test.go:50: restart The requested control is not valid for this service.
 [go] FAIL
 [go] FAIL        github.com/kardianos/service    0.074s

When i add sleeps between Start/Restart/Stop signals, the test is successful.

    err = s.Start()
    if err != nil {
        t.Fatal("start", err)
    }
    time.Sleep(time.Second * 1)
    err = s.Restart()
    if err != nil {
        t.Fatal("restart", err)
    }
    time.Sleep(time.Second * 1)
    err = s.Stop()
    if err != nil {
        t.Fatal("stop", err)
    }
    time.Sleep(time.Second * 1)
    err = s.Uninstall()
    if err != nil {
        t.Fatal("stop", err)
    }

I think that signals do not have the time to be processed. Do you have any idea about this problem ?

Thanks

@kardianos
Copy link
Owner

What os/service?

On Mon, Aug 31, 2015, 03:58 Loïc Geffroy [email protected] wrote:

Hi,

I have a problem with the TestInstallRunRestartStopRemove test in
service_test.go. The test systematically fails:

[go] ok github.com/kardianos/osext 0.140s
[go] --- FAIL: TestInstallRunRestartStopRemove (0.04s)
[go] service_test.go:50: restart The requested control is not valid for this service.
[go] FAIL
[go] FAIL github.com/kardianos/service 0.074s

When i add sleeps between Start/Restart/Stop signals, the test is
successful.

err = s.Start()
if err != nil {
    t.Fatal("start", err)
}
time.Sleep(time.Second * 1)
err = s.Restart()
if err != nil {
    t.Fatal("restart", err)
}
time.Sleep(time.Second * 1)
err = s.Stop()
if err != nil {
    t.Fatal("stop", err)
}
time.Sleep(time.Second * 1)
err = s.Uninstall()
if err != nil {
    t.Fatal("stop", err)
}

Thanks


Reply to this email directly or view it on GitHub
#30.

@lgylgy
Copy link
Author

lgylgy commented Aug 31, 2015

On Windows 7

@kardianos
Copy link
Owner

@lgylgy I'll look into this issue. Part of what this test tests is quickly stopping and starting. I had thought I had fixed it. Could you send me the repo revision you are on?

@lgylgy
Copy link
Author

lgylgy commented Sep 1, 2015

I'm on the last revision 06ebab1.

@kardianos
Copy link
Owner

Hmm. I can't reproduce this trouble on my win7 amd64. My pause to adding sleeps in the test is I would prefer to fix the windows stop and start logic.

I've updated the tests to print out the stop timeout time, could you update and run test, then post what the timeout says for your system? Also, are you running 32-bit or 64-bit?

@ChrisHines
Copy link

I get the same failure that @lgylgy reports.

Windows 7, amd64.

Running the updated test:

=== RUN TestTimeout
--- PASS: TestTimeout (0.00s)
        service_windows_test.go:13: Max Stop Duration 12s

@kardianos
Copy link
Owner

@ChrisHines @lgylgy
What happens if you put in a time.Sleep(100 * time.Millisecond) here:
https://github.com/kardianos/service/blob/master/service_windows.go#L354 (right before the return)

@ChrisHines
Copy link

C:\gopath\src\github.com\kardianos\service>git describe --always
5ab7ce2

C:\gopath\src\github.com\kardianos\service>git diff
diff --git a/service_windows.go b/service_windows.go
index f081dd0..bcd9024 100644
--- a/service_windows.go
+++ b/service_windows.go
@@ -352,6 +352,7 @@ func (ws *windowsService) stopWait(s *mgr.Service) error {
                        break
                }
        }
+       time.Sleep(100 * time.Millisecond)
        return nil
 }

C:\gopath\src\github.com\kardianos\service>go test -v
=== RUN TestPlatformName
--- PASS: TestPlatformName (0.00s)
        name_test.go:12: Platform is windows-service
=== RUN TestTimeout
--- PASS: TestTimeout (0.00s)
        service_windows_test.go:13: Max Stop Duration 12s
=== RUN TestInstallRunRestartStopRemove
--- FAIL: TestInstallRunRestartStopRemove (0.04s)
        service_test.go:50: restart The requested control is not valid for this service.
FAIL
exit status 1
FAIL    github.com/kardianos/service    0.099s

Also, the test service is not fully deleted after this. Running it a second time I get:

C:\gopath\src\github.com\kardianos\service>go test
--- FAIL: TestInstallRunRestartStopRemove (0.00s)
        service_test.go:40: install service go_service_test already exists
FAIL
exit status 1
FAIL    github.com/kardianos/service    0.049s

C:\gopath\src\github.com\kardianos\service>sc delete go_service_test
[SC] DeleteService FAILED 1072:

The specified service has been marked for deletion.

I have to reboot to get the service deleted, so testing this repeatedly is a pain.

Update: The service couldn't be deleted because it was still running. After manually stopping the service Windows finalized the deletion.

@kardianos
Copy link
Owner

@ChrisHines Agree testing on windows is a pain. Sometimes it deletes if fully, sometimes not. I'll look at it more later.Thanks for that test.

@ChrisHines
Copy link

@kardianos No worries. Manually stopping the service avoids the reboot. And thanks for the great package, I am happy to help make it better.

@djdv djdv linked a pull request Apr 24, 2021 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants