(t *testing.T)
| 162 | } |
| 163 | |
| 164 | func TestLargeObjectsMultipleTransactions(t *testing.T) { |
| 165 | // We use a very short limit to test chunking logic. |
| 166 | pgx.SetMaxLargeObjectMessageLength(t, 2) |
| 167 | |
| 168 | ctx, cancel := context.WithTimeout(context.Background(), 120*time.Second) |
| 169 | defer cancel() |
| 170 | |
| 171 | conn, err := pgx.Connect(ctx, os.Getenv("PGX_TEST_DATABASE")) |
| 172 | if err != nil { |
| 173 | t.Fatal(err) |
| 174 | } |
| 175 | |
| 176 | pgxtest.SkipCockroachDB(t, conn, "Server does support large objects") |
| 177 | |
| 178 | tx, err := conn.Begin(ctx) |
| 179 | if err != nil { |
| 180 | t.Fatal(err) |
| 181 | } |
| 182 | |
| 183 | lo := tx.LargeObjects() |
| 184 | |
| 185 | id, err := lo.Create(ctx, 0) |
| 186 | if err != nil { |
| 187 | t.Fatal(err) |
| 188 | } |
| 189 | |
| 190 | obj, err := lo.Open(ctx, id, pgx.LargeObjectModeWrite) |
| 191 | if err != nil { |
| 192 | t.Fatal(err) |
| 193 | } |
| 194 | |
| 195 | n, err := obj.Write([]byte("testing")) |
| 196 | if err != nil { |
| 197 | t.Fatal(err) |
| 198 | } |
| 199 | if n != 7 { |
| 200 | t.Errorf("Expected n to be 7, got %d", n) |
| 201 | } |
| 202 | |
| 203 | // Commit the first transaction |
| 204 | err = tx.Commit(ctx) |
| 205 | if err != nil { |
| 206 | t.Fatal(err) |
| 207 | } |
| 208 | |
| 209 | // IMPORTANT: Use the same connection for another query |
| 210 | query := `select n from generate_series(1,10) n` |
| 211 | rows, err := conn.Query(ctx, query) |
| 212 | if err != nil { |
| 213 | t.Fatal(err) |
| 214 | } |
| 215 | rows.Close() |
| 216 | |
| 217 | // Start a new transaction |
| 218 | tx2, err := conn.Begin(ctx) |
| 219 | if err != nil { |
| 220 | t.Fatal(err) |
| 221 | } |
nothing calls this directly
no test coverage detected