//go:build windows package main import ( "strings" "testing" "time" ) func TestOrdinaryPolicyUsesFreshPriorityAndReleasesHandles(t *testing.T) { t.Run("do not raise a light process after an external demotion", func(t *testing.T) { f := newFake() p := f.add(10, 50, PriorityClassHigh) c := testController(f) defer c.Shutdown() f.onRead = func(v *fakeProcess) { v.info.Prio = PriorityClassBelowNormal; f.onRead = nil } c.Step() assertPriority(t, p, PriorityClassBelowNormal) if p.writes != 0 { t.Fatal("stale priority decision performed a write") } }) t.Run("release obsolete denied-write state", func(t *testing.T) { f := newFake() p := f.add(10, 150, PriorityClassNormal) p.writable = false c := testController(f) defer c.Shutdown() c.Step() p.info.RSS = 50 c.Step() assertClosed(t, f) }) } func TestDeniedHeavyTriggerIsStillLoggedBeforeBackground(t *testing.T) { f := newFake() g := f.add(10, 250, PriorityClassNormal) g.info.Name = "BlockedGame.exe" g.writable = false b := f.add(20, 50, PriorityClassNormal) b.info.Name = "Background.exe" c := testController(f) defer c.Shutdown() text := formatReport(c.Step(), time.Unix(0, 0)) if strings.Index(text, "BlockedGame.exe") < 0 || strings.Index(text, "BlockedGame.exe") > strings.Index(text, "Background.exe") { t.Fatal("the triggering process is hidden below background changes", text) } if strings.Contains(text, "NORMAL -> HIGH") { t.Fatal("denied raise was logged as a success") } }