Code review and fixes.
This commit is contained in:
1 parent
f2a35a9305
commit
60f7f7a2e9
12 files changed
+185
-34
No files matched your search
@@ -4,6 +4,7 @@ import (
|
||||
"bytes"
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"log/slog"
|
||||
"os"
|
||||
"path/filepath"
|
||||
@@ -77,6 +78,66 @@ func TestHelperDiagnosticsBoundsFloodAndRecoversNextWindow(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestHelperReadinessBypassesDiagnosticBackpressure(t *testing.T) {
|
||||
for _, test := range []struct {
|
||||
name string
|
||||
windows int
|
||||
}{
|
||||
{name: "rate limit", windows: 1},
|
||||
{name: "full queue", windows: 2},
|
||||
} {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
output := newHelperDiagnostics()
|
||||
child := &process{launchedHelper: "helper", exclusions: map[string]bool{"game.exe": true}}
|
||||
readyCount := 0
|
||||
output.onReady = func(ready helperReady) {
|
||||
readyCount++
|
||||
child.readyExclusions.Store(int64(ready.HookExclusions))
|
||||
child.readySeen.Store(true)
|
||||
}
|
||||
// Do not start a log consumer: readiness must arrive even if a
|
||||
// sink cannot make progress. Fill successive rate windows to
|
||||
// exercise both diagnostic throttling and a completely full queue.
|
||||
for window := 0; window < test.windows; window++ {
|
||||
output.window = time.Now().Add(-11 * time.Second)
|
||||
for index := 0; index < 32; index++ {
|
||||
fmt.Fprintf(output, "wine-access: startup warning %d/%d\n", window, index)
|
||||
}
|
||||
}
|
||||
if test.windows == 2 {
|
||||
if len(output.lines) != cap(output.lines) {
|
||||
t.Fatal("diagnostic queue was not filled")
|
||||
}
|
||||
output.window = time.Now().Add(-11 * time.Second)
|
||||
}
|
||||
for _, line := range []string{
|
||||
"wine-access: ready {broken}\n",
|
||||
"unrelated: ready {\"reader\":\"org.example.Reader\"}\n",
|
||||
} {
|
||||
output.Write([]byte(line))
|
||||
}
|
||||
if readyCount != 0 {
|
||||
t.Fatal("invalid or unrelated output published readiness")
|
||||
}
|
||||
// Older helpers omit hook_exclusions and therefore report zero.
|
||||
output.Write([]byte("wine-access: rea"))
|
||||
output.Write([]byte("dy {\"reader\":\"org.example.Reader\"}\r\n"))
|
||||
if readyCount != 1 {
|
||||
t.Fatalf("readiness publications before logging = %d, want 1", readyCount)
|
||||
}
|
||||
manager := New(nil)
|
||||
if !manager.restart_running_helper(child, prefix{}, Settings{}) || !manager.helper_unconfirmed("helper") {
|
||||
t.Fatal("lost exclusion mismatch fallback under diagnostic backpressure")
|
||||
}
|
||||
output.finish()
|
||||
output.logRecords(slog.New(slog.DiscardHandler))
|
||||
if readyCount != 1 {
|
||||
t.Fatalf("logging published readiness again: count = %d", readyCount)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestManagerCapturesActualHelperDiagnosticsAndBoundsInheritedStderr(t *testing.T) {
|
||||
root := t.TempDir()
|
||||
helper := filepath.Join(root, "helper")
|
||||
|
||||
Reference in new issue
Block a user