forked from argoproj/argo-workflows
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: prevent stdout from disappearing in script templates. Fixes argo…
…proj#11330 (argoproj#11368) Signed-off-by: boiledfroginthewell <boiledfroginthewell@users.noreply.github.com> Signed-off-by: Dillen Padhiar <dillen_padhiar@intuit.com>
- Loading branch information
1 parent
9df499f
commit 7fa4db2
Showing
3 changed files
with
63 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package os_specific | ||
|
||
import ( | ||
"bytes" | ||
"io" | ||
"os/exec" | ||
"testing" | ||
"time" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestSimpleStartCloser(t *testing.T) { | ||
cmd := exec.Command("sh", "-c", "echo -n A123456789B123456789C123456789D123456789E123456789") | ||
var stdoutWriter bytes.Buffer | ||
slowWriter := SlowWriter{ | ||
&stdoutWriter, | ||
} | ||
// Command outputs are asynchronously written to cmd.Stdout. | ||
// Using SlowWriter causes the situation where the invoked command has exited but its outputs have not been written yet. | ||
cmd.Stdout = slowWriter | ||
|
||
closer, err := StartCommand(cmd) | ||
assert.NoError(t, err) | ||
err = cmd.Process.Release() | ||
assert.NoError(t, err) | ||
// Wait for echo command to exit before calling closer | ||
time.Sleep(100 * time.Millisecond) | ||
closer() | ||
|
||
assert.Equal(t, "A123456789B123456789C123456789D123456789E123456789", stdoutWriter.String()) | ||
} | ||
|
||
type SlowWriter struct { | ||
Writer io.Writer | ||
} | ||
|
||
func (s SlowWriter) Write(data []byte) (n int, err error) { | ||
for i := range data { | ||
_, err := s.Writer.Write(data[i : i+1]) | ||
if err != nil { | ||
return i, err | ||
} | ||
time.Sleep(7 * time.Millisecond) | ||
} | ||
return len(data), nil | ||
} |