Files
acp/full_linux_test.go
T
Samuel Cui c3bcd856aa feat!: stream caller-owned items and reduce the content options
Replaces the streaming request/result API with caller-owned items and
consolidates the content options, following the Job execution performance
design.

- `Item`, `BatchSource` and `Run` replace `StreamRequest`, `StreamResult`,
  `StreamSource`, `StreamSink` and `RunStream`. Every accepted item receives
  exactly one terminal callback from a single goroutine and without doing
  I/O; an item ACP cannot process reports `Failed`, and a completion carries
  one outcome per requested target in request order with its error identity
  preserved. A graceful stop stops feeding, finishes the items in flight and
  reports the rest, and a hard stop abandons per-item accounting.
- One `HashPolicy` replaces `WithHash`, `WithSignatureCache` and
  `ForceRehash`. A stored hash is read whenever the policy uses the cache,
  reused only where the policy allows it, and refreshed only when it differs.
- A source-only `WithReadMode` selects buffered (the default) or mapped
  reads, and buffered sources open with `O_NOATIME` where the platform has
  it. `LinearDevice` keeps request ordering, append targets and abort-on-error
  but no longer selects the read mode.
- `Overwrite` becomes a target-device option, `WithReadBuffer` sets the read
  buffer, and `SelectFiles` returns the entries the command line copies,
  replacing `AccurateJob`, `WildcardJob` and the walk options.
- Copy consumers share one reference-counted chunk buffer each from a common
  pool, and the per-item write goroutines finish before the result channel
  closes, so no finished item can be dropped.

The command line tools, the documentation and the test suite move with the
API, including semantic tests for the callback contract, the stop and drain
paths, the hash policy matrix and the read modes.
2026-09-19 02:03:34 +08:00

88 lines
2.5 KiB
Go

//go:build linux
package acp
import (
"context"
"errors"
"os"
"path/filepath"
"testing"
"time"
)
func TestRunMapsDeviceFullToTargetNoSpace(t *testing.T) {
// Route a disposable target symlink to Linux's deterministic ENOSPC device.
root := t.TempDir()
input := writeSourceFile(t, root, "source", []byte("fixture"))
target := filepath.Join(root, "target")
if err := os.Symlink("/dev/full", target); err != nil {
t.Fatal(err)
}
item := newFixtureItem(input, target)
// A target failure is an item outcome that keeps the portable no-space sentinel.
err := Run(
context.Background(),
newSliceSource(item),
SetToDevice(Overwrite(true), LinearDevice(true)),
)
if err != nil {
t.Fatalf("Run() error = %v, want nil", err)
}
result, terminalErr := item.terminal(t)
if terminalErr != nil {
t.Fatalf("item failed: %v", terminalErr)
}
if len(result.Targets) != 1 || !errors.Is(result.Targets[0].Err, ErrTargetNoSpace) {
t.Fatalf("target outcome = %#v, want %v", result.Targets, ErrTargetNoSpace)
}
}
func TestDeviceFullWriteFailureDrainsQueuedBuffers(t *testing.T) {
// A full device fails the first write while the producer still feeds the writer, which
// is the path that must release every queued read buffer.
trackChunkPool(t)
root := t.TempDir()
target := filepath.Join(root, "target")
if err := os.Symlink("/dev/full", target); err != nil {
t.Fatal(err)
}
size := int64(batchSize) * 4
readErr := errors.New("read failed")
item := newFixtureItem(filepath.Join(root, "source"), target)
copyer := newTestCopyer(t, SetToDevice(Overwrite(true)))
job := newWriteJob(&baseJob{
copyer: copyer,
item: item,
src: &source{base: root, path: "source"},
path: filepath.Join(root, "source"),
stat: &stat{size: size, mode: 0o644},
targets: []string{target},
}, &failingContentReader{err: readErr, batches: 4}, size, false)
// The writer must fail, release its queued buffers, and let the pipeline return.
done := make(chan error, 1)
go func() {
done <- runWriteJob(copyer, job)
}()
select {
case err := <-done:
if err != nil {
t.Fatalf("pipeline failed: %v", err)
}
case <-time.After(10 * time.Second):
t.Fatal("the pipeline deadlocked while draining a full target")
}
result, terminalErr := item.terminal(t)
if terminalErr != nil {
t.Fatalf("an item whose targets failed must still complete: %v", terminalErr)
}
if len(result.Targets) != 1 || !errors.Is(result.Targets[0].Err, ErrTargetNoSpace) {
t.Fatalf("target outcome = %#v, want %v", result.Targets, ErrTargetNoSpace)
}
}