CodeSampleX

Beispiel

github.com/jackc/puddle v1.3.0: ErrClosedPool

Verifiziertes Beispiel für golang github.com/jackc/puddle v1.3.0: ErrClosedPool. Der Vertrag lief auf go 1.26 · linux debian/x64 · docker und bestand.

sha256:4a8544d4162176e443069f94ac0111a9d16e449f0da6aac0ddd1842c1f1315af

Dieses Netzwerk bietet eine Sache: ein Sample, das baut. Es hat es in einer Sandbox ausgeführt und die signierte Quittung behalten. Es bewertet nichts und garantiert nichts — ob derselbe Code bei Ihnen baut, hat es nicht gemessen. Wie viele verschiedene Signaturschlüssel eine bestandene Vertragsquittung eingereicht haben. Einer ist der Autor allein; mehr als einer heißt, jemand anderes hat es auch gebaut. Ein Schlüssel wird selbst erzeugt und hat keine registrierte Identität dahinter — gezählt werden Schlüssel, nicht Personen. MIT-0

Ausführungsbelege

Die deklarierte Umgebung und die signierten Läufe stehen getrennt, damit Sie genau sehen, was dieses Sample ausgeführt hat und wo.

Beleggrundlage
Signierter Vertrag bestanden
Verifizierungsbelege
1
Signaturschlüssel, die es gebaut haben
1
Deklarierte Umgebung go 1.26 linux 24 · ubuntu · glibc 2.39 x64 go 1.26 go go 1

Umgebungen der Verifizierungsläufe

Umgebung Contract Stufen Lauf
go 1.26 · linux debian/x64 · docker ed25519:c1973797be207ac4 PASS compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · golang@1golang:1.26@sha256:e30143be198a…
2026-09-16

Fall

HOW
Ziel
verify github.com/jackc/puddle.ErrClosedPool in pkg:golang/github.com/jackc/puddle@v1.3.0
Pakete
Symbole
  • github.com/jackc/puddle.ErrClosedPool
Umgebung
go 1.26.6
Erstellt
2026-09-16T21:53:23Z

Contract

  1. puddle.ErrClosedPool has error message "closed pool"
  2. Acquire returns puddle.ErrClosedPool when called on a closed pool
  3. TryAcquire returns puddle.ErrClosedPool when called on a closed pool
  4. CreateResource returns puddle.ErrClosedPool when called on a closed pool
  5. errors.Is matches puddle.ErrClosedPool returned by closed pool operations

Dateien

  • PROMPT.md
  • csx.json
  • go.mod
  • go.sum
  • main.go
  • spec.json
  • test/contract.go

Quellartefakt herunterladen (tar.gz)

Quelltext

PROMPT.md
Clean-room public code sample — generation instructions

Write a brand-new, minimal, self-contained code sample in this clean-room directory.
Do not copy, paraphrase, or reference any existing project source. Work only from this spec.

A csx.json manifest scaffold already exists. Do not recreate it from memory. Preserve its case.goal, packages and symbols; fill its empty case.contract with exact assertions and correct its environment, commands and verifierAdapter for the files you generate.

Goal: verify github.com/jackc/puddle.ErrClosedPool in pkg:golang/github.com/jackc/puddle@v1.3.0
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:golang/github.com/jackc/puddle@v1.3.0
Demonstrate these symbols/APIs:
  - github.com/jackc/puddle.ErrClosedPool

Rules:
  - One focused purpose; the smallest project that proves the goal.
  - Include a contract test (test/contract.*) that runs OFFLINE and exits 0 exactly when the goal behavior works.
  - Pin every dependency with a lockfile so resolution is reproducible.
  - No secrets, credentials, or tokens. No real URLs (only example.com or localhost). No absolute paths.
  - No personal names, emails, company names, or project identifiers of any kind.
  - No binaries and no generated output (node_modules, dist, target, venv, .git, .env).
  - Keep it under 200 files and 256KB packed.
csx.json
{"case":{"caseId":"case:sha256:246e380d000b3e8e964b892c467af6f8c522a4b5e474ae31b8d738aec31533cf","contract":["puddle.ErrClosedPool has error message \"closed pool\"","Acquire returns puddle.ErrClosedPool when called on a closed pool","TryAcquire returns puddle.ErrClosedPool when called on a closed pool","CreateResource returns puddle.ErrClosedPool when called on a closed pool","errors.Is matches puddle.ErrClosedPool returned by closed pool operations"],"goal":"verify github.com/jackc/puddle.ErrClosedPool in pkg:golang/github.com/jackc/puddle@v1.3.0","kind":"HOW","packages":["pkg:golang/github.com/jackc/puddle@v1.3.0"],"schemaVersion":1,"symbols":["github.com/jackc/puddle.ErrClosedPool"]},"contractCommand":["go","run","./test"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"golang","language":"go","libc":"glibc","libcVersion":"2.39","os":"linux","osVersionBucket":"24","packageManager":"go","packageManagerVersion":"1.26.6","runtime":"go","runtimeVersion":"1.26.6","schemaVersion":1},"license":"MIT-0","packages":["pkg:golang/github.com/jackc/puddle@v1.3.0"],"schemaVersion":1,"subject":"pkg:golang/github.com/jackc/puddle@v1.3.0","symbols":["github.com/jackc/puddle.ErrClosedPool"],"verifierAdapter":"golang@1"}
go.mod
module sample

go 1.26.6

