Update flaky test and improve documentation.

This relates to #3
This commit is contained in:
IamTheFij 2024-11-22 12:07:48 -08:00
parent 0adf15dc3f
commit 53ae699acd
2 changed files with 8 additions and 4 deletions

View File

@ -89,12 +89,16 @@ func (sr *ShellRunner) Start() {
// AddCommand adds a shell command to be executed with an optional callback.
// No commands can be added if the runner has been stopped or not yet started.
// The callback is executed asynchronously after the command has completed.
// The order of command execution and callback invocation can be expected to be preserved.
// The order of command execution and callback invocation can be expected to be preserved (maybe?).
func (sr *ShellRunner) AddCommand(command string, callback func(*CommandResult)) error {
cmd, cancel := sr.newShellCommand(command)
return sr.AddCmd(cmd, callback, cancel)
}
// AddCmd adds a pre-configured exec.Cmd to be executed with an optional callback and cancel function.
// No commands can be added if the runner has been stopped or not yet started.
// The callback is executed asynchronously after the command has completed.
// The order of command execution and callback invocation can be expected to be preserved (maybe?).
func (sr *ShellRunner) AddCmd(cmd *exec.Cmd, callback func(*CommandResult), cancel context.CancelFunc) error {
sr.mu.Lock()
defer sr.mu.Unlock()

View File

@ -78,9 +78,6 @@ func TestShellRunnerCallback(t *testing.T) {
t.Fatalf("unexpected error adding command: %v", err)
}
// Wait a sec for the worker to pick up the task
time.Sleep(TaskStartWait)
callbackWait.Add(1)
if err := runner.AddCommand("echo callback b", func(result *tortoise.CommandResult) {
@ -93,6 +90,9 @@ func TestShellRunnerCallback(t *testing.T) {
t.Fatalf("unexpected error adding command: %v", err)
}
// Wait a sec for the worker to pick up the task
time.Sleep(TaskStartWait)
// Timeout waiting for callbacks
done := make(chan struct{})
go func() {