Files
mesh-catalog/modules/postgres/cmd/postgres-provider/moved_test.go
T
jschoubben b3fcf408f2 Make tests that wait for concurrent work wait on the event or a condition with a long deadline (issue 1814)
A test that slept a fixed time and then asserted what a goroutine, process or
watcher did failed under the checker's load. Each now waits for its positive
evidence (a started baseline, a call counted, a state reached) within 30 s, and
the concurrency-limit tests meet at a barrier instead of overlapping by sleep.

Claude-Session: https://claude.ai/code/session_01NcbgfJ9Gum47zkFKWRaovL
2026-11-01 17:24:19 +01:00

55 lines
1.5 KiB
Go

package main
import (
"os"
"path/filepath"
"testing"
"time"
)
// postgres's own part of the moved path (issue 849): the shared driving of it is proven in the SDK's harness package.
// Where the file is not there, postgres takes the grant directory, as before; where it is, the helper.
func TestTheGrantPathIsTakenWhereTheConsumersFileIsAbsent(t *testing.T) {
dir := t.TempDir()
at := filepath.Join(dir, "consumers.json")
env := func(k string) string {
if k == "MESH_CONSUMERS_FILE" {
return at
}
return ""
}
if got := handedConsumersFile(env, os.Stat); got != "" {
t.Fatalf("took %q for a file that is not there", got)
}
if got := handedConsumersFile(func(string) string { return "" }, os.Stat); got != "" {
t.Fatalf("took %q with no environment", got)
}
if err := os.WriteFile(at, []byte("[]"), 0o600); err != nil {
t.Fatal(err)
}
if got := handedConsumersFile(env, os.Stat); got != at {
t.Fatalf("took %q, want %q", got, at)
}
}
// The grant path restarts itself when the consumers file is first filled.
func TestTheGrantPathLeavesWhenTheConsumersFileIsFilled(t *testing.T) {
at := filepath.Join(t.TempDir(), "consumers.json")
done := make(chan struct{})
go exitWhenFilled(at, os.Stat, time.Millisecond, func() { close(done) })
select {
case <-done:
t.Fatal("left before the file was there")
case <-time.After(20 * time.Millisecond):
}
if err := os.WriteFile(at, []byte("[]"), 0o600); err != nil {
t.Fatal(err)
}
select {
case <-done:
case <-time.After(30 * time.Second):
t.Fatal("did not leave when the file was filled")
}
}