Skip to content
This repository was archived by the owner on Feb 8, 2021. It is now read-only.

Commit 27f1e86

Browse files
committed
add test for exec signal
Signed-off-by: HaoZhang <crazykev@zju.edu.cn>
1 parent 101d650 commit 27f1e86

File tree

2 files changed

+50
-0
lines changed

2 files changed

+50
-0
lines changed

integration/client.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,21 @@ func (c *HyperClient) RemovePod(podID string) error {
351351
return nil
352352
}
353353

354+
// ContainerExecSignal sends signal to specified exec of specified container
355+
func (c *HyperClient) ContainerExecSignal(container, execID string, sig int64) error {
356+
req := types.ExecSignalRequest{
357+
ContainerID: container,
358+
ExecID: execID,
359+
Signal: sig,
360+
}
361+
_, err := c.client.ExecSignal(c.ctx, &req)
362+
if err != nil {
363+
return err
364+
}
365+
366+
return nil
367+
}
368+
354369
// ContainerExecCreate creates exec in a container
355370
func (c *HyperClient) ContainerExecCreate(container string, command []string, tty bool) (string, error) {
356371
req := types.ExecCreateRequest{

integration/hyper_test.go

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -529,3 +529,38 @@ func (s *TestSuite) TestSendContainerSignal(c *C) {
529529
c.Assert(err, IsNil)
530530
c.Assert(containerInfo.Status.Phase, Equals, "failed")
531531
}
532+
533+
func (s *TestSuite) TestSendExecSignal(c *C) {
534+
sigKill := int64(9)
535+
cName := "test-exec-signal"
536+
spec := types.UserPod{
537+
Id: "busybox",
538+
Containers: []*types.UserContainer{
539+
{
540+
Name: cName,
541+
Image: "busybox",
542+
},
543+
},
544+
}
545+
podID, err := s.client.CreatePod(&spec)
546+
c.Assert(err, IsNil)
547+
548+
defer func() {
549+
err = s.client.RemovePod(podID)
550+
c.Assert(err, IsNil)
551+
}()
552+
553+
err = s.client.StartPod(podID)
554+
c.Assert(err, IsNil)
555+
556+
execId, err := s.client.ContainerExecCreate(cName, []string{"sh", "-c", "top"}, false)
557+
c.Assert(err, IsNil)
558+
err = s.client.ContainerExecStart(cName, execId, nil, nil, nil, false)
559+
c.Assert(err, IsNil)
560+
err = s.client.ContainerExecSignal(cName, execId, sigKill)
561+
c.Assert(err, IsNil)
562+
563+
exitCode, err := s.client.Wait(cName, execId, false)
564+
c.Assert(err, IsNil)
565+
c.Assert(exitCode, Equals, int32(0))
566+
}

0 commit comments

Comments
 (0)