mirror of
https://github.com/D-Modem/bbs.git
synced 2026-11-28 17:38:04 -08:00
email: read the test log under its lock
TestDNSBL read the site's log buffer while the SMTP server's goroutine wrote to it, which the race detector caught in CI. The log is now the synchronised writer itself, with a String that takes the same lock. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01B82eRSzB4EzF1cUBt1ccvB
This commit is contained in:
1 file changed
+10
-3
@@ -73,7 +73,7 @@ type site struct {
|
||||
b *bbs.BBS
|
||||
svc *Service
|
||||
st *store.Store
|
||||
log *bytes.Buffer
|
||||
log *syncWriter
|
||||
addrs map[string]string
|
||||
users map[string]*store.User
|
||||
}
|
||||
@@ -87,7 +87,7 @@ func newSite(t *testing.T, domain string, dns *fakeDNS, users []string, kinds ..
|
||||
t.Fatal(err)
|
||||
}
|
||||
t.Cleanup(func() { st.Close() })
|
||||
s := &site{st: st, log: &bytes.Buffer{}, addrs: map[string]string{}, users: map[string]*store.User{}}
|
||||
s := &site{st: st, log: &syncWriter{w: &bytes.Buffer{}}, addrs: map[string]string{}, users: map[string]*store.User{}}
|
||||
for _, name := range users {
|
||||
u, err := st.CreateUser(name, "password1", "", name == "sysop")
|
||||
if err != nil {
|
||||
@@ -97,7 +97,7 @@ func newSite(t *testing.T, domain string, dns *fakeDNS, users []string, kinds ..
|
||||
}
|
||||
set := bbs.Defaults()
|
||||
set.FailDelay = 0
|
||||
s.b = bbs.New(set, st, log.New(&syncWriter{w: s.log}, domain+": ", 0))
|
||||
s.b = bbs.New(set, st, log.New(s.log, domain+": ", 0))
|
||||
ms := Defaults(domain, "mail."+domain)
|
||||
ms.Resolver = dns
|
||||
s.svc = New(s.b, ms)
|
||||
@@ -155,6 +155,13 @@ func (w *syncWriter) Write(p []byte) (int, error) {
|
||||
return w.w.Write(p)
|
||||
}
|
||||
|
||||
// String is what has been written, read under the same lock.
|
||||
func (w *syncWriter) String() string {
|
||||
w.mu.Lock()
|
||||
defer w.mu.Unlock()
|
||||
return w.w.String()
|
||||
}
|
||||
|
||||
// submit sends a mail by SMTP submission, as name.
|
||||
func submit(t *testing.T, addr, name, from string, to []string, msg string) error {
|
||||
t.Helper()
|
||||
|
||||
Reference in new issue
Block a user