Files
yatm/internal/executor/device_test.go
T
Samuel Cui 4fef653b71 Prepare YATM v1.0.0-alpha.2
Unify file queries and Scan execution, retain indexed Identical results,
improve Job and Preview workflows, and verify release packaging.
2026-10-05 19:08:49 +08:00

27 lines
985 B
Go

package executor
import (
"context"
"testing"
"github.com/stretchr/testify/require"
)
func TestAttemptTapeLeaseReuseRetainsSingleOwnership(t *testing.T) {
// Identity resolution and physical Session setup share one attempt-owned drive lease.
exe := New(nil, nil, []string{"/dev/nst0"}, Paths{}, Scripts{}, nil)
require.NoError(t, exe.beginAttempt(1, func(error) {}))
require.NoError(t, exe.AcquireTapeDevice(context.Background(), 1, "/dev/nst0", nil))
require.NoError(t, exe.AcquireTapeDevice(context.Background(), 1, "/dev/nst0", func() {
t.Error("the same attempt must not queue behind its own drive lease")
}))
require.Len(t, exe.attempts[1].resources, 1)
require.Empty(t, exe.ListAvailableDevices())
// One settlement returns the drive exactly once, after all work using it has ended.
exe.endAttempt(1)
require.Equal(t, []string{"/dev/nst0"}, exe.ListAvailableDevices())
exe.endAttempt(1)
require.Equal(t, []string{"/dev/nst0"}, exe.ListAvailableDevices())
}