oficina / meet Public

Equal-work test: count only the request's own statements

Under -race on the runner the mail worker's authorize ran beside the
measured request and its queries were counted against whichever POST
was being timed (6 against 3). The counter now counts statements made
on the request's context alone; the worker runs on its own.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev pushed by paul@keymail.dev 6b18d00df96258936b732b2e6c63107d68687e7c parent dde2c12
1 file changed, +11 −1
  • internal/calls/signin_equal_work_test.go +11 −1

CI passed — run details

CI log
=== vet ===
go vet ./...
=== fmt ===
=== test ===
go test ./...
ok  	amadan.net/oficina/calls/callscore	(cached)
?   	amadan.net/oficina/calls/cmd/calls	[no test files]
ok  	amadan.net/oficina/calls/cmd/quality-summary	(cached)
ok  	amadan.net/oficina/calls/internal/calls	1.960s
ok  	amadan.net/oficina/calls/internal/calls/apns	(cached)
ok  	amadan.net/oficina/calls/internal/calls/hub	(cached)
?   	amadan.net/oficina/calls/internal/calls/icons	[no test files]
?   	amadan.net/oficina/calls/internal/calls/keymailtest	[no test files]
ok  	amadan.net/oficina/calls/internal/calls/relay	(cached)
ok  	amadan.net/oficina/calls/internal/calls/seal	(cached)
ok  	amadan.net/oficina/calls/internal/callstest	9.980s
?   	amadan.net/oficina/calls/protocol	[no test files]
?   	amadan.net/oficina/calls/scripts/writeestilo	[no test files]
=== migration-check ===
go run amadan.net/rastrillo/rastrillo/cmd/rastrillo migration check
rastrillo migration check: models and migrations agree
=== race ===
CGO_ENABLED=1 go test -race ./internal/...
ok  	amadan.net/oficina/calls/internal/calls	12.217s
ok  	amadan.net/oficina/calls/internal/calls/apns	(cached)
ok  	amadan.net/oficina/calls/internal/calls/hub	(cached)
?   	amadan.net/oficina/calls/internal/calls/icons	[no test files]
?   	amadan.net/oficina/calls/internal/calls/keymailtest	[no test files]
ok  	amadan.net/oficina/calls/internal/calls/relay	(cached)
ok  	amadan.net/oficina/calls/internal/calls/seal	(cached)
ok  	amadan.net/oficina/calls/internal/callstest	29.812s
diff --git a/internal/calls/signin_equal_work_test.go b/internal/calls/signin_equal_work_test.go
index 1d58b1d..d4fd9ca 100644
--- a/internal/calls/signin_equal_work_test.go
+++ b/internal/calls/signin_equal_work_test.go
@@ -21,6 +21,9 @@ import (
"gorm.io/gorm"
)
+// measuredKey marks the context of a request whose statements count.
+type measuredKey struct{}
+
// countingHandler counts log records, and nothing else.
type countingHandler struct{ n *atomic.Int64 }
@@ -63,7 +66,13 @@ func TestMemberAndOutsiderDoTheSameWorkOverBudget(t *testing.T) {
}
var statements atomic.Int64
- count := func(*gorm.DB) { statements.Add(1) }
+ // Only the request's own statements: the mail worker runs beside it
+ // (authorize, after the response) on a context of its own.
+ count := func(tx *gorm.DB) {
+ if tx.Statement.Context != nil && tx.Statement.Context.Value(measuredKey{}) != nil {
+ statements.Add(1)
+ }
+ }
cb := a.db.G.Callback()
for _, err := range []error{
cb.Query().After("gorm:query").Register("equalwork:query", count),
@@ -85,6 +94,7 @@ func TestMemberAndOutsiderDoTheSameWorkOverBudget(t *testing.T) {
r.Header.Set("Origin", keymailOrigin)
r.Header.Set("Sec-Fetch-Site", "same-origin")
r.RemoteAddr = "198.51.100." + strconv.Itoa(ip) + ":1234"
+ r = r.WithContext(context.WithValue(r.Context(), measuredKey{}, true))
for _, c := range cookies {
r.AddCookie(c)
}