github.com/cockroachdb/cockroach@v20.2.0-alpha.1+incompatible/pkg/cmd/roachtest/libpq.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 libPQReleaseTagRegex = regexp.MustCompile(`^v(?P<major>\d+)\.(?P<minor>\d+)\.(?P<point>\d+)$`)
    20  
    21  func registerLibPQ(r *testRegistry) {
    22  	runLibPQ := func(ctx context.Context, t *test, c *cluster) {
    23  		if c.isLocal() {
    24  			t.Fatal("cannot be run in local mode")
    25  		}
    26  		node := c.Node(1)
    27  		t.Status("setting up cockroach")
    28  		c.Put(ctx, cockroach, "./cockroach", c.All())
    29  		c.Start(ctx, t, c.All())
    30  		version, err := fetchCockroachVersion(ctx, c, node[0])
    31  		if err != nil {
    32  			t.Fatal(err)
    33  		}
    34  		if err := alterZoneConfigAndClusterSettings(ctx, version, c, node[0]); err != nil {
    35  			t.Fatal(err)
    36  		}
    37  
    38  		t.Status("cloning lib/pq and installing prerequisites")
    39  		latestTag, err := repeatGetLatestTag(
    40  			ctx, c, "lib", "pq", libPQReleaseTagRegex)
    41  		if err != nil {
    42  			t.Fatal(err)
    43  		}
    44  		c.l.Printf("Latest lib/pq release is %s.", latestTag)
    45  
    46  		installLatestGolang(ctx, t, c, node)
    47  
    48  		const (
    49  			libPQRepo   = "github.com/lib/pq"
    50  			libPQPath   = goPath + "/src/" + libPQRepo
    51  			resultsDir  = "~/logs/report/libpq-results"
    52  			resultsPath = resultsDir + "/report.xml"
    53  		)
    54  
    55  		// Remove any old lib/pq installations
    56  		if err := repeatRunE(
    57  			ctx, c, node, "remove old lib/pq", fmt.Sprintf("rm -rf %s", libPQPath),
    58  		); err != nil {
    59  			t.Fatal(err)
    60  		}
    61  
    62  		// Install go-junit-report to convert test results to .xml format we know
    63  		// how to work with.
    64  		if err := repeatRunE(
    65  			ctx, c, node, "install go-junit-report", fmt.Sprintf("GOPATH=%s go get -u github.com/jstemmer/go-junit-report", goPath),
    66  		); err != nil {
    67  			t.Fatal(err)
    68  		}
    69  
    70  		if err := repeatGitCloneE(
    71  			ctx,
    72  			t.l,
    73  			c,
    74  			fmt.Sprintf("https://%s.git", libPQRepo),
    75  			libPQPath,
    76  			latestTag,
    77  			node,
    78  		); err != nil {
    79  			t.Fatal(err)
    80  		}
    81  
    82  		_ = c.RunE(ctx, node, fmt.Sprintf("mkdir -p %s", resultsDir))
    83  
    84  		blacklistName, expectedFailures, ignorelistName, ignoredFailures := libPQBlacklists.getLists(version)
    85  		if expectedFailures == nil {
    86  			t.Fatalf("No lib/pq blacklist defined for cockroach version %s", version)
    87  		}
    88  		c.l.Printf("Running cockroach version %s, using blacklist %s, using ignorelist %s", version, blacklistName, ignorelistName)
    89  
    90  		t.Status("running lib/pq test suite and collecting results")
    91  
    92  		// Ignore the error as there will be failing tests.
    93  		_ = c.RunE(
    94  			ctx,
    95  			node,
    96  			fmt.Sprintf("cd %s && PGPORT=26257 PGUSER=root PGSSLMODE=disable PGDATABASE=postgres go test -v 2>&1 | %s/bin/go-junit-report > %s", libPQPath, goPath, resultsPath),
    97  		)
    98  
    99  		parseAndSummarizeJavaORMTestsResults(
   100  			ctx, t, c, node, "lib/pq" /* ormName */, []byte(resultsPath),
   101  			blacklistName, expectedFailures, ignoredFailures, version, latestTag,
   102  		)
   103  	}
   104  
   105  	r.Add(testSpec{
   106  		Name:       "lib/pq",
   107  		Owner:      OwnerAppDev,
   108  		MinVersion: "v19.2.0",
   109  		Cluster:    makeClusterSpec(1),
   110  		Tags:       []string{`default`, `driver`},
   111  		Run:        runLibPQ,
   112  	})
   113  }