Bump version to 1.0.10
Smart WoL: TCP pre-check before sending magic packet (3s timeout). Machine status updates via SSE: online/offline tracked in DB and broadcast to all connected browser tabs in real-time. - Pre-check: if machine already reachable, skip WoL and mark online - WoL path: send 3 magic packets, wait for SSH, mark online/offline - Backend: setMachineStatus() helper + machine_status SSE event - Frontend: subscribeMachineStatus() SSE helper for Machines + Dashboard - IsReachable() helper in wol package for TCP reachability checks
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
package syncengine
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/syncserver/internal/wol"
|
||||
)
|
||||
|
||||
func TestIsReachable(t *testing.T) {
|
||||
ln, err := net.ListenTCP("tcp4", &net.TCPAddr{IP: net.ParseIP("127.0.0.1"), Port: 0})
|
||||
if err != nil {
|
||||
t.Skipf("skipping test (no TCP listener available): %v", err)
|
||||
}
|
||||
defer ln.Close()
|
||||
addr := ln.Addr().(*net.TCPAddr)
|
||||
|
||||
ctx := context.Background()
|
||||
|
||||
if !wol.IsReachable(ctx, "127.0.0.1", addr.Port, 500*time.Millisecond) {
|
||||
t.Error("expected reachable on listening port")
|
||||
}
|
||||
if wol.IsReachable(ctx, "127.0.0.1", addr.Port+1, 500*time.Millisecond) {
|
||||
t.Error("expected unreachable on non-listening port")
|
||||
}
|
||||
}
|
||||
|
||||
func TestIsReachableTimeout(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
start := time.Now()
|
||||
if wol.IsReachable(ctx, "192.0.2.1", 12345, 500*time.Millisecond) {
|
||||
t.Error("expected unreachable for non-routable IP")
|
||||
}
|
||||
if d := time.Since(start); d < 400*time.Millisecond {
|
||||
t.Errorf("IsReachable returned too early: %v", d)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user