github.com/cockroachdb/cockroach@v20.2.0-alpha.1+incompatible/pkg/cmd/roachtest/pgx.go (about)

     1  // Copyright 2019 The Cockroach Authors.
     2  //
     3  // Use of this software is governed by the Business Source License
     4  // included in the file licenses/BSL.txt.
     5  //
     6  // As of the Change Date specified in that file, in accordance with
     7  // the Business Source License, use of this software will be governed
     8  // by the Apache License, Version 2.0, included in the file
     9  // licenses/APL.txt.
    10  
    11  package main
    12  
    13  import (
    14  	"context"
    15  	"fmt"
    16  	"regexp"
    17  )
    18  
    19  var pgxReleaseTagRegex = regexp.MustCompile(`^v(?P<major>\d+)\.(?P<minor>\d+)\.(?P<point>\d+)$`)
    20  
    21  // This test runs pgx's full test suite against a single cockroach node.
    22  
    23  func registerPgx(r *testRegistry) {
    24  	runPgx := func(
    25  		ctx context.Context,
    26  		t *test,
    27  		c *cluster,
    28  	) {
    29  		if c.isLocal() {
    30  			t.Fatal("cannot be run in local mode")
    31  		}
    32  		node := c.Node(1)
    33  		t.Status("setting up cockroach")
    34  		c.Put(ctx, cockroach, "./cockroach", c.All())
    35  		c.Start(ctx, t, c.All())
    36  
    37  		version, err := fetchCockroachVersion(ctx, c, node[0])
    38  		if err != nil {
    39  			t.Fatal(err)
    40  		}
    41  
    42  		if err := alterZoneConfigAndClusterSettings(ctx, version, c, node[0]); err != nil {
    43  			t.Fatal(err)
    44  		}
    45  
    46  		t.Status("setting up go")
    47  		installLatestGolang(ctx, t, c, node)
    48  
    49  		t.Status("installing pgx")
    50  		if err := repeatRunE(
    51  			ctx, c, node, "install pgx", "go get -u github.com/jackc/pgx",
    52  		); err != nil {
    53  			t.Fatal(err)
    54  		}
    55  
    56  		latestTag, err := repeatGetLatestTag(ctx, c, "jackc", "pgx", pgxReleaseTagRegex)
    57  		if err != nil {
    58  			t.Fatal(err)
    59  		}
    60  		c.l.Printf("Latest jackc/pgx release is %s.", latestTag)
    61  
    62  		t.Status("installing go-junit-report")
    63  		if err := repeatRunE(
    64  			ctx, c, node, "install pgx", "go get -u github.com/jstemmer/go-junit-report",
    65  		); err != nil {
    66  			t.Fatal(err)
    67  		}
    68  
    69  		t.Status("checking blacklist")
    70  		blacklistName, expectedFailures, ignorelistName, ignorelist := pgxBlacklists.getLists(version)
    71  		if expectedFailures == nil {
    72  			t.Fatalf("No pgx blacklist defined for cockroach version %s", version)
    73  		}
    74  		status := fmt.Sprintf("Running cockroach version %s, using blacklist %s", version, blacklistName)
    75  		if ignorelist != nil {
    76  			status = fmt.Sprintf("Running cockroach version %s, using blacklist %s, using ignorelist %s",
    77  				version, blacklistName, ignorelistName)
    78  		}
    79  		c.l.Printf("%s", status)
    80  
    81  		t.Status("setting up test db")
    82  		db, err := c.ConnE(ctx, node[0])
    83  		if err != nil {
    84  			t.Fatal(err)
    85  		}
    86  		defer db.Close()
    87  		if _, err = db.ExecContext(
    88  			ctx, `drop database if exists pgx_test; create database pgx_test;`,
    89  		); err != nil {
    90  			t.Fatal(err)
    91  		}
    92  
    93  		// This is expected to fail because the feature is unsupported by Cockroach, but pgx expects it.
    94  		// https://github.com/cockroachdb/cockroach/issues/27796
    95  		_, _ = db.ExecContext(
    96  			ctx, `create domain uint64 as numeric(20,0);`,
    97  		)
    98  
    99  		t.Status("running pgx test suite")
   100  		// Running the test suite is expected to error out, so swallow the error.
   101  		xmlResults, _ := repeatRunWithBuffer(
   102  			ctx, c, t.l, node,
   103  			"run pgx test suite",
   104  			"cd `go env GOPATH`/src/github.com/jackc/pgx && "+
   105  				"PGX_TEST_DATABASE='postgresql://root:@localhost:26257/pgx_test' go test -v 2>&1 | "+
   106  				"`go env GOPATH`/bin/go-junit-report",
   107  		)
   108  
   109  		results := newORMTestsResults()
   110  		results.parseJUnitXML(t, expectedFailures, ignorelist, xmlResults)
   111  		results.summarizeAll(
   112  			t, "pgx", blacklistName, expectedFailures, version, latestTag,
   113  		)
   114  	}
   115  
   116  	r.Add(testSpec{
   117  		Name:       "pgx",
   118  		Owner:      OwnerAppDev,
   119  		Cluster:    makeClusterSpec(1),
   120  		MinVersion: "v19.2.0",
   121  		Tags:       []string{`default`, `driver`},
   122  		Run: func(ctx context.Context, t *test, c *cluster) {
   123  			runPgx(ctx, t, c)
   124  		},
   125  	})
   126  }