fetch_ml/internal/queue/filesystem_fallback_test.go
Jeremie Fraeys ee0b90cfc5
refactor: co-locate queue and resources tests, add manager tests
Move unit tests from tests/unit/ to internal/ following Go conventions:
- tests/unit/queue/* -> internal/queue/* (dedup, filesystem_fallback, queue_permissions, queue_spec, queue, sqlite_queue tests)
- tests/unit/gpu/* -> internal/resources/* (gpu_detector, gpu_golden tests)
- tests/unit/resources/* -> internal/resources/* (manager_test.go)

Update import paths in test files to reflect new locations.

Note: GPU tests consolidated into resources package since GPU detection is part of resource management. Manager tests show significant new test coverage (166 lines).
2026-03-12 16:36:02 -04:00

66 lines
1.6 KiB
Go

package queue_test
import (
"os"
"path/filepath"
"testing"
"time"
"github.com/google/uuid"
"github.com/jfraeys/fetch_ml/internal/queue"
)
func TestBackendFallbackToFilesystemWhenRedisUnavailable(t *testing.T) {
root := t.TempDir()
fsPath := filepath.Join(root, "queue-fs")
b, err := queue.NewBackend(queue.BackendConfig{
Backend: queue.QueueBackendRedis,
RedisAddr: "127.0.0.1:0",
FallbackToFilesystem: true,
FilesystemPath: fsPath,
})
if err != nil {
t.Fatalf("expected fallback backend, got error: %v", err)
}
if _, ok := b.(*queue.FilesystemQueue); !ok {
t.Fatalf("expected filesystem backend, got %T", b)
}
task := &queue.Task{
ID: uuid.New().String(),
JobName: "job-1",
Args: "--epochs 1",
Status: "queued",
Priority: 5,
CreatedAt: time.Now().UTC(),
UserID: "local",
Username: "local",
CreatedBy: "local",
Metadata: map[string]string{"commit_id": "deadbeef"},
}
if err := b.AddTask(task); err != nil {
t.Fatalf("add task: %v", err)
}
p := filepath.Join(fsPath, "pending", "entries", task.ID+".json")
if _, err := os.Stat(p); err != nil {
t.Fatalf("expected pending task file %s to exist: %v", p, err)
}
}
func TestBackendFilesystemDirect(t *testing.T) {
root := t.TempDir()
fsPath := filepath.Join(root, "queue-fs")
b, err := queue.NewBackend(queue.BackendConfig{
Backend: queue.QueueBackendFS,
FilesystemPath: fsPath,
})
if err != nil {
t.Fatalf("expected filesystem backend, got error: %v", err)
}
if _, ok := b.(*queue.FilesystemQueue); !ok {
t.Fatalf("expected filesystem backend, got %T", b)
}
}