droboticflow/internal/api/query_periodic_fixture_test.go

56 lines
2.1 KiB
Go

package api
import (
"encoding/json"
"os"
"os/exec"
"strings"
"testing"
)
// A separate opt-in for same-size LOCAL synthetic HTTP comparison. It cannot
// waive the owned marker / node guards of the company-cluster harness.
func verifyPeriodicLocalHTTPFixture(t *testing.T) {
t.Helper()
if os.Getenv("QUERY_REPLICA_CLUSTER_TEST") != "" || os.Getenv("QUERY_REPLICA_TEST_TARGET_URI") != "" || os.Getenv("QUERY_COMPARE_IN_CLUSTER") != "" {
t.Fatal("local comparison cannot select a cluster/alternate URI")
}
endpoint, err := exec.Command("docker", "context", "inspect", "--format", "{{.Endpoints.docker.Host}}").Output()
if err != nil || !strings.HasPrefix(strings.TrimSpace(string(endpoint)), "unix://") {
t.Fatal("owned local Docker socket required")
}
for _, name := range []string{"source", "query"} {
raw, err := exec.Command("docker", "inspect", "fanyu-query-replica-local-"+name+"-1").Output()
if err != nil {
t.Fatal("local Mongo fixture unavailable")
}
var d []struct {
State struct{ Running bool }
Config struct {
Labels map[string]string
Cmd []string
}
HostConfig struct {
NanoCpus int64
Memory int64
PortBindings map[string][]struct{ HostIp, HostPort string }
}
}
if json.Unmarshal(raw, &d) != nil || len(d) != 1 || !d[0].State.Running || d[0].Config.Labels["com.docker.compose.project"] != "fanyu-query-replica-local" {
t.Fatal("unowned synthetic container")
}
cpu, memory, port := int64(4e9), int64(4<<30), "27119"
if name == "query" {
cpu, memory, port = 1e9, 1<<30, "27129"
}
bindings := d[0].HostConfig.PortBindings[port+"/tcp"]
if d[0].HostConfig.NanoCpus != cpu || d[0].HostConfig.Memory != memory || len(bindings) != 1 || bindings[0].HostIp != "127.0.0.1" || bindings[0].HostPort != port {
t.Fatal("local fixture resources or loopback binding changed")
}
command := " " + strings.Join(d[0].Config.Cmd, " ")
if !strings.Contains(command, " --port "+port) || (name == "query" && (!strings.Contains(command, " --replSet query-read-rs") || !strings.Contains(command, " --wiredTigerCacheSizeGB 0.25"))) {
t.Fatal("synthetic Mongo command/cache identity changed")
}
}
}