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

     1  // Copyright 2018 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  	"regexp"
    16  )
    17  
    18  var psycopgReleaseTagRegex = regexp.MustCompile(`^(?P<major>\d+)(?:_(?P<minor>\d+)(?:_(?P<point>\d+)(?:_(?P<subpoint>\d+))?)?)?$`)
    19  
    20  // This test runs psycopg full test suite against a single cockroach node.
    21  
    22  func registerPsycopg(r *testRegistry) {
    23  	runPsycopg := func(
    24  		ctx context.Context,
    25  		t *test,
    26  		c *cluster,
    27  	) {
    28  		if c.isLocal() {
    29  			t.Fatal("cannot be run in local mode")
    30  		}
    31  		node := c.Node(1)
    32  		t.Status("setting up cockroach")
    33  		c.Put(ctx, cockroach, "./cockroach", c.All())
    34  		c.Start(ctx, t, c.All())
    35  
    36  		version, err := fetchCockroachVersion(ctx, c, node[0])
    37  		if err != nil {
    38  			t.Fatal(err)
    39  		}
    40  
    41  		if err := alterZoneConfigAndClusterSettings(ctx, version, c, node[0]); err != nil {
    42  			t.Fatal(err)
    43  		}
    44  
    45  		t.Status("cloning psycopg and installing prerequisites")
    46  		latestTag, err := repeatGetLatestTag(ctx, c, "psycopg", "psycopg2", psycopgReleaseTagRegex)
    47  		if err != nil {
    48  			t.Fatal(err)
    49  		}
    50  		c.l.Printf("Latest Psycopg release is %s.", latestTag)
    51  
    52  		if err := repeatRunE(
    53  			ctx, c, node, "update apt-get", `sudo apt-get -qq update`,
    54  		); err != nil {
    55  			t.Fatal(err)
    56  		}
    57  
    58  		if err := repeatRunE(
    59  			ctx,
    60  			c,
    61  			node,
    62  			"install dependencies",
    63  			`sudo apt-get -qq install make python3 libpq-dev python-dev gcc python3-setuptools python-setuptools`,
    64  		); err != nil {
    65  			t.Fatal(err)
    66  		}
    67  
    68  		if err := repeatRunE(
    69  			ctx, c, node, "remove old Psycopg", `sudo rm -rf /mnt/data1/psycopg`,
    70  		); err != nil {
    71  			t.Fatal(err)
    72  		}
    73  
    74  		if err := repeatGitCloneE(
    75  			ctx,
    76  			t.l,
    77  			c,
    78  			"https://github.com/psycopg/psycopg2.git",
    79  			"/mnt/data1/psycopg",
    80  			latestTag,
    81  			node,
    82  		); err != nil {
    83  			t.Fatal(err)
    84  		}
    85  
    86  		t.Status("building Psycopg")
    87  		if err := repeatRunE(
    88  			ctx, c, node, "building Psycopg", `cd /mnt/data1/psycopg/ && make`,
    89  		); err != nil {
    90  			t.Fatal(err)
    91  		}
    92  
    93  		blacklistName, expectedFailures, ignoredlistName, ignoredlist := psycopgBlacklists.getLists(version)
    94  		if expectedFailures == nil {
    95  			t.Fatalf("No psycopg blacklist defined for cockroach version %s", version)
    96  		}
    97  		if ignoredlist == nil {
    98  			t.Fatalf("No psycopg ignorelist defined for cockroach version %s", version)
    99  		}
   100  		c.l.Printf("Running cockroach version %s, using blacklist %s, using ignoredlist %s",
   101  			version, blacklistName, ignoredlistName)
   102  
   103  		t.Status("running psycopg test suite")
   104  		// Note that this is expected to return an error, since the test suite
   105  		// will fail. And it is safe to swallow it here.
   106  		rawResults, _ := c.RunWithBuffer(ctx, t.l, node,
   107  			`cd /mnt/data1/psycopg/ &&
   108  			export PSYCOPG2_TESTDB=defaultdb &&
   109  			export PSYCOPG2_TESTDB_USER=root &&
   110  			export PSYCOPG2_TESTDB_PORT=26257 &&
   111  			export PSYCOPG2_TESTDB_HOST=localhost &&
   112  			make check`,
   113  		)
   114  
   115  		t.Status("collating the test results")
   116  		c.l.Printf("Test Results: %s", rawResults)
   117  
   118  		// Find all the failed and errored tests.
   119  		results := newORMTestsResults()
   120  		results.parsePythonUnitTestOutput(rawResults, expectedFailures, ignoredlist)
   121  		results.summarizeAll(
   122  			t, "psycopg" /* ormName */, blacklistName, expectedFailures,
   123  			version, latestTag,
   124  		)
   125  	}
   126  
   127  	r.Add(testSpec{
   128  		Name:       "psycopg",
   129  		Owner:      OwnerAppDev,
   130  		Cluster:    makeClusterSpec(1),
   131  		MinVersion: "v19.1.0",
   132  		Tags:       []string{`default`, `driver`},
   133  		Run: func(ctx context.Context, t *test, c *cluster) {
   134  			runPsycopg(ctx, t, c)
   135  		},
   136  	})
   137  }