Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(test): load to stream tmp file counting #13366

Merged
merged 1 commit into from
Jul 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion workflow/artifacts/common/load_to_stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import (
wfv1 "github.com/argoproj/argo-workflows/v3/pkg/apis/workflow/v1alpha1"
)

const loadToStreamPrefix = `wfstream-`

// wrapper around os.File enables us to remove the file when it gets closed
type selfDestructingFile struct {
os.File
Expand All @@ -28,7 +30,7 @@ func (w selfDestructingFile) Close() error {
func LoadToStream(a *wfv1.Artifact, g ArtifactDriver) (io.ReadCloser, error) {
log.Infof("Efficient artifact streaming is not supported for type %v: see https://github.com/argoproj/argo-workflows/issues/8489",
reflect.TypeOf(g))
filename := "/tmp/" + rand.String(32)
filename := "/tmp/" + loadToStreamPrefix + rand.String(32)
if err := g.Load(a, filename); err != nil {
return nil, err
}
Expand Down
21 changes: 19 additions & 2 deletions workflow/artifacts/common/load_to_stream_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"fmt"
"io"
"os"
"strings"
"testing"

"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -55,6 +56,22 @@ func (a *fakeArtifactDriver) ListObjects(artifact *wfv1.Artifact) ([]string, err
return nil, fmt.Errorf("not implemented")
}

func filteredFiles(t *testing.T) ([]os.DirEntry, error) {
t.Helper()

filtered := make([]os.DirEntry, 0)
entries, err := os.ReadDir("/tmp/")
if err != nil {
return filtered, err
}
for _, entry := range entries {
if strings.HasPrefix(entry.Name(), loadToStreamPrefix) {
filtered = append(filtered, entry)
}
}
return filtered, err
}

func TestLoadToStream(t *testing.T) {
tests := map[string]struct {
artifactDriver ArtifactDriver
Expand All @@ -80,7 +97,7 @@ func TestLoadToStream(t *testing.T) {
t.Run(name, func(t *testing.T) {

// need to verify that a new file doesn't get written so check the /tmp directory ahead of time
filesBefore, err := os.ReadDir("/tmp/")
filesBefore, err := filteredFiles(t)
if err != nil {
panic(err)
}
Expand All @@ -92,7 +109,7 @@ func TestLoadToStream(t *testing.T) {
stream.Close()

// make sure the new file got deleted when we called stream.Close() above
filesAfter, err := os.ReadDir("/tmp/")
filesAfter, err := filteredFiles(t)
if err != nil {
panic(err)
}
Expand Down
Loading