Skip to content

Commit

Permalink
refactor(testutils): export CheckAnyConstraint
Browse files Browse the repository at this point in the history
It is also useful for backup svc tests.
  • Loading branch information
Michal-Leszczynski committed Dec 18, 2024
1 parent f371ebc commit 47bbcf1
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 28 deletions.
18 changes: 0 additions & 18 deletions pkg/service/restore/helper_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
"github.com/scylladb/gocqlx/v2"
"github.com/scylladb/gocqlx/v2/qb"
"github.com/scylladb/scylla-manager/v3/pkg/service/cluster"
"github.com/scylladb/scylla-manager/v3/pkg/util/version"
"go.uber.org/zap/zapcore"

"github.com/scylladb/scylla-manager/v3/pkg/metrics"
Expand Down Expand Up @@ -465,23 +464,6 @@ func validateCompleteProgress(t *testing.T, pr Progress, tables []table) {
}
}

func checkAnyConstraint(t *testing.T, client *scyllaclient.Client, constraints ...string) bool {
ni, err := client.AnyNodeInfo(context.Background())
if err != nil {
t.Fatal(err)
}
for _, c := range constraints {
ok, err := version.CheckConstraint(ni.ScyllaVersion, c)
if err != nil {
t.Fatal(err)
}
if ok {
return true
}
}
return false
}