require github.com/jackc/puddle v1.3.0
go.sum
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/jackc/puddle v1.3.0 h1:eHK/5clGOatcjX3oWGBO/MpxpbHzSwud5EWTSCI+MX0=
github.com/jackc/puddle v1.3.0/go.mod h1:m4B5Dj62Y0fbyuIc15OsIqK0+JU8nkqQjsgx7dvjSWk=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
main.go
package main

import (
	"context"
	"errors"
	"fmt"

	"github.com/jackc/puddle"
)

func main() {
	ctx := context.Background()

	// Initialize a puddle resource pool with a simple constructor and destructor
	constructor := func(ctx context.Context) (interface{}, error) {
		return "database-conn", nil
	}
	destructor := func(res interface{}) {}

	pool := puddle.NewPool(constructor, destructor, 5)

	// Demonstrate normal resource acquisition before closing
	res, err := pool.Acquire(ctx)
	if err != nil {
		fmt.Printf("failed to acquire resource: %v\n", err)
		return
	}
	fmt.Printf("successfully acquired resource: %v\n", res.Value())
	res.Release()

	// Close the pool
	pool.Close()

	// Demonstrate that acquiring from a closed pool returns ErrClosedPool
	_, err = pool.Acquire(ctx)
	if errors.Is(err, puddle.ErrClosedPool) {
		fmt.Printf("Acquire after Close returned expected error: %v\n", err)
	}

	// Demonstrate that TryAcquire also returns ErrClosedPool
	_, err = pool.TryAcquire(ctx)
	if errors.Is(err, puddle.ErrClosedPool) {
		fmt.Printf("TryAcquire after Close returned expected error: %v\n", err)
	}
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify github.com/jackc/puddle.ErrClosedPool in pkg:golang/github.com/jackc/puddle@v1.3.0",
  "kind": "HOW",
  "packages": [
    "pkg:golang/github.com/jackc/puddle@v1.3.0"
  ],
  "symbols": [
    "github.com/jackc/puddle.ErrClosedPool"
  ]
}
test/contract.go
package main

import (
	"context"
	"errors"
	"fmt"
	"os"

	"github.com/jackc/puddle"
)

func main() {
	ctx := context.Background()

	newTestPool := func() *puddle.Pool {
		return puddle.NewPool(
			func(ctx context.Context) (interface{}, error) {
				return "test-resource", nil
			},
			func(res interface{}) {},
			2,
		)
	}

	// Assertion 1: puddle.ErrClosedPool has error message "closed pool"
	{
		if puddle.ErrClosedPool == nil {
			fmt.Fprintf(os.Stderr, "assertion 1 failed: puddle.ErrClosedPool must not be nil\n")
			os.Exit(1)
		}
		if puddle.ErrClosedPool.Error() != "closed pool" {
			fmt.Fprintf(os.Stderr, "assertion 1 failed: expected error string 'closed pool', got '%s'\n", puddle.ErrClosedPool.Error())
			os.Exit(1)
		}
	}

	// Assertion 2: Acquire returns puddle.ErrClosedPool when called on a closed pool
	{
		pool := newTestPool()
		pool.Close()

		res, err := pool.Acquire(ctx)
		if res != nil {
			fmt.Fprintf(os.Stderr, "assertion 2 failed: expected nil resource from closed pool Acquire\n")
			os.Exit(1)
		}
		if !errors.Is(err, puddle.ErrClosedPool) {
			fmt.Fprintf(os.Stderr, "assertion 2 failed: expected ErrClosedPool, got: %v\n", err)
			os.Exit(1)
		}
	}

	// Assertion 3: TryAcquire returns puddle.ErrClosedPool when called on a closed pool
	{
		pool := newTestPool()
		pool.Close()

		res, err := pool.TryAcquire(ctx)
		if res != nil {
			fmt.Fprintf(os.Stderr, "assertion 3 failed: expected nil resource from closed pool TryAcquire\n")
			os.Exit(1)
		}
		if !errors.Is(err, puddle.ErrClosedPool) {
			fmt.Fprintf(os.Stderr, "assertion 3 failed: expected ErrClosedPool, got: %v\n", err)
			os.Exit(1)
		}
	}

	// Assertion 4: CreateResource returns puddle.ErrClosedPool when called on a closed pool
	{
		pool := newTestPool()
		pool.Close()

		err := pool.CreateResource(ctx)
		if !errors.Is(err, puddle.ErrClosedPool) {
			fmt.Fprintf(os.Stderr, "assertion 4 failed: expected ErrClosedPool from CreateResource, got: %v\n", err)
			os.Exit(1)
		}
	}

	// Assertion 5: errors.Is matches puddle.ErrClosedPool returned by closed pool operations
	{
		pool := newTestPool()
		pool.Close()

		_, errAcquire := pool.Acquire(ctx)
		_, errTryAcquire := pool.TryAcquire(ctx)
		errCreate := pool.CreateResource(ctx)

		if !errors.Is(errAcquire, puddle.ErrClosedPool) {
			fmt.Fprintf(os.Stderr, "assertion 5 failed: errAcquire does not match ErrClosedPool\n")
			os.Exit(1)
		}
		if !errors.Is(errTryAcquire, puddle.ErrClosedPool) {
			fmt.Fprintf(os.Stderr, "assertion 5 failed: errTryAcquire does not match ErrClosedPool\n")
			os.Exit(1)
		}
		if !errors.Is(errCreate, puddle.ErrClosedPool) {
			fmt.Fprintf(os.Stderr, "assertion 5 failed: errCreate does not match ErrClosedPool\n")
			os.Exit(1)
		}
	}

	fmt.Println("All contract assertions passed successfully.")
}

Ursprungs-Seeder

anonym