Skip to content

Commit

Permalink
Tweak tests
Browse files Browse the repository at this point in the history
  • Loading branch information
croqaz committed Mar 29, 2024
1 parent a81537d commit 3616003
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 53 deletions.
89 changes: 44 additions & 45 deletions cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,33 +10,33 @@
//
// A basic example that runs env and prints its output:
//
// import (
// "fmt"
// cmd "https://github.com/ShinyTrinkets/overseer"
// )
// import (
// "fmt"
// cmd "https://github.com/ShinyTrinkets/overseer"
// )
//
// func main() {
// // Create a Cmd
// envCmd := cmd.NewCmd("env")
// func main() {
// // Create a Cmd
// envCmd := cmd.NewCmd("env")
//
// // Run and wait for Cmd to return Status
// status := <-envCmd.Start()
// // Run and wait for Cmd to return Status
// status := <-envCmd.Start()
//
// // Print each line of STDOUT from Cmd
// for _, line := range status.Stdout {
// fmt.Println(line)
// }
// }
// // Print each line of STDOUT from Cmd
// for _, line := range status.Stdout {
// fmt.Println(line)
// }
// }
//
// Commands can be ran synchronously (blocking) or asynchronously (non-blocking):
//
// envCmd := cmd.NewCmd("env") // create
// envCmd := cmd.NewCmd("env") // create
//
// status := <-envCmd.Start() // run blocking
// status := <-envCmd.Start() // run blocking
//
// statusChan := envCmd.Start() // run non-blocking
// // Do other work while Cmd is running...
// status <- statusChan // blocking
// statusChan := envCmd.Start() // run non-blocking
// // Do other work while Cmd is running...
// status <- statusChan // blocking
//
// Start returns a channel to which the final Status is sent when the command
// finishes for any reason. The first example blocks receiving on the channel.
Expand Down Expand Up @@ -93,8 +93,8 @@ type Cmd struct {
// for any reason, this combination of values indicates success (presuming the
// command only exits zero on success):
//
// Exit = 0
// Error = nil
// Exit = 0
// Error = nil
//
// Error is a Go error from the underlying os/exec.Cmd.Start or os/exec.Cmd.Wait.
// If not nil, the command either failed to start (it never ran) or it started
Expand Down Expand Up @@ -281,13 +281,13 @@ func (c *Cmd) getRetryTimes() uint {
// can use to receive the final Status of the command when it ends. The caller
// can start the command and wait like,
//
// status := <-myCmd.Start() // blocking
// status := <-myCmd.Start() // blocking
//
// or start the command asynchronously and be notified later when it ends,
//
// statusChan := myCmd.Start() // non-blocking
// // Do other work while Cmd is running...
// status := <-statusChan // blocking
// statusChan := myCmd.Start() // non-blocking
// // Do other work while Cmd is running...
// status := <-statusChan // blocking
//
// Exactly one Status is sent on the channel when the command ends. The channel
// is not closed. Any Go error is set to Status.Error. Start is idempotent; it
Expand Down Expand Up @@ -357,9 +357,9 @@ func (c *Cmd) Signal(sig syscall.Signal) error {
// as of the Status call time. For example, if the command counts to 3 and three
// calls are made between counts, Status.Stdout contains:
//
// "1"
// "1 2"
// "1 2 3"
// "1"
// "1 2"
// "1 2 3"
//
// The caller is responsible for tailing the buffered output if needed. Else,
// consider using streaming output. When the command finishes, buffered output
Expand Down Expand Up @@ -550,11 +550,11 @@ func (c *Cmd) run() {
// default when created by calling NewCmd. To use OutputBuffer directly with
// a Go standard library os/exec.Command:
//
// import "os/exec"
// import cmd "github.com/ShinyTrinkets/overseer"
// runnableCmd := exec.Command(...)
// stdout := cmd.NewOutputBuffer()
// runnableCmd.Stdout = stdout
// import "os/exec"
// import cmd "github.com/ShinyTrinkets/overseer"
// runnableCmd := exec.Command(...)
// stdout := cmd.NewOutputBuffer()
// runnableCmd.Stdout = stdout
//
// While runnableCmd is running, call stdout.Lines() to read all output
// currently written.
Expand Down Expand Up @@ -642,20 +642,19 @@ func (e ErrLineBufferOverflow) Error() string {
// created by calling NewCmdOptions and Options.Streaming is true. To use
// OutputStream directly with a Go standard library os/exec.Command:
//
// import "os/exec"
// import cmd "github.com/ShinyTrinkets/overseer"
// import "os/exec"
// import cmd "github.com/ShinyTrinkets/overseer"
//
// stdoutChan := make(chan string, 100)
// go func() {
// for line := range stdoutChan {
// // Do something with the line
// }
// }()
//
// runnableCmd := exec.Command(...)
// stdout := cmd.NewOutputStream(stdoutChan)
// runnableCmd.Stdout = stdout
// stdoutChan := make(chan string, 100)
// go func() {
// for line := range stdoutChan {
// // Do something with the line
// }
// }()
//
// runnableCmd := exec.Command(...)
// stdout := cmd.NewOutputStream(stdoutChan)
// runnableCmd.Stdout = stdout
//
// While runnableCmd is running, lines are sent to the channel as soon as they
// are written and newline-terminated by the command.
Expand Down
26 changes: 18 additions & 8 deletions manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -895,9 +895,12 @@ func TestOverseerProcsStreaming(t *testing.T) {
// The purpose of this test is to check if all
// overseer processes stop after all
// managed procs have stopped
assert := assert.New(t)
if runtime.GOOS != "linux" {
t.Skip("This test is only supported on Linux.")
}

// assert.Equal(0, len(getOverseerProcs()), "Overseer procs exist from other tests. There may be a bug.")
assert := assert.New(t)
assert.Equal(0, len(getOverseerProcs()), "Overseer procs exist from other tests. There may be a bug.")

opts := cmd.Options{
Group: "A", Dir: "/",
Expand Down Expand Up @@ -934,9 +937,12 @@ func TestOverseerProcsBuffered(t *testing.T) {
// The purpose of this test is to check if all
// overseer processes stop after all
// managed procs have stopped
assert := assert.New(t)
if runtime.GOOS != "linux" {
t.Skip("This test is only supported on Linux.")
}

// assert.Equal(0, len(getOverseerProcs()), "Overseer procs exist from other tests. There may be a bug.")
assert := assert.New(t)
assert.Equal(0, len(getOverseerProcs()), "Overseer procs exist from other tests. There may be a bug.")

opts := cmd.Options{
Group: "A", Dir: "/",
Expand Down Expand Up @@ -974,9 +980,12 @@ func TestOverseerProcsManyInstancesNoOutput(t *testing.T) {
// overseer processes stop after all managed procs
// have stopped when no output is selected
// and when multiple instances of overseer exist
assert := assert.New(t)
if runtime.GOOS != "linux" {
t.Skip("This test is only supported on Linux.")
}

// assert.Equal(0, len(getOverseerProcs()), "Overseer procs exist from other tests. There may be a bug.")
assert := assert.New(t)
assert.Equal(0, len(getOverseerProcs()), "Overseer procs exist from other tests. There may be a bug.")

opts := cmd.Options{
Group: "A", Dir: "/",
Expand Down Expand Up @@ -1032,10 +1041,11 @@ func TestOverseerSystemSIGINT(t *testing.T) {
// The purpose of this test is to ensure
// SIGINT is handled properly and all
// overseer procs are stopped gracefully
if runtime.GOOS != "linux" {
t.Skip("This test is only supported on Linux.")
}
assert := assert.New(t)

// assert.Equal(0, len(getOverseerProcs()), "Overseer procs exist from other tests. There may be a bug.")

opts := cmd.Options{
Group: "A", Dir: "/",
Buffered: false, Streaming: true,
Expand Down

0 comments on commit 3616003

Please sign in to comment.