Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
63831: roachtest: add roachtest against pg ruby driver r=rafiss a=RichardJCai

roachtest: add roachtest against pg ruby driver

Release note: None

Resolves #62472

64732: bazel: upgrade to bazel 4.0.0 in the builder image r=rail a=rickystewart

This will allow us to pick up the latest version of `rules_foreign_cc`,
(for example, for #64334) which doesn't build with an earlier bazel
(#64709). Also make sure the version assertion in `WORKSPACE` is
up-to-date.

Release note: None

64745: bazel: use a wildcard instead of listing every stringer file for gazelle r=rail a=rickystewart

This excludes a single non-stringer file,
`pkg/sql/sem/tree/parse_string.go`, so re-include it and mark it
`# keep`.

Release note: None

64766: sql: fix the session tracing in some cases r=yuzefovich a=yuzefovich

When the session tracing is started, we might need to start two tracing
spans: we always start a span for the connection, but also if we're
inside of a txn, we start a separate span for the txn. Previously, the
span of the previous txn wasn't properly cleaned up when the session
tracing is started again outside of a txn, which resulted in old
(irrelevant) entries being added to the newer trace. Now this is fixed.

Additionally, this commit makes sure to finish the tracing spans (which
wasn't done previously).

Fixes: #59203.
Fixes: #60672.

Release note (bug fix): Previously, the session trace (i.e.
`SHOW TRACE FOR SESSION`) could contain entries that corresponded to the previous
trace (i.e. `SET TRACING=ON` didn't properly reset the trace). Now this
is fixed.

64775: changefeedccl: add test for disabled outbound IO r=HonoreDB a=stevendanna

This adds a test to ensure that we do not allow sinkful changefeeds to
be started when the --external-io-disabled flag has been set.

Note that this only tests a single node setup. For the flag to be
effective, it needs to be set on all nodes in a cluster.

Release note: None

Co-authored-by: richardjcai <[email protected]>
Co-authored-by: Ricky Stewart <[email protected]>
Co-authored-by: Yahor Yuzefovich <[email protected]>
Co-authored-by: Steven Danna <[email protected]>
  • Loading branch information
5 people committed May 6, 2021
6 parents dee0558 + 2053f17 + 88bb41d + 8a5865b + 3568d74 + c8c1404 commit 84c450e
Show file tree
Hide file tree
Showing 17 changed files with 914 additions and 83 deletions.
41 changes: 1 addition & 40 deletions BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -86,46 +86,7 @@ load("@bazel_gazelle//:def.bzl", "gazelle")
# gazelle:exclude vendor
# gazelle:exclude pkg/security/securitytest/embedded.go
# gazelle:exclude pkg/cmd/roachprod/vm/aws/embedded.go
# gazelle:exclude pkg/base/testclusterreplicationmode_string.go
# gazelle:exclude pkg/ccl/sqlproxyccl/errorcode_string.go
# gazelle:exclude pkg/cli/keytype_string.go
# gazelle:exclude pkg/clusterversion/key_string.go
# gazelle:exclude pkg/kv/kvclient/kvcoord/txnstate_string.go
# gazelle:exclude pkg/kv/kvserver/closedts/sidetransport/cantclosereason_string.go
# gazelle:exclude pkg/kv/kvserver/refreshraftreason_string.go
# gazelle:exclude pkg/roachpb/errordetailtype_string.go
# gazelle:exclude pkg/roachpb/method_string.go
# gazelle:exclude pkg/sql/advancecode_string.go
# gazelle:exclude pkg/sql/catalog/catalogkv/descriptorkind_string.go
# gazelle:exclude pkg/sql/catalog/descpb/formatversion_string.go
# gazelle:exclude pkg/sql/catalog/descpb/privilegedescversion_string.go
# gazelle:exclude pkg/sql/colfetcher/fetcherstate_string.go
# gazelle:exclude pkg/sql/execinfra/consumerstatus_string.go
# gazelle:exclude pkg/sql/execinfra/procstate_string.go
# gazelle:exclude pkg/sql/nodestatus_string.go
# gazelle:exclude pkg/sql/opt/optgen/lang/operator_string.go
# gazelle:exclude pkg/sql/opt/optgen/lang/token_string.go
# gazelle:exclude pkg/sql/opt/rule_name_string.go
# gazelle:exclude pkg/sql/pgwire/pgwirebase/clientmessagetype_string.go
# gazelle:exclude pkg/sql/pgwire/pgwirebase/formatcode_string.go
# gazelle:exclude pkg/sql/pgwire/pgwirebase/pgnumericsign_string.go
# gazelle:exclude pkg/sql/pgwire/pgwirebase/preparetype_string.go
# gazelle:exclude pkg/sql/pgwire/pgwirebase/servererrfieldtype_string.go
# gazelle:exclude pkg/sql/pgwire/pgwirebase/servermessagetype_string.go
# gazelle:exclude pkg/sql/privilege/kind_string.go
# gazelle:exclude pkg/sql/roleoption/option_string.go
# gazelle:exclude pkg/sql/schemachange/columnconversionkind_string.go
# gazelle:exclude pkg/sql/schemachanger/scop/type_string.go
# gazelle:exclude pkg/sql/sem/tree/createtypevariety_string.go
# gazelle:exclude pkg/sql/sem/tree/statementreturntype_string.go
# gazelle:exclude pkg/sql/sem/tree/statementtype_string.go
# gazelle:exclude pkg/sql/txnevent_string.go
# gazelle:exclude pkg/sql/txntype_string.go
# gazelle:exclude pkg/util/encoding/type_string.go
# gazelle:exclude pkg/util/timeutil/pgdate/field_string.go
# gazelle:exclude pkg/util/timeutil/pgdate/parsemode_string.go
# gazelle:exclude pkg/workload/schemachange/optype_string.go
# gazelle:exclude pkg/workload/schemachange/txstatus_string.go
# gazelle:exclude pkg/**/*_string.go
# gazelle:exclude pkg/geo/wkt/wkt_generated.go
# gazelle:exclude pkg/sql/schemachanger/scop/backfill_visitor_generated.go
# gazelle:exclude pkg/sql/schemachanger/scop/mutation_visitor_generated.go
Expand Down
2 changes: 1 addition & 1 deletion WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ yarn_install(
# NB: @bazel_skylib comes from go_rules_dependencies().
load("@bazel_skylib//lib:versions.bzl", "versions")

versions.check(minimum_bazel_version = "3.5.0")
versions.check(minimum_bazel_version = "4.0.0")

# Load gazelle dependencies.
load("@bazel_gazelle//:deps.bzl", "gazelle_dependencies")
Expand Down
4 changes: 2 additions & 2 deletions build/bazelbuilder/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ RUN echo "deb [arch=amd64] https://storage.googleapis.com/bazel-apt stable jdk1.
&& curl https://bazel.build/bazel-release.pub.gpg | apt-key add - \
&& apt-get update \
&& DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
bazel-3.6.0
bazel-4.0.0

# git - Upgrade to a more modern version
RUN DEBIAN_FRONTEND=noninteractive apt-get install dh-autoreconf libcurl4-gnutls-dev libexpat1-dev gettext libz-dev libssl-dev -y && \
Expand All @@ -58,7 +58,7 @@ RUN apt-get purge -y \

RUN rm -rf /tmp/* /var/lib/apt/lists/*

RUN ln -s /usr/bin/bazel-3.6.0 /usr/bin/bazel
RUN ln -s /usr/bin/bazel-4.0.0 /usr/bin/bazel

COPY entrypoint.sh /usr/bin
ENTRYPOINT ["/usr/bin/entrypoint.sh"]
Expand Down
2 changes: 1 addition & 1 deletion build/teamcity-bazel-support.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
BAZEL_IMAGE=cockroachdb/bazel:20210408-113636
BAZEL_IMAGE=cockroachdb/bazel:20210505-134517

# Call `run_bazel $NAME_OF_SCRIPT` to start an appropriately-configured Docker
# container with the `cockroachdb/bazel` image running the given script.
Expand Down
4 changes: 4 additions & 0 deletions pkg/base/test_server_args.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,10 @@ type TestServerArgs struct {
// ExternalIODir is used to initialize field in cluster.Settings.
ExternalIODir string

// ExternalIODirConfig is used to initialize the same-named
// field on the server.Config struct.
ExternalIODirConfig ExternalIODirConfig

// Fields copied to the server.Config.
Insecure bool
RetryOptions retry.Options // TODO(tbg): make testing knob.
Expand Down
48 changes: 48 additions & 0 deletions pkg/ccl/changefeedccl/changefeed_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -551,6 +551,54 @@ func TestChangefeedUserDefinedTypes(t *testing.T) {
t.Run(`kafka`, kafkaTest(testFn))
}

func TestChangefeedExternalIODisabled(t *testing.T) {
defer leaktest.AfterTest(t)()
defer log.Scope(t).Close(t)
t.Run("sinkful changefeeds not allowed with disabled external io", func(t *testing.T) {
disallowedSinkProtos := []string{
changefeedbase.SinkSchemeExperimentalSQL,
changefeedbase.SinkSchemeKafka,
changefeedbase.SinkSchemeNull, // Doesn't work because all sinkful changefeeds are disallowed
// Cloud sink schemes
"experimental-s3",
"experimental-gs",
"experimental-nodelocal",
"experimental-http",
"experimental-https",
"experimental-azure",
}
ctx := context.Background()
s, db, _ := serverutils.StartServer(t, base.TestServerArgs{
ExternalIODirConfig: base.ExternalIODirConfig{
DisableOutbound: true,
},
})
defer s.Stopper().Stop(ctx)
sqlDB := sqlutils.MakeSQLRunner(db)
sqlDB.Exec(t, "CREATE TABLE target_table (pk INT PRIMARY KEY)")
for _, proto := range disallowedSinkProtos {
sqlDB.ExpectErr(t, "Outbound IO is disabled by configuration, cannot create changefeed",
"CREATE CHANGEFEED FOR target_table INTO $1",
fmt.Sprintf("%s://does-not-matter", proto),
)
}
})

withDisabledOutbound := func(args *base.TestServerArgs) { args.ExternalIODirConfig.DisableOutbound = true }
t.Run("sinkless changfeeds are allowed with disabled external io",
sinklessTestWithServerArgs(withDisabledOutbound,
func(t *testing.T, db *gosql.DB, f cdctest.TestFeedFactory) {
sqlDB := sqlutils.MakeSQLRunner(db)
sqlDB.Exec(t, "CREATE TABLE target_table (pk INT PRIMARY KEY)")
sqlDB.Exec(t, "INSERT INTO target_table VALUES (1)")
feed := feed(t, f, "CREATE CHANGEFEED FOR target_table")
defer closeFeed(t, feed)
assertPayloads(t, feed, []string{
`target_table: [1]->{"after": {"pk": 1}}`,
})
}))
}

// Test how Changefeeds react to schema changes that do not require a backfill
// operation.
func TestChangefeedSchemaChangeNoBackfill(t *testing.T) {
Expand Down
2 changes: 2 additions & 0 deletions pkg/cmd/roachtest/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ go_library(
"restart.go",
"restore.go",
"roachmart.go",
"ruby_pg.go",
"ruby_pg_blocklist.go",
"schema_change_database_version_upgrade.go",
"schemachange.go",
"schemachange_random_load.go",
Expand Down
1 change: 1 addition & 0 deletions pkg/cmd/roachtest/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ func registerTests(r *testRegistry) {
registerRestoreNodeShutdown(r)
registerRestore(r)
registerRoachmart(r)
registerRubyPG(r)
registerSchemaChangeBulkIngest(r)
registerSchemaChangeDatabaseVersionUpgrade(r)
registerSchemaChangeDuringKV(r)
Expand Down
205 changes: 205 additions & 0 deletions pkg/cmd/roachtest/ruby_pg.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,205 @@
// Copyright 2021 The Cockroach Authors.
//
// Use of this software is governed by the Business Source License
// included in the file licenses/BSL.txt.
//
// As of the Change Date specified in that file, in accordance with
// the Business Source License, use of this software will be governed
// by the Apache License, Version 2.0, included in the file
// licenses/APL.txt.

package main

import (
"bufio"
"bytes"
"context"
"fmt"
"regexp"

"github.com/cockroachdb/cockroach/pkg/util/log"
"github.com/stretchr/testify/require"
)

var rubyPGTestFailureRegex = regexp.MustCompile(`^rspec ./.*# .*`)
var rubyPGVersion = "v1.2.3"

// This test runs Ruby PG's full test suite against a single cockroach node.
func registerRubyPG(r *testRegistry) {
runRubyPGTest := func(
ctx context.Context,
t *test,
c *cluster,
) {
if c.isLocal() {
t.Fatal("cannot be run in local mode")
}
node := c.Node(1)
t.Status("setting up cockroach")
c.Put(ctx, cockroach, "./cockroach", c.All())
if err := c.PutLibraries(ctx, "./lib"); err != nil {
t.Fatal(err)
}
c.Start(ctx, t, c.All())

version, err := fetchCockroachVersion(ctx, c, node[0], nil)
if err != nil {
t.Fatal(err)
}

if err := alterZoneConfigAndClusterSettings(ctx, version, c, node[0], nil); err != nil {
t.Fatal(err)
}

t.Status("cloning rails and installing prerequisites")

c.l.Printf("Supported ruby-pg version is %s.", rubyPGVersion)

if err := repeatRunE(
ctx, c, node, "update apt-get", `sudo apt-get -qq update`,
); err != nil {
t.Fatal(err)
}

if err := repeatRunE(
ctx,
c,
node,
"install dependencies",
`sudo apt-get -qq install ruby-full ruby-dev rubygems build-essential zlib1g-dev libpq-dev libsqlite3-dev`,
); err != nil {
t.Fatal(err)
}

if err := repeatRunE(
ctx,
c,
node,
"install ruby 2.7",
`mkdir -p ruby-install && \
curl -fsSL https://github.com/postmodern/ruby-install/archive/v0.6.1.tar.gz | tar --strip-components=1 -C ruby-install -xz && \
sudo make -C ruby-install install && \
sudo ruby-install --system ruby 2.7.1 && \
sudo gem update --system`,
); err != nil {
t.Fatal(err)
}

if err := repeatRunE(
ctx, c, node, "remove old ruby-pg", `sudo rm -rf /mnt/data1/ruby-pg`,
); err != nil {
t.Fatal(err)
}

if err := repeatGitCloneE(
ctx,
t.l,
c,
"https://github.com/ged/ruby-pg.git",
"/mnt/data1/ruby-pg",
rubyPGVersion,
node,
); err != nil {
t.Fatal(err)
}

t.Status("installing bundler")
if err := repeatRunE(
ctx,
c,
node,
"installing bundler",
`cd /mnt/data1/ruby-pg/ && sudo gem install bundler:2.1.4`,
); err != nil {
t.Fatal(err)
}

t.Status("installing gems")
if err := repeatRunE(
ctx,
c,
node,
"installing gems",
`cd /mnt/data1/ruby-pg/ && sudo bundle install`,
); err != nil {
t.Fatal(err)
}

if err := repeatRunE(
ctx, c, node, "remove old ruby-pg helpers.rb", `sudo rm /mnt/data1/ruby-pg/spec/helpers.rb`,
); err != nil {
t.Fatal(err)
}

// Write the cockroach config into the test suite to use.
err = c.PutE(ctx, c.l, "./pkg/cmd/roachtest/ruby_pg_helpers.rb", "/mnt/data1/ruby-pg/spec/helpers.rb", c.All())
require.NoError(t, err)

t.Status("running ruby-pg test suite")
// Note that this is expected to return an error, since the test suite
// will fail. And it is safe to swallow it here.
rawResults, _ := c.RunWithBuffer(ctx, t.l, node,
`cd /mnt/data1/ruby-pg/ && sudo rake`,
)

c.l.Printf("Test Results:\n%s", rawResults)

// Find all the failed and errored tests.
results := newORMTestsResults()
blocklistName, expectedFailures, _, _ := rubyPGBlocklist.getLists(version)
if expectedFailures == nil {
t.Fatalf("No ruby-pg blocklist defined for cockroach version %s", version)
}

scanner := bufio.NewScanner(bytes.NewReader(rawResults))
for scanner.Scan() {
match := rubyPGTestFailureRegex.FindStringSubmatch(scanner.Text())
if match == nil {
continue
}
if len(match) != 1 {
log.Fatalf(ctx, "expected one match for test name, found: %d", len(match))
}

// Take the first test name.
test := match[0]

// This regex is used to get the name of the test.
// The test name follows the file name and a hashtag.
// ie. test.rb:99 # TEST NAME.
strs := regexp.MustCompile("^rspec .*.rb.*([0-9]|]) # ").Split(test, -1)
if len(strs) != 2 {
log.Fatalf(ctx, "expected test output line to be split into two strings")
}
test = strs[1]

issue, expectedFailure := expectedFailures[test]
switch {
case expectedFailure:
results.results[test] = fmt.Sprintf("--- FAIL: %s - %s (expected)",
test, maybeAddGithubLink(issue),
)
results.failExpectedCount++
results.currentFailures = append(results.currentFailures, test)
case !expectedFailure:
results.results[test] = fmt.Sprintf("--- PASS: %s - %s (unexpected)",
test, maybeAddGithubLink(issue),
)
}
results.runTests[test] = struct{}{}
}

results.summarizeAll(t, "ruby-pg", blocklistName, expectedFailures, version, rubyPGVersion)
}

r.Add(testSpec{
MinVersion: "v20.1.0",
Name: "ruby-pg",
Owner: OwnerSQLExperience,
Cluster: makeClusterSpec(1),
Tags: []string{`default`, `orm`},
Run: func(ctx context.Context, t *test, c *cluster) {
runRubyPGTest(ctx, t, c)
},
})
}
Loading

0 comments on commit 84c450e

Please sign in to comment.