mirror of
https://github.com/restic/restic.git
synced 2026-06-01 22:59:44 +00:00
backup: prevent hang using --stdin-from-command if upload fails (#21829)
This commit is contained in:
@@ -6,6 +6,7 @@ import (
|
||||
"io"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/restic/restic/internal/fs"
|
||||
"github.com/restic/restic/internal/test"
|
||||
@@ -51,3 +52,14 @@ func TestCommandReaderOutput(t *testing.T) {
|
||||
|
||||
test.Equals(t, "hello world", strings.TrimSpace(buf.String()))
|
||||
}
|
||||
|
||||
func TestCommandReaderQuickClose(t *testing.T) {
|
||||
ctx, cancel := context.WithTimeout(context.TODO(), 10*time.Second)
|
||||
defer cancel()
|
||||
reader, err := fs.NewCommandReader(ctx, []string{"sleep", "3600"}, func(msg string, args ...interface{}) {})
|
||||
test.OK(t, err)
|
||||
|
||||
// test that close returns before the context expires
|
||||
_ = reader.Close()
|
||||
test.OK(t, ctx.Err())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user