| index d039231e5..b57b98f16 100644 |
| --- a/dbforward_e2e_test.go |
| +++ b/dbforward_e2e_test.go |
| @@ -699,3 +699,87 @@ func TestDBForwardRefusesSQLThatIsNotUTF8(t *testing.T) { |
| t.Fatalf("a query JSON would rewrite reached the bucket: %v", keys) |
| } |
| } |
| + |
| +// throughBackhaul serves the console's handler with console.NewHTTPServer |
| +// (its ReadTimeout set to readTimeout) on 127.0.0.1, behind two real edges |
| +// that package edge's test binary runs as a helper process: the CLI reaches |
| +// betty, which backhauls to annie, the console's home. The CLI finds betty |
| +// through a CONNECT proxy (a dbfTap, standing in for DNS) and trusts the |
| +// edges' test CA through SSL_CERT_FILE. Building the helper needs the go |
| +// command on PATH, as every CI step has. |
| +func throughBackhaul(readTimeout time.Duration, tap **dbfTap) func(t *testing.T, h http.Handler) (string, []string) { |
| + return func(t *testing.T, h http.Handler) (string, []string) { |
| + ln, err := net.Listen("tcp", "127.0.0.1:0") |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + hs := console.NewHTTPServer(h) |
| + hs.ReadTimeout = readTimeout |
| + go hs.Serve(ln) |
| + t.Cleanup(func() { hs.Close() }) |
| + dir := t.TempDir() |
| + bin := filepath.Join(dir, "edge.test") |
| + // From the module root with the environment TestMain kept for the |
| + // carlos build (the real HOME and Go cache), as sharedCarlos builds. |
| + build := exec.Command("go", "test", "-c", "-o", bin, "./internal/edge") |
| + build.Dir, build.Env = moduleRoot, carlosBuildEnv |
| + if out, err := build.CombinedOutput(); err != nil { |
| + t.Fatalf("build the edge test binary: %v\n%s", err, out) |
| + } |
| + cmd := exec.Command(bin, "-test.run", "^TestDBForwardBackhaulPairHelper$", "-test.v") |
| + cmd.Env = append(os.Environ(), "DBF_BACKHAUL_HELPER=1", "DBF_BACKHAUL_UPSTREAM="+ln.Addr().String(), "DBF_BACKHAUL_DIR="+dir) |
| + stdin, err := cmd.StdinPipe() |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + pr, pw := io.Pipe() |
| + cmd.Stdout = pw |
| + var helperErr bytes.Buffer |
| + cmd.Stderr = &helperErr |
| + if err := cmd.Start(); err != nil { |
| + t.Fatal(err) |
| + } |
| + t.Cleanup(func() { |
| + stdin.Close() |
| + cmd.Wait() |
| + pw.Close() |
| + if t.Failed() { |
| + t.Logf("backhaul helper stderr:\n%s", helperErr.String()) |
| + } |
| + }) |
| + lines := bufio.NewScanner(pr) |
| + sender := "" |
| + for lines.Scan() { |
| + if addr, ok := strings.CutPrefix(lines.Text(), "DBF-BACKHAUL "); ok { |
| + sender = addr |
| + break |
| + } |
| + } |
| + if sender == "" { |
| + t.Fatalf("the backhaul helper never came up:\n%s", helperErr.String()) |
| + } |
| + go func() { |
| + for lines.Scan() { |
| + } |
| + }() |
| + tp := newDBFTap(t, sender, true) |
| + *tap = tp |
| + return "https://console.backhaul.test", []string{"HTTPS_PROXY=http://" + tp.addr, "NO_PROXY=", "SSL_CERT_FILE=" + filepath.Join(dir, "ca.pem")} |
| + } |
| +} |
| + |
| +// T7, the backhaul half, end to end (plan review finding 34): the real CLI |
| +// binary reaches the real console through two real edges, the second hop a |
| +// backhaul with its 30 s header bound, during a 40 s quiet restore. At the |
| +// CLI's own stderr and socket: DBF-11 within a second, no silence over 16 s, |
| +// and its rows after more than the hop's 30 s. The console's real |
| +// http.Server runs with ReadTimeout 2 s, as in |
| +// TestDBForwardLongRequestThroughTheEdge. |
| +// Mutations: drop the stream's flush (red: the wait lines sit in the |
| +// console's buffer and the CLI's socket is silent); stream nothing before |
| +// the box's first chunk (red: no headers inside the hop's 30 s). |
| +func TestDBForwardThroughTheBackhaulHop(t *testing.T) { |
| + var tap *dbfTap |
| + e := newDBFE2E(t, dbfE2EOptions{forward: true, serve: throughBackhaul(2*time.Second, &tap), worker: slowRestore(40 * time.Second)}) |
| + checkProgressAtTheCLI(t, e, tap, 40*time.Second) |
| +} |