From 2b7de3ad0a30cf0e87a0dec8f4b92142d684ffed Mon Sep 17 00:00:00 2001 From: Khosrow Afroozeh Date: Tue, 19 Mar 2024 16:29:43 +0000 Subject: [PATCH] Fix tests that relied on the server nsup-period setting to be larger than zero --- aerospike_suite_test.go | 17 ++++++++++++++ client_object_test.go | 51 +++++++++++++++++++++++++++++++++-------- udf_test.go | 15 +++++++++--- 3 files changed, 71 insertions(+), 12 deletions(-) diff --git a/aerospike_suite_test.go b/aerospike_suite_test.go index 52050fc0..6bc2bafd 100644 --- a/aerospike_suite_test.go +++ b/aerospike_suite_test.go @@ -404,6 +404,23 @@ const ( vsEqual versionStatus = "equal" ) +func nsupPeriod(ns string) int { + if *proxy || *dbaas { + return 0 + } + + var pattern = `(?Pnsup-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\d+)(\.(?P\d+)(\.(?P\d+)(\.(?P\d+))?)?)?.*` var vmeta = regexp.MustCompile(pattern) diff --git a/client_object_test.go b/client_object_test.go index a5eb7be4..6a0eb8e3 100644 --- a/client_object_test.go +++ b/client_object_test.go @@ -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 { @@ -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()) @@ -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 @@ -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"` @@ -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()) @@ -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 @@ -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()) @@ -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 @@ -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 @@ -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 diff --git a/udf_test.go b/udf_test.go index 06ab41e8..fd5dd4bd 100644 --- a/udf_test.go +++ b/udf_test.go @@ -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"})) @@ -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))