Count repeated report write failures once
This commit is contained in:
@@ -11,6 +11,7 @@ import (
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"slices"
|
||||
"strconv"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
@@ -427,6 +428,40 @@ func TestFailedReportsIncludeLaterDeliveryFailures(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestRepeatedFailureOfOneReportCountsOnce(t *testing.T) {
|
||||
dir := t.TempDir()
|
||||
session, err := PrepareOutput(OutputSelection{ReportDir: dir, ReportingEnabled: true})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
initial, retry := errors.New("initial write failed"), errors.New("retry failed")
|
||||
replace := session.replace
|
||||
attempts := 0
|
||||
session.replace = func(ctx context.Context, path string, payload []byte) error {
|
||||
if filepath.Base(path) == RecoveriesFile {
|
||||
attempts++
|
||||
if attempts == 1 {
|
||||
return initial
|
||||
}
|
||||
return retry
|
||||
}
|
||||
return replace(ctx, path, payload)
|
||||
}
|
||||
err = session.Finish(context.Background(), nil, nil, func(_ error, failures []FileFailure) (ReportBundle, error) {
|
||||
payload := []byte(strconv.Itoa(len(failures)))
|
||||
return ReportBundle{Errors: payload, Recoveries: payload, Markdown: payload}, nil
|
||||
})
|
||||
if !errors.Is(err, initial) || !errors.Is(err, retry) || attempts != 2 {
|
||||
t.Fatalf("writes = %d, error = %v", attempts, err)
|
||||
}
|
||||
for _, name := range []string{ErrorsFile, MarkdownFile} {
|
||||
got, readErr := os.ReadFile(filepath.Join(dir, name))
|
||||
if readErr != nil || string(got) != "1" {
|
||||
t.Errorf("%s recorded %q failures, error = %v", name, got, readErr)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
type writerFunc func([]byte) (int, error)
|
||||
|
||||
func (write writerFunc) Write(payload []byte) (int, error) { return write(payload) }
|
||||
|
||||
Reference in New Issue
Block a user