tusd: `TestWriteChunkCleansUpTempFiles` test fails at random times
The S3 test TestWriteChunkCleansUpTempFiles fails at random times, especially in the CI pipeline, and only seems to be on linux.
Doing some digging locally, and I see that the temp directory has three files in it when the test fails.
1 at 10 bytes with 1234567890
1 at 4 bytes with ABCD
1 at 0 bytes (this is the one that causes the test to fail)
--- FAIL: TestWriteChunkCleansUpTempFiles (0.00s)
s3store_test.go:1278:
Error Trace: s3store_test.go:1278
s3store.go:414
s3store.go:382
s3store_test.go:1350
Error: Not equal:
expected: 3
actual : 2
Test: TestWriteChunkCleansUpTempFiles
Using this dockerfile
FROM golang:1.17.2
WORKDIR /go/src/github.com/tus/tusd
COPY go.mod go.sum ./
RUN go mod download
COPY cmd ./cmd/
COPY internal ./internal/
COPY pkg ./pkg/
CMD [ "go", "test", "./pkg/s3store", "-v" ]
With this patch on the S3 test
diff --git a/pkg/s3store/s3store_test.go b/pkg/s3store/s3store_test.go
index 88ec09a..a5ec33f 100644
--- a/pkg/s3store/s3store_test.go
+++ b/pkg/s3store/s3store_test.go
@@ -5,6 +5,7 @@ import (
"context"
"fmt"
"io/ioutil"
+ "path/filepath"
"strings"
"testing"
"time"
@@ -1273,6 +1274,9 @@ func (s s3APIWithTempFileAssertion) UploadPartWithContext(context.Context, *s3.U
files, err := ioutil.ReadDir(s.tempDir)
assert.Nil(err)
for _, file := range files {
+ // Print the file name and file size to make it easier to find the file.
+ content, _ := ioutil.ReadFile(filepath.Join(s.tempDir, file.Name()))
+ fmt.Printf("%s (%d bytes): %s\n", file.Name(), file.Size(), string(content))
assert.True(strings.HasPrefix(file.Name(), "tusd-s3-tmp-"))
}
assert.Equal(len(files), 2)
It shows the file, its size and contents. When it fails, it’ll show a third file with 0 bytes in it.
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Comments: 15 (15 by maintainers)
@Acconut I did not find any reliable way to reproduce it. Seemed very random. But I can do testing for a while against the V2 branch and see if it fails or not.