func createTable(t *testing.T, session gocqlx.Session, keyspace string, tables ...string) {
for _, tab := range tables {
ExecStmt(t, session, fmt.Sprintf("CREATE TABLE %q.%q (id int PRIMARY KEY, data int)", keyspace, tab))
Expand Down
6 changes: 3 additions & 3 deletions pkg/service/restore/restore_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import (
func TestRestoreTablesUserIntegration(t *testing.T) {
h := newTestHelper(t, ManagedSecondClusterHosts(), ManagedClusterHosts())

if checkAnyConstraint(t, h.dstCluster.Client, ">= 6.0, < 2000", ">= 2024.2, > 1000") {
if CheckAnyConstraint(t, h.dstCluster.Client, ">= 6.0, < 2000", ">= 2024.2, > 1000") {
t.Skip("Auth restore is not supported in Scylla 6.0. It requires core side support that is aimed at 6.1 release")
}

Expand Down Expand Up @@ -123,7 +123,7 @@ func TestRestoreSchemaRoundtripIntegration(t *testing.T) {
h := newTestHelper(t, ManagedSecondClusterHosts(), ManagedClusterHosts())
hRev := newTestHelper(t, ManagedClusterHosts(), ManagedSecondClusterHosts())

if !checkAnyConstraint(t, h.dstCluster.Client, ">= 6.0, < 2000", ">= 2024.2, > 1000") {
if !CheckAnyConstraint(t, h.dstCluster.Client, ">= 6.0, < 2000", ">= 2024.2, > 1000") {
t.Skip("This test assumes that schema is backed up and restored via DESCRIBE SCHEMA WITH INTERNALS")
}

Expand Down Expand Up @@ -237,7 +237,7 @@ func TestRestoreSchemaRoundtripIntegration(t *testing.T) {
func TestRestoreSchemaDropAddColumnIntegration(t *testing.T) {
h := newTestHelper(t, ManagedSecondClusterHosts(), ManagedClusterHosts())

if !checkAnyConstraint(t, h.dstCluster.Client, ">= 6.0, < 2000", ">= 2024.2, > 1000") {
if !CheckAnyConstraint(t, h.dstCluster.Client, ">= 6.0, < 2000", ">= 2024.2, > 1000") {
t.Skip("This test is the reason why SM needs to restore schema by DESCRIBE SCHEMA WITH INTERNALS")
}

Expand Down
14 changes: 7 additions & 7 deletions pkg/service/restore/service_restore_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ func TestRestoreGetTargetUnitsViewsIntegration(t *testing.T) {
}

var ignoreTarget []string
if checkAnyConstraint(t, h.Client, ">= 6.0, < 2000", ">= 2024.2, > 1000") {
if CheckAnyConstraint(t, h.Client, ">= 6.0, < 2000", ">= 2024.2, > 1000") {
ignoreTarget = []string{
"!system_auth.*",
"!system_distributed.service_levels",
Expand All @@ -325,10 +325,10 @@ func TestRestoreGetTargetUnitsViewsIntegration(t *testing.T) {
}

var ignoreUnits []string
if checkAnyConstraint(t, h.Client, "< 1000") {
if CheckAnyConstraint(t, h.Client, "< 1000") {
ignoreUnits = append(ignoreUnits, "system_replicated_keys")
}
if checkAnyConstraint(t, h.Client, ">= 6.0, < 2000", ">= 2024.2, > 1000") {
if CheckAnyConstraint(t, h.Client, ">= 6.0, < 2000", ">= 2024.2, > 1000") {
ignoreUnits = append(ignoreUnits,
"system_auth",
"service_levels",
Expand Down Expand Up @@ -1407,7 +1407,7 @@ func restoreAllTables(t *testing.T, schemaTarget, tablesTarget Target, keyspace
{ks: "system_traces", tab: "sessions"},
{ks: "system_traces", tab: "sessions_time_idx"},
}
if !checkAnyConstraint(t, dstH.Client, ">= 6.0, < 2000", ">= 2024.2, > 1000") {
if !CheckAnyConstraint(t, dstH.Client, ">= 6.0, < 2000", ">= 2024.2, > 1000") {
toValidate = append(toValidate,
table{ks: "system_auth", tab: "role_attributes"},
table{ks: "system_auth", tab: "role_members"},
Expand Down Expand Up @@ -1480,7 +1480,7 @@ func restoreAlternator(t *testing.T, schemaTarget, tablesTarget Target, testKeys
)

dstH.shouldSkipTest(schemaTarget, tablesTarget)
if checkAnyConstraint(t, dstH.Client, ">= 6.0, < 2000", ">= 2024.2, > 1000") {
if CheckAnyConstraint(t, dstH.Client, ">= 6.0, < 2000", ">= 2024.2, > 1000") {
t.Skip("See https://github.com/scylladb/scylladb/issues/19112")
}

Expand Down Expand Up @@ -1531,7 +1531,7 @@ func (h *restoreTestHelper) validateRestoreSuccess(dstSession, srcSession gocqlx
Print("Then: validate restore result")

if target.RestoreSchema {
if !checkAnyConstraint(h.T, h.Client, ">= 6.0, < 2000", ">= 2024.2, > 1000") {
if !CheckAnyConstraint(h.T, h.Client, ">= 6.0, < 2000", ">= 2024.2, > 1000") {
// Schema restart is required only for older Scylla versions
h.restartScylla()
}
Expand Down Expand Up @@ -1828,7 +1828,7 @@ func getBucketKeyspaceUser(t *testing.T) (string, string, string) {
func (h *restoreTestHelper) shouldSkipTest(targets ...Target) {
for _, target := range targets {
if target.RestoreSchema {
if err := IsRestoreSchemaFromSSTablesSupported(context.Background(), h.Client); err != nil && !checkAnyConstraint(h.T, h.Client, ">= 6.0, < 2000", ">= 2024.2, > 1000") {
if err := IsRestoreSchemaFromSSTablesSupported(context.Background(), h.Client); err != nil && !CheckAnyConstraint(h.T, h.Client, ">= 6.0, < 2000", ">= 2024.2, > 1000") {
h.T.Skip(err)
}
}
Expand Down
32 changes: 32 additions & 0 deletions pkg/testutils/version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// Copyright (C) 2024 ScyllaDB

package testutils

import (
"context"
"testing"

"github.com/scylladb/scylla-manager/v3/pkg/scyllaclient"
"github.com/scylladb/scylla-manager/v3/pkg/util/version"
)

// CheckAnyConstraint checks if any of the passed version constraints are satisfied.
// Can be used for skipping tests which make sense only for certain Scylla versions.
func CheckAnyConstraint(t *testing.T, client *scyllaclient.Client, constraints ...string) bool {
t.Helper()

ni, err := client.AnyNodeInfo(context.Background())
if err != nil {
t.Fatal(err)
}
for _, c := range constraints {
ok, err := version.CheckConstraint(ni.ScyllaVersion, c)
if err != nil {
t.Fatal(err)
}
if ok {
return true
}
}
return false
}

0 comments on commit 47bbcf1

Please sign in to comment.