Выпуск WDTT Plus v18

This commit is contained in:
Ivan4537 committed 2026-09-11 15:45:55 +03:00
1 parent abf0a0f130
commit b3935b947a
101 files changed
+16512 -1477

No files matched your search

+139 -3
View File
@@ -86,14 +86,48 @@ func TestDeviceStateChangeClearsPendingAndReportedTrafficStall(t *testing.T) {
}
}
func TestSocksModeDoesNotTreatOneSilentFlowAsGlobalTransportFailure(t *testing.T) {
d := &Dispatcher{}
startedAt := time.Unix(100, 0)
d.setUnansweredUserTrafficHealthEnabled(false)
d.noteUserTrafficSent(startedAt)
if _, stalled := d.claimStalledUserTraffic(startedAt.Add(10*time.Minute), 45*time.Second); stalled {
t.Fatal("a silent SOCKS flow must not fail the shared transport")
}
if d.noteUserTrafficResponse() {
t.Fatal("SOCKS traffic must not report recovery from a disabled watchdog")
}
}
func TestVpnModeCanReenableUnansweredTrafficHealth(t *testing.T) {
d := &Dispatcher{}
startedAt := time.Unix(100, 0)
d.setUnansweredUserTrafficHealthEnabled(false)
d.setUnansweredUserTrafficHealthEnabled(true)
d.noteUserTrafficSent(startedAt)
if _, stalled := d.claimStalledUserTraffic(startedAt.Add(time.Minute), 45*time.Second); !stalled {
t.Fatal("VPN mode must retain unanswered user traffic detection")
}
}
func TestDeviceSleepSuppressesHealthAndWakeNotifiesWorkers(t *testing.T) {
d := &Dispatcher{}
wakeCh := make(chan struct{}, 1)
workers := []*WorkerSlot{{ID: 1, WakeCh: wakeCh}}
wakeCh := make(chan uint64, 1)
sleepCh := make(chan struct{}, 1)
workers := []*WorkerSlot{{ID: 1, WakeCh: wakeCh, SleepCh: sleepCh}}
d.workers.Store(&workers)
wakeAt := time.Unix(500, 0)
d.noteDeviceSleep()
select {
case <-sleepCh:
default:
t.Fatal("sleep must cancel an outstanding worker wake probe")
}
if !d.shouldSuppressTransportHealth(wakeAt.Add(24 * time.Hour)) {
t.Fatal("transport timeouts must stay suppressed while the device sleeps")
}
@@ -102,7 +136,10 @@ func TestDeviceSleepSuppressesHealthAndWakeNotifiesWorkers(t *testing.T) {
t.Fatalf("first wake generation = %d, want 1", generation)
}
select {
case <-wakeCh:
case generation := <-wakeCh:
if generation != 1 {
t.Fatalf("worker wake generation = %d, want 1", generation)
}
default:
t.Fatal("wake must request an immediate keepalive from every worker")
}
@@ -113,3 +150,102 @@ func TestDeviceSleepSuppressesHealthAndWakeNotifiesWorkers(t *testing.T) {
t.Fatal("transport health checks must resume after wake grace")
}
}
func TestLatestWakeGenerationReplacesAnUndeliveredOlderProbe(t *testing.T) {
ch := make(chan uint64, 1)
offerLatestGeneration(ch, 1)
offerLatestGeneration(ch, 2)
if generation := <-ch; generation != 2 {
t.Fatalf("queued generation = %d, want latest generation 2", generation)
}
}
func TestWakeGenerationRoutesOnlyThroughIndividuallyVerifiedWorkers(t *testing.T) {
d := &Dispatcher{}
workers := []*WorkerSlot{
{ID: 1, WakeCh: make(chan uint64, 1), WakeAckCh: make(chan uint64, 1)},
{ID: 2, WakeCh: make(chan uint64, 1), WakeAckCh: make(chan uint64, 1)},
}
d.workers.Store(&workers)
generation := d.noteDeviceWake(time.Unix(700, 0))
if workerEligibleForWakeGeneration(workers[0], generation, false) ||
workerEligibleForWakeGeneration(workers[1], generation, false) {
t.Fatal("registered workers must stay out of user routing until their own wake response")
}
d.acknowledgeWorkerWake(workers[0], generation)
if !workerEligibleForWakeGeneration(workers[0], generation, false) {
t.Fatal("the worker that answered the current wake probe must become routable")
}
if workerEligibleForWakeGeneration(workers[1], generation, false) {
t.Fatal("one worker response must not validate another worker")
}
ready, total := d.wakeStatus(generation)
if ready != 1 || total != 2 {
t.Fatalf("wake status = %d/%d, want 1/2", ready, total)
}
}
func TestSleepingDoesNotApplyWakeRoutingGate(t *testing.T) {
worker := &WorkerSlot{ID: 1}
if !workerEligibleForWakeGeneration(worker, 3, true) {
t.Fatal("screen-off traffic must not be blocked by a previous wake generation")
}
}
func TestReplacementWorkerReceivesCurrentWakeGeneration(t *testing.T) {
d := &Dispatcher{}
empty := make([]*WorkerSlot, 0)
d.workers.Store(&empty)
d.wakeGeneration.Store(4)
worker := &WorkerSlot{ID: 7, WakeCh: make(chan uint64, 1)}
d.Register(worker)
select {
case generation := <-worker.WakeCh:
if generation != 4 {
t.Fatalf("replacement worker generation = %d, want 4", generation)
}
default:
t.Fatal("a replacement worker must be probed before receiving user traffic")
}
}
func TestSleepAndWakeReachEverySupportedWorkerCount(t *testing.T) {
for workerCount := workersPerGroup; workerCount <= 108; workerCount += workersPerGroup {
d := &Dispatcher{}
workers := make([]*WorkerSlot, 0, workerCount)
for id := 1; id <= workerCount; id++ {
workers = append(workers, &WorkerSlot{
ID: id,
WakeCh: make(chan uint64, 1),
SleepCh: make(chan struct{}, 1),
})
}
d.workers.Store(&workers)
d.noteDeviceSleep()
if generation := d.noteDeviceWake(time.Unix(int64(workerCount), 0)); generation != 1 {
t.Fatalf("%d workers: wake generation = %d, want 1", workerCount, generation)
}
for _, worker := range workers {
select {
case <-worker.SleepCh:
default:
t.Fatalf("%d workers: worker %d missed sleep notification", workerCount, worker.ID)
}
select {
case generation := <-worker.WakeCh:
if generation != 1 {
t.Fatalf("%d workers: worker %d generation = %d, want 1", workerCount, worker.ID, generation)
}
default:
t.Fatalf("%d workers: worker %d missed wake notification", workerCount, worker.ID)
}
}
}
}