• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

trento-project / agent / 12777046822

14 Jan 2025 09:44PM UTC coverage: 71.801%. First build
12777046822

Pull #376

github

balanza
handle context cancellation
Pull Request #376: Handle context cancellation in `corosync-cmapctl` gatherer

26 of 46 new or added lines in 3 files covered. (56.52%)

4074 of 5674 relevant lines covered (71.8%)

20.53 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/pkg/utils/commandexecutor.go
1
package utils
2

3
import (
4
        "context"
5
        "os/exec"
6
        "syscall"
7

8
        log "github.com/sirupsen/logrus"
9
)
10

11
//go:generate mockery --name=CommandExecutor
12

13
type CommandExecutor interface {
14
        Exec(name string, arg ...string) ([]byte, error)
15
        ExecContext(ctx context.Context, name string, arg ...string) ([]byte, error)
16
}
17

18
type Executor struct{}
19

20
func (e Executor) Exec(name string, arg ...string) ([]byte, error) {
×
21
        cmd := exec.Command(name, arg...)
×
NEW
22

×
NEW
23
        return cmd.Output()
×
NEW
24
}
×
25

NEW
26
func (e Executor) ExecContext(ctx context.Context, name string, arg ...string) ([]byte, error) {
×
NEW
27
        cmd := exec.Command(name, arg...)
×
NEW
28
        cmd.SysProcAttr = &syscall.SysProcAttr{Setpgid: true}
×
NEW
29

×
NEW
30
        go func() {
×
NEW
31
                <-ctx.Done()
×
NEW
32
                err := syscall.Kill(-cmd.Process.Pid, syscall.SIGKILL)
×
NEW
33
                if err != nil {
×
NEW
34
                        log.Errorf("Error killing process group: %v", err)
×
NEW
35
                }
×
36
        }()
37

38
        return cmd.Output()
×
39
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc