carlos / platform Public

console stop tests: synctest for the relay join, honest GOMAXPROCS note

Astra scoped check on a2e41dfe (passed; one P2 in a test):
TestStartRelayJoinsItsWriterLoop could pass against a StartRelay that
does not join, if its main goroutine was delayed for the whole 200 ms
window. It now runs in a testing/synctest bubble with the held store's
channels made inside it: after the cancel, synctest.Wait returns only
once StartRelay has either returned or parked on the writer, so the
check is exact. Watched failing with defer writer.Wait() removed.

The comment on TestConsoleStopQueuedSecondSignalBeforeRelease no longer
claims GOMAXPROCS(1) prevents preemption.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev pushed by paul@keymail.dev a7488581b629441d96b4917f6954a644306e10ea parent a60c26f
2 files changed, +34 −31
  • cmd/console/stop_test.go +4 −3
  • internal/console/workerjoin_test.go +30 −28

CI cancelled — superseded by a newer push — run details

diff --git a/cmd/console/stop_test.go b/cmd/console/stop_test.go
index 3c58b5873..a36964cd3 100644
--- a/cmd/console/stop_test.go
+++ b/cmd/console/stop_test.go
@@ -432,9 +432,10 @@ func testWorkers(t *testing.T) *workers {
}
// A second signal already queued when the waits have all finished is taken
-// at the release decision: no release, exit status 1. GOMAXPROCS(1) keeps
-// any other goroutine from running before stop's first block, which made
-// the old asynchronous watcher lose this race every time.
+// at the release decision: no release, exit status 1. The new stop takes it
+// there whatever the scheduling. GOMAXPROCS(1) only makes it likely, not
+// certain (the scheduler can still preempt), that the old asynchronous
+// watcher had not run by then, which is how this test caught the old race.
func TestConsoleStopQueuedSecondSignalBeforeRelease(t *testing.T) {
defer runtimeGOMAXPROCS(1)()
r := newBareStopRig(t, time.Minute, time.Minute, time.Minute)
diff --git a/internal/console/workerjoin_test.go b/internal/console/workerjoin_test.go
index ab1aabc96..f0421036f 100644
--- a/internal/console/workerjoin_test.go
+++ b/internal/console/workerjoin_test.go
@@ -5,6 +5,7 @@ import (
"errors"
"sync"
"testing"
+ "testing/synctest"
"time"
"github.com/carlosframework/platform/internal/release"
@@ -27,36 +28,37 @@ func (h *heldGetStore) Get(ctx context.Context, key string) ([]byte, string, err
// StartRelay returns only after its writer-lease loop has: cmd/console's
// stop waits for StartRelay, so a lease loop it left behind would run on
-// past the stop's join and never be named.
+// past the stop's join and never be named. In a synctest bubble (the held
+// store's channels are made inside it), synctest.Wait returns once every
+// goroutine is durably blocked, so after the cancel StartRelay has either
+// returned or is parked waiting for the writer, whatever the scheduling.
func TestStartRelayJoinsItsWriterLoop(t *testing.T) {
- st := &heldGetStore{Store: release.NewDirStore(t.TempDir()), entered: make(chan struct{}), unblock: make(chan struct{})}
- s := &Server{cfg: Config{Releases: st, RelayRegions: []string{"eu-west-1"}}}
- ctx, cancel := context.WithCancel(context.Background())
- returned := make(chan struct{})
- go func() {
- defer close(returned)
- s.StartRelay(ctx)
- }()
- select {
- case <-st.entered:
- case <-time.After(30 * time.Second):
- t.Fatal("the writer loop never read the lease")
- }
- cancel()
- // Proving that something does NOT return needs a window: the main loop
- // returns within milliseconds of the cancel when it does not join.
- select {
- case <-returned:
+ synctest.Test(t, func(t *testing.T) {
+ st := &heldGetStore{Store: release.NewDirStore(t.TempDir()), entered: make(chan struct{}), unblock: make(chan struct{})}
+ s := &Server{cfg: Config{Releases: st, RelayRegions: []string{"eu-west-1"}}}
+ ctx, cancel := context.WithCancel(context.Background())
+ returned := make(chan struct{})
+ go func() {
+ defer close(returned)
+ s.StartRelay(ctx)
+ }()
+ synctest.Wait()
+ select {
+ case <-st.entered:
+ default:
+ t.Fatal("the writer loop never read the lease")
+ }
+ cancel()
+ synctest.Wait()
+ select {
+ case <-returned:
+ close(st.unblock)
+ t.Fatal("StartRelay returned while its writer loop was still in a store call")
+ default:
+ }
close(st.unblock)
- t.Fatal("StartRelay returned while its writer loop was still in a store call")
- case <-time.After(200 * time.Millisecond):
- }
- close(st.unblock)
- select {
- case <-returned:
- case <-time.After(30 * time.Second):
- t.Fatal("StartRelay did not return once its writer loop could")
- }
+ <-returned // a StartRelay that never returns is a bubble deadlock, which fails the test
+ })
}
// StartVerifyReader's channel closes when its tick goroutine ends, and at