service/rpccommon: halt before detach in Stop (#2677)
* service/rpccommon: halt before detach in Stop * Addd IsRunning check Co-authored-by: Polina Sokolova <polinasok@users.noreply.github.com>
This commit is contained in:
parent
45f44bc218
commit
5d158820f6
@ -254,7 +254,7 @@ func TestContinue(t *testing.T) {
|
|||||||
cmd := exec.Command(dlvbin, "debug", "--headless", "--continue", "--accept-multiclient", "--listen", listenAddr)
|
cmd := exec.Command(dlvbin, "debug", "--headless", "--continue", "--accept-multiclient", "--listen", listenAddr)
|
||||||
cmd.Dir = buildtestdir
|
cmd.Dir = buildtestdir
|
||||||
stdout, err := cmd.StdoutPipe()
|
stdout, err := cmd.StdoutPipe()
|
||||||
assertNoError(err, t, "stderr pipe")
|
assertNoError(err, t, "stdout pipe")
|
||||||
defer stdout.Close()
|
defer stdout.Close()
|
||||||
|
|
||||||
assertNoError(cmd.Start(), t, "start headless instance")
|
assertNoError(cmd.Start(), t, "start headless instance")
|
||||||
@ -299,7 +299,7 @@ func TestChildProcessExitWhenNoDebugInfo(t *testing.T) {
|
|||||||
// search the running process named fix.Name
|
// search the running process named fix.Name
|
||||||
cmd := exec.Command("ps", "-aux")
|
cmd := exec.Command("ps", "-aux")
|
||||||
stdout, err := cmd.StdoutPipe()
|
stdout, err := cmd.StdoutPipe()
|
||||||
assertNoError(err, t, "stderr pipe")
|
assertNoError(err, t, "stdout pipe")
|
||||||
defer stdout.Close()
|
defer stdout.Close()
|
||||||
|
|
||||||
assertNoError(cmd.Start(), t, "start `ps -aux`")
|
assertNoError(cmd.Start(), t, "start `ps -aux`")
|
||||||
@ -330,7 +330,7 @@ func TestRedirect(t *testing.T) {
|
|||||||
catfixture := filepath.Join(protest.FindFixturesDir(), "cat.go")
|
catfixture := filepath.Join(protest.FindFixturesDir(), "cat.go")
|
||||||
cmd := exec.Command(dlvbin, "debug", "--headless", "--continue", "--accept-multiclient", "--listen", listenAddr, "-r", catfixture, catfixture)
|
cmd := exec.Command(dlvbin, "debug", "--headless", "--continue", "--accept-multiclient", "--listen", listenAddr, "-r", catfixture, catfixture)
|
||||||
stdout, err := cmd.StdoutPipe()
|
stdout, err := cmd.StdoutPipe()
|
||||||
assertNoError(err, t, "stderr pipe")
|
assertNoError(err, t, "stdout pipe")
|
||||||
defer stdout.Close()
|
defer stdout.Close()
|
||||||
|
|
||||||
assertNoError(cmd.Start(), t, "start headless instance")
|
assertNoError(cmd.Start(), t, "start headless instance")
|
||||||
|
|||||||
@ -90,10 +90,14 @@ func NewServer(config *service.Config) *ServerImpl {
|
|||||||
|
|
||||||
// Stop stops the JSON-RPC server.
|
// Stop stops the JSON-RPC server.
|
||||||
func (s *ServerImpl) Stop() error {
|
func (s *ServerImpl) Stop() error {
|
||||||
|
s.log.Debug("stopping")
|
||||||
close(s.stopChan)
|
close(s.stopChan)
|
||||||
if s.config.AcceptMulti {
|
if s.config.AcceptMulti {
|
||||||
s.listener.Close()
|
s.listener.Close()
|
||||||
}
|
}
|
||||||
|
if s.debugger.IsRunning() {
|
||||||
|
s.debugger.Command(&api.DebuggerCommand{Name: api.Halt}, nil)
|
||||||
|
}
|
||||||
kill := s.config.Debugger.AttachPid == 0
|
kill := s.config.Debugger.AttachPid == 0
|
||||||
return s.debugger.Detach(kill)
|
return s.debugger.Detach(kill)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1892,6 +1892,39 @@ func TestAcceptMulticlient(t *testing.T) {
|
|||||||
<-serverDone
|
<-serverDone
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestForceStopWhileContinue(t *testing.T) {
|
||||||
|
listener, err := net.Listen("tcp", "127.0.0.1:0")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("couldn't start listener: %s\n", err)
|
||||||
|
}
|
||||||
|
serverStopped := make(chan struct{})
|
||||||
|
disconnectChan := make(chan struct{})
|
||||||
|
go func() {
|
||||||
|
defer close(serverStopped)
|
||||||
|
defer listener.Close()
|
||||||
|
server := rpccommon.NewServer(&service.Config{
|
||||||
|
Listener: listener,
|
||||||
|
ProcessArgs: []string{protest.BuildFixture("http_server", protest.AllNonOptimized).Path},
|
||||||
|
AcceptMulti: true,
|
||||||
|
DisconnectChan: disconnectChan,
|
||||||
|
Debugger: debugger.Config{
|
||||||
|
Backend: "default",
|
||||||
|
},
|
||||||
|
})
|
||||||
|
if err := server.Run(); err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
<-disconnectChan
|
||||||
|
server.Stop()
|
||||||
|
}()
|
||||||
|
|
||||||
|
client := rpc2.NewClient(listener.Addr().String())
|
||||||
|
client.Disconnect(true /*continue*/)
|
||||||
|
time.Sleep(10 * time.Millisecond) // give server time to start running
|
||||||
|
close(disconnectChan) // stop the server
|
||||||
|
<-serverStopped // Stop() didn't block on detach because we halted first
|
||||||
|
}
|
||||||
|
|
||||||
func TestClientServerFunctionCall(t *testing.T) {
|
func TestClientServerFunctionCall(t *testing.T) {
|
||||||
protest.MustSupportFunctionCalls(t, testBackend)
|
protest.MustSupportFunctionCalls(t, testBackend)
|
||||||
withTestClient2("fncall", t, func(c service.Client) {
|
withTestClient2("fncall", t, func(c service.Client) {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user