Skip to content

Commit

Permalink
Merge 81ca785 into b0bd09a
Browse files Browse the repository at this point in the history
  • Loading branch information
kozlovic committed Aug 3, 2022
2 parents b0bd09a + 81ca785 commit 0d2b62e
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 61 deletions.
38 changes: 23 additions & 15 deletions server/clustering_test.go
Expand Up @@ -6915,9 +6915,14 @@ func TestClusteringRestoreSnapshotWithDifferentVersionsOfSameChannel(t *testing.
}

func TestClusteringSQLMsgStoreFlushed(t *testing.T) {
if persistentStoreType != stores.TypeSQL {
t.SkipNow()
// If user doesn't want to run any SQL tests, we need to bail.
if !doSQL {
t.Skip()
}
// Force persistent store to be SQL for this test.
orgps := persistentStoreType
persistentStoreType = stores.TypeSQL
defer func() { persistentStoreType = orgps }()

cleanupDatastore(t)
defer cleanupDatastore(t)
Expand Down Expand Up @@ -6965,19 +6970,22 @@ func TestClusteringSQLMsgStoreFlushed(t *testing.T) {
t.Fatalf("Did not get all our acks")
}

db, err := sql.Open(testSQLDriver, testSQLSource+"_b")
if err != nil {
t.Fatalf("Error opening db: %v", err)
}
defer db.Close()
r := db.QueryRow("SELECT COUNT(seq) FROM Messages")
count = 0
if err := r.Scan(&count); err != nil {
t.Fatalf("Error on scan: %v", err)
}
if count == 0 {
t.Fatalf("Expected some messages, got none")
}
waitFor(t, time.Second, 15*time.Millisecond, func() error {
db, err := sql.Open(testSQLDriver, testSQLSource+"_b")
if err != nil {
return err
}
defer db.Close()
r := db.QueryRow("SELECT COUNT(seq) FROM Messages")
count = 0
if err := r.Scan(&count); err != nil {
return fmt.Errorf("Error on scan: %v", err)
}
if count == 0 {
return fmt.Errorf("Expected some messages, got none")
}
return nil
})
}

func TestClusteringQueueMemberPendingCount(t *testing.T) {
Expand Down
8 changes: 4 additions & 4 deletions server/ft_test.go
Expand Up @@ -366,15 +366,15 @@ func TestFTPartition(t *testing.T) {
"-test.v",
"-test.run=TestFTPartition$",
"-persistent_store", persistentStoreType,
"-sql_create_db=false",
"-sql_delete_db=false",
}
if !doSQL {
params = append(params, "-sql=false")
}
// Start a process that will be the standby
if persistentStoreType == stores.TypeSQL {
params = append(params,
"-sql_create_db=false",
"-sql_delete_db=false",
"-sql_driver", testSQLDriver,
"-sql_source", testSQLSource,
"-sql_source_admin", testSQLSourceAdmin,
Expand Down Expand Up @@ -488,15 +488,15 @@ func TestFTPartitionReversed(t *testing.T) {
"-test.v",
"-test.run=TestFTPartitionReversed$",
"-persistent_store", persistentStoreType,
"-sql_create_db=false",
"-sql_delete_db=false",
}
if !doSQL {
params = append(params, "-sql=false")
}
// Start a process that will act as the active server
if persistentStoreType == stores.TypeSQL {
params = append(params,
"-sql_create_db=false",
"-sql_delete_db=false",
"-sql_driver", testSQLDriver,
"-sql_source", testSQLSource,
"-sql_source_admin", testSQLSourceAdmin,
Expand Down
29 changes: 10 additions & 19 deletions server/server_delivery_test.go
Expand Up @@ -22,7 +22,6 @@ import (

natsdTest "github.com/nats-io/nats-server/v2/test"
"github.com/nats-io/nats-streaming-server/stores"
"github.com/nats-io/nats-streaming-server/test"
"github.com/nats-io/nats.go"
"github.com/nats-io/stan.go"
"github.com/nats-io/stan.go/pb"
Expand Down Expand Up @@ -258,31 +257,23 @@ func TestDeliveryWithGapsInSequence(t *testing.T) {
}

func TestPersistentStoreSQLSubsPendingRows(t *testing.T) {
// If user doesn't want to run any SQL tests, we need to bail.
if !doSQL {
t.SkipNow()
}
source := testSQLSource
sourceAdmin := testSQLSourceAdmin
// If not running tests with `-persistent_store sql`,
// initialize few things and default to MySQL.
if persistentStoreType != stores.TypeSQL {
source = testDefaultMySQLSource
sourceAdmin = testDefaultMySQLSourceAdmin
if err := test.CreateSQLDatabase(testSQLDriver, sourceAdmin,
source, testSQLDatabaseName); err != nil {
t.Fatalf("Error setting up test for SQL: %v", err)
}
t.Skip()
}
defer test.DeleteSQLDatabase(testSQLDriver, sourceAdmin, testSQLDatabaseName)
// Force persistent store to be SQL for this test.
orgps := persistentStoreType
persistentStoreType = stores.TypeSQL
defer func() { persistentStoreType = orgps }()

cleanupDatastore(t)
defer cleanupDatastore(t)

ns := natsdTest.RunDefaultServer()
defer ns.Shutdown()

opts := GetDefaultOptions()
opts := getTestDefaultOptsForPersistentStore()
opts.NATSServerURL = "nats://127.0.0.1:4222"
opts.StoreType = stores.TypeSQL
opts.SQLStoreOpts.Driver = testSQLDriver
opts.SQLStoreOpts.Source = source
s := runServerWithOpts(t, opts, nil)
defer shutdownRestartedServerOnTestExit(&s)

Expand Down
5 changes: 5 additions & 0 deletions server/server_queue_test.go
Expand Up @@ -637,6 +637,11 @@ func TestPersistentStoreQMemberRemovedFromStore(t *testing.T) {
}

func TestPersistentStoreMultipleShadowQSubs(t *testing.T) {
// If user doesn't want to run any SQL tests, we will do the filestore only
// and need to bail if the persistent store type is set to SQL.
if !doSQL && persistentStoreType == stores.TypeSQL {
t.Skip()
}
cleanupDatastore(t)
defer cleanupDatastore(t)

Expand Down
34 changes: 11 additions & 23 deletions server/server_storefailures_test.go
Expand Up @@ -25,7 +25,6 @@ import (

"github.com/nats-io/nats-streaming-server/spb"
"github.com/nats-io/nats-streaming-server/stores"
"github.com/nats-io/nats-streaming-server/test"
"github.com/nats-io/stan.go"
"github.com/nats-io/stan.go/pb"
)
Expand Down Expand Up @@ -818,33 +817,22 @@ func TestFileStoreServerStateMissing(t *testing.T) {
}

func TestSQLStoreServerStateMissing(t *testing.T) {
// If can't run any SQL test, bail out
// If user doesn't want to run any SQL tests, we need to bail.
if !doSQL {
t.SkipNow()
t.Skip()
}
// Force persistent store to be SQL for this test.
orgps := persistentStoreType
persistentStoreType = stores.TypeSQL
defer func() { persistentStoreType = orgps }()

l := &noSrvStateLogger{ch: make(chan string, 1)}
cleanupDatastore(t)
defer cleanupDatastore(t)

// Force the storage to be SQL
source := testSQLSource
sourceAdmin := testSQLSourceAdmin
// If not running tests with `-persistent_store sql`,
// initialize few things and default to MySQL.
if persistentStoreType != stores.TypeSQL {
source = testDefaultMySQLSource
sourceAdmin = testDefaultMySQLSourceAdmin
if err := test.CreateSQLDatabase(testSQLDriver, sourceAdmin,
source, testSQLDatabaseName); err != nil {
t.Fatalf("Error setting up test for SQL: %v", err)
}
}
defer test.DeleteSQLDatabase(testSQLDriver, sourceAdmin, testSQLDatabaseName)
l := &noSrvStateLogger{ch: make(chan string, 1)}

opts := GetDefaultOptions()
opts := getTestDefaultOptsForPersistentStore()
opts.CustomLogger = l
opts.StoreType = stores.TypeSQL
opts.SQLStoreOpts.Driver = testSQLDriver
opts.SQLStoreOpts.Source = source
s := runServerWithOpts(t, opts, nil)
defer s.Shutdown()

Expand All @@ -854,7 +842,7 @@ func TestSQLStoreServerStateMissing(t *testing.T) {

s.Shutdown()

db, err := sql.Open(testSQLDriver, source)
db, err := sql.Open(testSQLDriver, testSQLSource)
if err != nil {
t.Fatalf("Error opening database: %v", err)
}
Expand Down
5 changes: 5 additions & 0 deletions server/server_sub_test.go
Expand Up @@ -732,6 +732,11 @@ func TestAckTimerSetOnStalledSub(t *testing.T) {
}

func TestPersistentStoreNonDurableSubRemovedOnConnClose(t *testing.T) {
// If user doesn't want to run any SQL tests, we will do the filestore only
// and need to bail if the persistent store type is set to SQL.
if !doSQL && persistentStoreType == stores.TypeSQL {
t.Skip()
}
cleanupDatastore(t)
defer cleanupDatastore(t)

Expand Down

0 comments on commit 0d2b62e

Please sign in to comment.