package platform

import (
	"runtime"
	"testing"
)

func TestPlatformStressCPUThreadsOverride(t *testing.T) {
	t.Setenv("BEE_PLATFORM_STRESS_THREADS", "7")
	if got := platformStressCPUThreads(); got != 7 {
		t.Fatalf("platformStressCPUThreads=%d want 7", got)
	}
}

func TestPlatformStressCPUThreadsDefaultLeavesHeadroom(t *testing.T) {
	t.Setenv("BEE_PLATFORM_STRESS_THREADS", "")
	got := platformStressCPUThreads()
	if got < 1 {
		t.Fatalf("platformStressCPUThreads=%d want >= 1", got)
	}
	if got > runtime.NumCPU() {
		t.Fatalf("platformStressCPUThreads=%d want <= NumCPU=%d", got, runtime.NumCPU())
	}
	if runtime.NumCPU() > 2 && got >= runtime.NumCPU() {
		t.Fatalf("platformStressCPUThreads=%d want headroom below NumCPU=%d", got, runtime.NumCPU())
	}
}

func TestPlatformStressMemoryMBOverride(t *testing.T) {
	t.Setenv("BEE_PLATFORM_STRESS_MB", "8192")
	if got := platformStressMemoryMB(); got != 8192 {
		t.Fatalf("platformStressMemoryMB=%d want 8192", got)
	}
}
