Skip to content

SeaweedFS is a distributed storage system for object storage (S3), file systems, Iceberg table buckets, and Lance vector buckets, designed to handle billions of files with O(1) disk access and effortless horizontal scaling.

2.0 KB
Raw Blame
package plugin

import (
	"testing"
)

func TestJobTypeLaneMapCoversKnownTypes(t *testing.T) {
	// Every job type in the map must resolve to a lane the scheduler runs.
	// Checked against AllLanes rather than a list spelled out here, so adding a
	// lane does not silently leave its job types unscheduled.
	known := make(map[SchedulerLane]bool, len(AllLanes()))
	for _, lane := range AllLanes() {
		known[lane] = true
	}
	for jobType, lane := range jobTypeLaneMap {
		if !known[lane] {
			t.Errorf("jobTypeLaneMap[%q] = %q, want a lane from AllLanes()", jobType, lane)
		}
	}
}

func TestJobTypeLaneFallsBackToDefault(t *testing.T) {
	if got := JobTypeLane("unknown_job_type"); got != LaneDefault {
		t.Errorf("JobTypeLane(unknown) = %q, want %q", got, LaneDefault)
	}
}

func TestAllLanesHaveIdleSleep(t *testing.T) {
	for _, lane := range AllLanes() {
		if d := LaneIdleSleep(lane); d <= 0 {
			t.Errorf("LaneIdleSleep(%q) = %v, want > 0", lane, d)
		}
	}
}

func TestLaneRequiresLock(t *testing.T) {
	tests := []struct {
		name string
		lane SchedulerLane
		want bool
	}{
		{"Default", LaneDefault, true},
		{"Iceberg", LaneIceberg, false},
		{"Lifecycle", LaneLifecycle, false},
		{"Unknown", "unknown_lane", true},
	}
	for _, tt := range tests {
		t.Run(tt.name, func(t *testing.T) {
			if got := LaneRequiresLock(tt.lane); got != tt.want {
				t.Errorf("LaneRequiresLock(%q) = %v, want %v", tt.lane, got, tt.want)
			}
		})
	}
}

func TestKnownJobTypesInMap(t *testing.T) {
	// Ensure the well-known job types are mapped. This catches drift
	// if a handler's job type string changes without updating the map.
	expected := map[string]SchedulerLane{
		"vacuum":              LaneDefault,
		"volume_balance":      LaneDefault,
		"ec_balance":          LaneDefault,
		"erasure_coding":      LaneDefault,
		"admin_script":        LaneDefault,
		"iceberg_maintenance": LaneIceberg,
		"s3_lifecycle":        LaneLifecycle,
	}
	for jobType, wantLane := range expected {
		if got := JobTypeLane(jobType); got != wantLane {
			t.Errorf("JobTypeLane(%q) = %q, want %q", jobType, got, wantLane)
		}
	}
}