MCPcopy Create free account
hub / github.com/PostHog/duckgres / TestJDBCVersionQuery

Function TestJDBCVersionQuery

tests/integration/jdbc_test.go:33–93  ·  view source on GitHub ↗

TestJDBCVersionQuery tests SELECT version() via extended query protocol, which is the pattern JDBC/Metabase uses on connection and that hangs sporadically.

(t *testing.T)

Source from the content-addressed store, hash-verified

31// TestJDBCVersionQuery tests SELECT version() via extended query protocol,
32// which is the pattern JDBC/Metabase uses on connection and that hangs sporadically.
33func TestJDBCVersionQuery(t *testing.T) {
34 ctx := context.Background()
35
36 t.Run("simple_version", func(t *testing.T) {
37 conn := pgxConnect(t)
38 defer func() { _ = conn.Close(ctx) }()
39
40 var ver string
41 err := conn.QueryRow(ctx, "SELECT version()").Scan(&ver)
42 if err != nil {
43 t.Fatalf("SELECT version() failed: %v", err)
44 }
45 if ver == "" {
46 t.Error("version() returned empty string")
47 }
48 t.Logf("version() = %s", ver)
49 })
50
51 t.Run("version_with_timeout", func(t *testing.T) {
52 conn := pgxConnect(t)
53 defer func() { _ = conn.Close(ctx) }()
54
55 tctx, cancel := context.WithTimeout(ctx, 5*time.Second)
56 defer cancel()
57
58 var ver string
59 err := conn.QueryRow(tctx, "SELECT version()").Scan(&ver)
60 if err != nil {
61 t.Fatalf("SELECT version() timed out or failed: %v", err)
62 }
63 })
64
65 t.Run("repeated_version_same_connection", func(t *testing.T) {
66 conn := pgxConnect(t)
67 defer func() { _ = conn.Close(ctx) }()
68
69 for i := 0; i < 50; i++ {
70 tctx, cancel := context.WithTimeout(ctx, 5*time.Second)
71 var ver string
72 err := conn.QueryRow(tctx, "SELECT version()").Scan(&ver)
73 cancel()
74 if err != nil {
75 t.Fatalf("Iteration %d: SELECT version() failed: %v", i, err)
76 }
77 }
78 })
79
80 t.Run("repeated_version_new_connections", func(t *testing.T) {
81 for i := 0; i < 20; i++ {
82 conn := pgxConnect(t)
83 tctx, cancel := context.WithTimeout(ctx, 5*time.Second)
84 var ver string
85 err := conn.QueryRow(tctx, "SELECT version()").Scan(&ver)
86 cancel()
87 _ = conn.Close(ctx)
88 if err != nil {
89 t.Fatalf("Connection %d: SELECT version() failed: %v", i, err)
90 }

Callers

nothing calls this directly

Calls 5

pgxConnectFunction · 0.85
RunMethod · 0.65
CloseMethod · 0.65
ScanMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected