provider, agent: the sign-in watch tests count no reads of their own check, in both packages
TestAccountDiscoveryOffReadsNoSignIn (internal/provider) is the sibling5421f4468left: its sanity read failed on "{}{}" when the FIFO was answered twice under load, and909d76747shipped past it as "fails on main too (1 in ~20)". It now takes one or more "{}" and counts only opens after the check, as the agent test does. Both tests also had a second race in that fix: a write the watch began while the check's read was still open (after its EOF, before close) is noted after the read returns, past `checked`, and reported as a read of a sign-in. Each test now waits until the notes stop for 20ms before counting. Ran: on origin/main's provider test, a 5ms delay before the read: 3/3 red; with the fix 5/5 green. Late close (1ms after EOF) plus 3ms before the watch notes an open: without the wait 6/10 red (".codex/auth.json"), with it 10/10 green. A stray read of a sign-in after the check is still reported (only that file). -count=30 of each test; go test ./internal/agent ./internal/provider; go vet and GOOS=linux go vet; gofmt -l clean.
This commit is contained in:
@@ -95,6 +95,11 @@ func TestAccountDiscoveryOffAgentsReadNoSignIn(t *testing.T) {
|
||||
if b, err := os.ReadFile(files[0]); err != nil || len(b) == 0 || strings.ReplaceAll(string(b), "{}", "") != "" {
|
||||
t.Fatalf("the watch didn't answer a read: %q %v", b, err)
|
||||
}
|
||||
// a write the watch began while the read was still open is noted
|
||||
// after it returns; wait for the notes to stop before counting
|
||||
for n := -1; n != len(opened()); time.Sleep(20 * time.Millisecond) {
|
||||
n = len(opened())
|
||||
}
|
||||
checked := len(opened())
|
||||
|
||||
cfgDir := filepath.Join(home, ".config", "opencode")
|
||||
|
||||
@@ -132,13 +132,21 @@ func TestAccountDiscoveryOffReadsNoSignIn(t *testing.T) {
|
||||
files = slices.Compact(files)
|
||||
opened := openWatch(t, files)
|
||||
|
||||
// the watch sees a read: this test's own
|
||||
if b, err := os.ReadFile(codexAuthPath()); err != nil || string(b) != "{}" {
|
||||
// the watch sees a read: this test's own. A reader slow to reach the
|
||||
// end is handed "{}" again by the next loop's write, and noted again,
|
||||
// so under load it reads "{}{}"
|
||||
if b, err := os.ReadFile(codexAuthPath()); err != nil || len(b) == 0 || strings.ReplaceAll(string(b), "{}", "") != "" {
|
||||
t.Fatalf("the watch didn't answer a read: %q %v", b, err)
|
||||
}
|
||||
if got := opened(); len(got) != 1 {
|
||||
if got := opened(); len(got) == 0 || slices.ContainsFunc(got, func(p string) bool { return p != codexAuthPath() }) {
|
||||
t.Fatalf("the watch saw %v, want the test's own read", got)
|
||||
}
|
||||
// a write the watch began while the read was still open is noted
|
||||
// after it returns; wait for the notes to stop before counting
|
||||
for n := -1; n != len(opened()); time.Sleep(20 * time.Millisecond) {
|
||||
n = len(opened())
|
||||
}
|
||||
checked := len(opened())
|
||||
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
|
||||
defer cancel()
|
||||
@@ -203,9 +211,9 @@ func TestAccountDiscoveryOffReadsNoSignIn(t *testing.T) {
|
||||
|
||||
// anything started in the background has its moment
|
||||
time.Sleep(300 * time.Millisecond)
|
||||
if got := opened(); len(got) != 1 {
|
||||
read := slices.Compact(slices.Sorted(slices.Values(got[1:])))
|
||||
t.Errorf("with discovery off, %d reads of sign-ins: %s", len(got)-1, strings.Join(read, " "))
|
||||
if got := opened()[checked:]; len(got) != 0 {
|
||||
read := slices.Compact(slices.Sorted(slices.Values(got)))
|
||||
t.Errorf("with discovery off, %d reads of sign-ins: %s", len(got), strings.Join(read, " "))
|
||||
}
|
||||
if s := ran(); s != "" {
|
||||
t.Errorf("with discovery off, these ran:\n%s", s)
|
||||
|
||||
Reference in New Issue
Block a user