package scheduler

import (
	"context"
	"testing"
	"time"
)

// The scheduler runs in Docker on macOS, whose VM does not route ICMP to the
// LAN — every ping check reported "down" for hosts that were demonstrably up.
// tcpReachable is the fallback that keeps "is it reachable" answerable.
func TestTCPReachableAnswersWhenICMPCannot(t *testing.T) {
	ctx := context.Background()
	// localhost:22 is open on this machine (sshd), and port 1 is not.
	if !tcpReachable(ctx, "127.0.0.1", 22, 3*time.Second) {
		t.Skip("no sshd on localhost — cannot exercise the positive case")
	}
	if tcpReachable(ctx, "127.0.0.1", 1, 1*time.Second) {
		t.Error("port 1 should not be reachable")
	}
	// Defaults to 22 when unset, which is what checkdefaults' ping configs use.
	if !tcpReachable(ctx, "127.0.0.1", 0, 3*time.Second) {
		t.Error("port 0 should default to 22")
	}
}
