MCPcopy
hub / github.com/jackc/pgx / TestLargeObjectsMultipleTransactions

Function TestLargeObjectsMultipleTransactions

large_objects_test.go:164–306  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

162}
163
164func 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 }

Callers

nothing calls this directly

Calls 15

SkipCockroachDBFunction · 0.92
CreateMethod · 0.80
SeekMethod · 0.80
TellMethod · 0.80
TruncateMethod · 0.80
UnlinkMethod · 0.80
BeginMethod · 0.65
LargeObjectsMethod · 0.65
CommitMethod · 0.65
QueryMethod · 0.65
CloseMethod · 0.65
ConnectMethod · 0.45

Tested by

no test coverage detected