Skip to content

Commit

Permalink
Fix tests that relied on the server nsup-period setting to be larger …
Browse files Browse the repository at this point in the history
…than zero
  • Loading branch information
khaf committed Mar 19, 2024
1 parent f730e19 commit 2b7de3a
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 12 deletions.
17 changes: 17 additions & 0 deletions aerospike_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,23 @@ const (
vsEqual versionStatus = "equal"
)

func nsupPeriod(ns string) int {
if *proxy || *dbaas {
return 0
}

var pattern = `(?P<v1>nsup-period=\d+)`
var vmeta = regexp.MustCompile(pattern)

vs := info(nativeClient, "namespace/"+ns)
server := findNamedMatches(vmeta, vs)

if len(server) > 0 {
return server[0]
}
return 0
}

func cmpServerVersion(v string) versionStatus {
var pattern = `(?P<v1>\d+)(\.(?P<v2>\d+)(\.(?P<v3>\d+)(\.(?P<v4>\d+))?)?)?.*`
var vmeta = regexp.MustCompile(pattern)
Expand Down
51 changes: 42 additions & 9 deletions client_object_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import (

// ALL tests are isolated by SetName and Key, which are 50 random characters
var _ = gg.Describe("Aerospike", func() {
var nsup int

gg.BeforeEach(func() {
if *dbaas {
Expand Down Expand Up @@ -974,7 +975,15 @@ var _ = gg.Describe("Aerospike", func() {
resObjects = nil
objects = nil

wpolicy := as.NewWritePolicy(0, 500)
nsup = nsupPeriod(ns)

var wpolicy *as.WritePolicy
if nsup > 0 {
wpolicy = as.NewWritePolicy(0, 500)
} else {
wpolicy = as.NewWritePolicy(0, 0)
}

for i := 0; i < 100; i++ {
key, err = as.NewKey(ns, set, randString(50))
gm.Expect(err).ToNot(gm.HaveOccurred())
Expand Down Expand Up @@ -1019,7 +1028,9 @@ var _ = gg.Describe("Aerospike", func() {
gm.Expect(found[i]).To(gm.BeTrue())
resObj := resObjects[i].(*testObjectTagged)

gm.Expect(resObj.TTL).To(gm.BeNumerically("<=", 500))
if nsup > 0 {
gm.Expect(resObj.TTL).To(gm.BeNumerically("<=", 500))
}
gm.Expect(resObj.Gen).To(gm.BeNumerically(">", 0))

objects[i].TTL = resObj.TTL
Expand Down Expand Up @@ -1143,7 +1154,6 @@ var _ = gg.Describe("Aerospike", func() {
var queryPolicy = as.NewQueryPolicy()

gg.Context("ScanObjects operations", func() {

type InnerStruct struct {
PersistNot int `as:"-"`
PersistAsInner1 int `as:"inner1"`
Expand All @@ -1154,7 +1164,15 @@ var _ = gg.Describe("Aerospike", func() {
gg.BeforeEach(func() {
set = randString(50)

wp := as.NewWritePolicy(0, 500)
nsup = nsupPeriod(ns)

var wp *as.WritePolicy
if nsup > 0 {
wp = as.NewWritePolicy(0, 500)
} else {
wp = as.NewWritePolicy(0, 0)

}
for i := 1; i < 100; i++ {
key, err = as.NewKey(ns, set, randString(50))
gm.Expect(err).ToNot(gm.HaveOccurred())
Expand All @@ -1180,7 +1198,9 @@ var _ = gg.Describe("Aerospike", func() {
gm.Expect(resObj.PersistAsInner1).To(gm.BeNumerically(">", 0))
gm.Expect(resObj.PersistNot).To(gm.Equal(0))
gm.Expect(resObj.Gen).To(gm.BeNumerically(">", 0))
gm.Expect(resObj.TTL).To(gm.BeNumerically("<=", 500))
if nsup > 0 {
gm.Expect(resObj.TTL).To(gm.BeNumerically("<=", 500))
}

testObj.PersistAsInner1 = resObj.PersistAsInner1
testObj.Gen = resObj.Gen
Expand Down Expand Up @@ -1210,7 +1230,14 @@ var _ = gg.Describe("Aerospike", func() {
gg.BeforeEach(func() {
set = randString(50)

wp := as.NewWritePolicy(5, 500)
nsup = nsupPeriod(ns)

var wp *as.WritePolicy
if nsup > 0 {
wp = as.NewWritePolicy(5, 500)
} else {
wp = as.NewWritePolicy(5, 0)
}
for i := 1; i < 100; i++ {
key, err = as.NewKey(ns, set, randString(50))
gm.Expect(err).ToNot(gm.HaveOccurred())
Expand All @@ -1237,7 +1264,9 @@ var _ = gg.Describe("Aerospike", func() {
gm.Expect(resObj.PersistAsInner1).To(gm.BeNumerically(">", 0))
gm.Expect(resObj.PersistNot).To(gm.Equal(0))
gm.Expect(resObj.Gen).To(gm.BeNumerically(">", 0))
gm.Expect(resObj.TTL).To(gm.BeNumerically("<=", 500))
if nsup > 0 {
gm.Expect(resObj.TTL).To(gm.BeNumerically("<=", 500))
}

testObj.PersistAsInner1 = resObj.PersistAsInner1
testObj.Gen = resObj.Gen
Expand Down Expand Up @@ -1277,7 +1306,9 @@ var _ = gg.Describe("Aerospike", func() {
gm.Expect(resObj.PersistAsInner1).To(gm.BeNumerically("<=", 70))
gm.Expect(resObj.PersistNot).To(gm.Equal(0))
gm.Expect(resObj.Gen).To(gm.BeNumerically(">", 0))
gm.Expect(resObj.TTL).To(gm.BeNumerically("<=", 500))
if nsup > 0 {
gm.Expect(resObj.TTL).To(gm.BeNumerically("<=", 500))
}

testObj.PersistAsInner1 = resObj.PersistAsInner1
testObj.Gen = resObj.Gen
Expand Down Expand Up @@ -1320,7 +1351,9 @@ var _ = gg.Describe("Aerospike", func() {
gm.Expect(resObj.PersistAsInner1).To(gm.BeNumerically("<=", 70))
gm.Expect(resObj.PersistNot).To(gm.Equal(0))
gm.Expect(resObj.Gen).To(gm.BeNumerically(">", 0))
gm.Expect(resObj.TTL).To(gm.BeNumerically("<=", 500))
if nsup > 0 {
gm.Expect(resObj.TTL).To(gm.BeNumerically("<=", 500))
}

testObj.PersistAsInner1 = resObj.PersistAsInner1
testObj.Gen = resObj.Gen
Expand Down
15 changes: 12 additions & 3 deletions udf_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,14 @@ var _ = gg.Describe("UDF/Query tests", func() {
err = client.PutBins(wpolicy, key, bin1, bin2)
gm.Expect(err).ToNot(gm.HaveOccurred())

wpolicy := as.NewWritePolicy(0, 1000)
nsup := nsupPeriod(ns)

var wpolicy *as.WritePolicy
if nsup > 0 {
wpolicy = as.NewWritePolicy(0, 1000)
} else {
wpolicy = as.NewWritePolicy(0, 0)
}
res, err := client.Execute(wpolicy, key, "udf1", "testFunc1", as.NewValue(2))
gm.Expect(err).ToNot(gm.HaveOccurred())
gm.Expect(res).To(gm.Equal(map[interface{}]interface{}{"status": "OK"}))
Expand All @@ -112,8 +119,10 @@ var _ = gg.Describe("UDF/Query tests", func() {
// read all data and make sure it is consistent
rec, err := client.Get(nil, key)
gm.Expect(err).ToNot(gm.HaveOccurred())
gm.Expect(rec.Expiration).To(gm.BeNumerically("<=", 997))
gm.Expect(rec.Expiration).To(gm.BeNumerically(">", 900)) // give a bit of leeway for slow testing VMs
if nsup > 0 {
gm.Expect(rec.Expiration).To(gm.BeNumerically("<=", 997))
gm.Expect(rec.Expiration).To(gm.BeNumerically(">", 900)) // give a bit of leeway for slow testing VMs
}

gm.Expect(rec.Bins[bin1.Name]).To(gm.Equal(bin1.Value.GetObject()))
gm.Expect(rec.Bins[bin2.Name]).To(gm.Equal(bin1.Value.GetObject().(int) / 2))
Expand Down

0 comments on commit 2b7de3a

Please sign in to comment.