From bc9a811107d4624202a08f73c9596a2649eb363d Mon Sep 17 00:00:00 2001 From: Piotr Piotrowski Date: Fri, 30 Jun 2023 13:45:56 +0200 Subject: [PATCH 01/11] Add compatibility test for object store Signed-off-by: Piotr Piotrowski --- object.go | 14 +++---- test/compat_test.go | 93 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 100 insertions(+), 7 deletions(-) create mode 100644 test/compat_test.go diff --git a/object.go b/object.go index 5aafdfec7..b02507260 100644 --- a/object.go +++ b/object.go @@ -150,13 +150,13 @@ var ( // ObjectStoreConfig is the config for the object store. type ObjectStoreConfig struct { - Bucket string - Description string - TTL time.Duration - MaxBytes int64 - Storage StorageType - Replicas int - Placement *Placement + Bucket string `json:"bucket"` + Description string `json:"description,omitempty"` + TTL time.Duration `json:"max_age,omitempty"` + MaxBytes int64 `json:"max_bytes,omitempty"` + Storage StorageType `json:"storage,omitempty"` + Replicas int `json:"num_replicas,omitempty"` + Placement *Placement `json:"placement,omitempty"` } type ObjectStoreStatus interface { diff --git a/test/compat_test.go b/test/compat_test.go new file mode 100644 index 000000000..179503bd9 --- /dev/null +++ b/test/compat_test.go @@ -0,0 +1,93 @@ +//go:build compat +// +build compat + +package test + +import ( + "encoding/json" + "fmt" + "net/http" + "testing" + "time" + + "github.com/nats-io/nats.go" +) + +type objectRequest struct { + Config *nats.ObjectMeta `json:"config"` + URL string `json:"url"` + Bucket string `json:"bucket"` +} + +func TestObjectStoreCompatibility(t *testing.T) { + nc, err := nats.Connect("demo.nats.io") + if err != nil { + t.Fatalf("Error connecting to NATS: %v", err) + } + defer nc.Close() + sub, err := nc.SubscribeSync("tests.object_store.>") + if err != nil { + t.Fatalf("Error subscribing to test subject: %v", err) + } + defer sub.Unsubscribe() + init, err := sub.NextMsg(5 * time.Second) + if err != nil { + t.Fatalf("Error getting message: %v", err) + } + + js, err := nc.JetStream() + if err != nil { + t.Fatalf("Error getting JetStream context: %v", err) + } + os, err := js.CreateObjectStore(&nats.ObjectStoreConfig{ + Bucket: "test", + }) + if err != nil { + t.Fatalf("Error creating object store: %v", err) + } + if err := init.Respond(nil); err != nil { + t.Fatalf("Error responding to message: %v", err) + } + custom, err := sub.NextMsg(5 * time.Second) + if err != nil { + t.Fatalf("Error getting message: %v", err) + } + var cfg nats.ObjectStoreConfig + if err := json.Unmarshal(custom.Data, &cfg); err != nil { + t.Fatalf("Error unmarshalling message: %v", err) + } + fmt.Printf("%+v\n", cfg) + + os, err = js.CreateObjectStore(&cfg) + if err != nil { + t.Fatalf("Error creating object store: %v", err) + } + if err := custom.Respond(nil); err != nil { + t.Fatalf("Error responding to message: %v", err) + } + + objReq, err := sub.NextMsg(5 * time.Second) + if err != nil { + t.Fatalf("Error getting message: %v", err) + } + var req objectRequest + if err := json.Unmarshal(objReq.Data, &req); err != nil { + t.Fatalf("Error unmarshalling message: %v", err) + } + os, err = js.ObjectStore(req.Bucket) + if err != nil { + t.Fatalf("Error getting object store: %v", err) + } + client := http.Client{Timeout: 10 * time.Second, Transport: &http.Transport{DisableKeepAlives: true}} + resp, err := client.Get(req.URL) + if err != nil { + t.Fatalf("Error getting content: %v", err) + } + defer resp.Body.Close() + if _, err := os.Put(req.Config, resp.Body); err != nil { + t.Fatalf("Error putting object: %v", err) + } + if err := objReq.Respond(nil); err != nil { + t.Fatalf("Error responding to message: %v", err) + } +} From 1ea6ab637580c3a5c0ff6d19662b3372c19f597b Mon Sep 17 00:00:00 2001 From: Piotr Piotrowski Date: Tue, 11 Jul 2023 14:58:25 +0200 Subject: [PATCH 02/11] Improve comparibility tests Signed-off-by: Piotr Piotrowski --- test/compat_test.go | 49 +++++++++++++++++++++++++++++++++------------ 1 file changed, 36 insertions(+), 13 deletions(-) diff --git a/test/compat_test.go b/test/compat_test.go index 179503bd9..5648f8c40 100644 --- a/test/compat_test.go +++ b/test/compat_test.go @@ -5,7 +5,6 @@ package test import ( "encoding/json" - "fmt" "net/http" "testing" "time" @@ -13,10 +12,13 @@ import ( "github.com/nats-io/nats.go" ) -type objectRequest struct { - Config *nats.ObjectMeta `json:"config"` - URL string `json:"url"` - Bucket string `json:"bucket"` +type objectStepConfig[T any] struct { + Suite string `json:"suite"` + Test string `json:"test"` + Command string `json:"command"` + URL string `json:"url"` + Bucket string `json:"bucket"` + Config T `json:"config"` } func TestObjectStoreCompatibility(t *testing.T) { @@ -25,11 +27,15 @@ func TestObjectStoreCompatibility(t *testing.T) { t.Fatalf("Error connecting to NATS: %v", err) } defer nc.Close() + + // setup subscription on which tester will be sending requests sub, err := nc.SubscribeSync("tests.object_store.>") if err != nil { t.Fatalf("Error subscribing to test subject: %v", err) } defer sub.Unsubscribe() + + // 1. Create default bucket init, err := sub.NextMsg(5 * time.Second) if err != nil { t.Fatalf("Error getting message: %v", err) @@ -45,49 +51,66 @@ func TestObjectStoreCompatibility(t *testing.T) { if err != nil { t.Fatalf("Error creating object store: %v", err) } + // send empty response to indicate client is done if err := init.Respond(nil); err != nil { t.Fatalf("Error responding to message: %v", err) } + validateStepResult(t, sub) + + // 2. Create bucket with custom config custom, err := sub.NextMsg(5 * time.Second) if err != nil { t.Fatalf("Error getting message: %v", err) } - var cfg nats.ObjectStoreConfig + var cfg objectStepConfig[*nats.ObjectStoreConfig] if err := json.Unmarshal(custom.Data, &cfg); err != nil { t.Fatalf("Error unmarshalling message: %v", err) } - fmt.Printf("%+v\n", cfg) - os, err = js.CreateObjectStore(&cfg) + os, err = js.CreateObjectStore(cfg.Config) if err != nil { t.Fatalf("Error creating object store: %v", err) } if err := custom.Respond(nil); err != nil { t.Fatalf("Error responding to message: %v", err) } + validateStepResult(t, sub) + // 3. Put object objReq, err := sub.NextMsg(5 * time.Second) if err != nil { t.Fatalf("Error getting message: %v", err) } - var req objectRequest - if err := json.Unmarshal(objReq.Data, &req); err != nil { + var putObjectCfg objectStepConfig[*nats.ObjectMeta] + if err := json.Unmarshal(objReq.Data, &putObjectCfg); err != nil { t.Fatalf("Error unmarshalling message: %v", err) } - os, err = js.ObjectStore(req.Bucket) + os, err = js.ObjectStore(putObjectCfg.Bucket) if err != nil { t.Fatalf("Error getting object store: %v", err) } client := http.Client{Timeout: 10 * time.Second, Transport: &http.Transport{DisableKeepAlives: true}} - resp, err := client.Get(req.URL) + resp, err := client.Get(putObjectCfg.URL) if err != nil { t.Fatalf("Error getting content: %v", err) } defer resp.Body.Close() - if _, err := os.Put(req.Config, resp.Body); err != nil { + if _, err := os.Put(putObjectCfg.Config, resp.Body); err != nil { t.Fatalf("Error putting object: %v", err) } if err := objReq.Respond(nil); err != nil { t.Fatalf("Error responding to message: %v", err) } + validateStepResult(t, sub) +} + +func validateStepResult(t *testing.T, sub *nats.Subscription) { + t.Helper() + stepEnd, err := sub.NextMsg(5 * time.Second) + if err != nil { + t.Fatalf("Error getting message: %v", err) + } + if len(stepEnd.Header["STATUS"]) > 0 { + t.Fatalf("Test step failed: %v", stepEnd.Header["STATUS"][0]) + } } From 9d6a6f120166d3ae12b4225a827e6d80de953836 Mon Sep 17 00:00:00 2001 From: Piotr Piotrowski Date: Tue, 22 Aug 2023 13:50:29 +0200 Subject: [PATCH 03/11] Split compat tests into multiple go tests, add missing tests Signed-off-by: Piotr Piotrowski --- test/compat_test.go | 250 ++++++++++++++++++++++++++++++++++++++------ 1 file changed, 217 insertions(+), 33 deletions(-) diff --git a/test/compat_test.go b/test/compat_test.go index 5648f8c40..98d6f5362 100644 --- a/test/compat_test.go +++ b/test/compat_test.go @@ -1,11 +1,14 @@ -//go:build compat -// +build compat - package test import ( + "bytes" + "crypto/sha256" "encoding/json" + "fmt" + "io" "net/http" + "os" + "strings" "testing" "time" @@ -18,74 +21,148 @@ type objectStepConfig[T any] struct { Command string `json:"command"` URL string `json:"url"` Bucket string `json:"bucket"` + Object string `json:"object"` Config T `json:"config"` } -func TestObjectStoreCompatibility(t *testing.T) { - nc, err := nats.Connect("demo.nats.io") - if err != nil { - t.Fatalf("Error connecting to NATS: %v", err) - } +func TestCompatibilityObjectStoreDefaultBucket(t *testing.T) { + t.Parallel() + nc, js := connect(t) defer nc.Close() // setup subscription on which tester will be sending requests - sub, err := nc.SubscribeSync("tests.object_store.>") + sub, err := nc.SubscribeSync("tests.object-store.default-bucket.>") if err != nil { t.Fatalf("Error subscribing to test subject: %v", err) } defer sub.Unsubscribe() // 1. Create default bucket - init, err := sub.NextMsg(5 * time.Second) + msg, err := sub.NextMsg(1 * time.Hour) if err != nil { t.Fatalf("Error getting message: %v", err) } - js, err := nc.JetStream() - if err != nil { - t.Fatalf("Error getting JetStream context: %v", err) - } - os, err := js.CreateObjectStore(&nats.ObjectStoreConfig{ + _, err = js.CreateObjectStore(&nats.ObjectStoreConfig{ Bucket: "test", }) if err != nil { t.Fatalf("Error creating object store: %v", err) } // send empty response to indicate client is done - if err := init.Respond(nil); err != nil { + if err := msg.Respond(nil); err != nil { t.Fatalf("Error responding to message: %v", err) } - validateStepResult(t, sub) + validateTestResult(t, sub) +} + +func TestCompatibilityObjectStoreCustomBucket(t *testing.T) { + t.Parallel() + nc, js := connect(t) + defer nc.Close() - // 2. Create bucket with custom config - custom, err := sub.NextMsg(5 * time.Second) + // setup subscription on which tester will be sending requests + sub, err := nc.SubscribeSync("tests.object-store.custom-bucket.>") + if err != nil { + t.Fatalf("Error subscribing to test subject: %v", err) + } + defer sub.Unsubscribe() + + // 1. Create custom bucket + msg, err := sub.NextMsg(1 * time.Hour) if err != nil { t.Fatalf("Error getting message: %v", err) } var cfg objectStepConfig[*nats.ObjectStoreConfig] - if err := json.Unmarshal(custom.Data, &cfg); err != nil { + if err := json.Unmarshal(msg.Data, &cfg); err != nil { t.Fatalf("Error unmarshalling message: %v", err) } - os, err = js.CreateObjectStore(cfg.Config) + _, err = js.CreateObjectStore(cfg.Config) if err != nil { t.Fatalf("Error creating object store: %v", err) } - if err := custom.Respond(nil); err != nil { + // send empty response to indicate client is done + if err := msg.Respond(nil); err != nil { t.Fatalf("Error responding to message: %v", err) } - validateStepResult(t, sub) + validateTestResult(t, sub) +} + +func TestCompatibilityObjectStoreGetObject(t *testing.T) { + t.Parallel() + type config struct { + Bucket string `json:"bucket"` + Object string `json:"object"` + } + + nc, js := connect(t) + defer nc.Close() - // 3. Put object - objReq, err := sub.NextMsg(5 * time.Second) + // setup subscription on which tester will be sending requests + sub, err := nc.SubscribeSync("tests.object-store.get-object.>") + if err != nil { + t.Fatalf("Error subscribing to test subject: %v", err) + } + defer sub.Unsubscribe() + + msg, err := sub.NextMsg(1 * time.Hour) if err != nil { t.Fatalf("Error getting message: %v", err) } + var cfg config + if err := json.Unmarshal(msg.Data, &cfg); err != nil { + t.Fatalf("Error unmarshalling message: %v", err) + } + // Get object + os, err := js.ObjectStore(cfg.Bucket) + if err != nil { + t.Fatalf("Error getting object store: %v", err) + } + obj, err := os.Get(cfg.Object) + if err != nil { + t.Fatalf("Error creating object store: %v", err) + } + data, err := io.ReadAll(obj) + if err != nil { + t.Fatalf("Error reading object: %v", err) + } + + // calculate sha256 of the object + h := sha256.New() + h.Write(data) + sha := h.Sum(nil) + + // send response to indicate client is done + if err := msg.Respond(sha); err != nil { + t.Fatalf("Error responding to message: %v", err) + } + validateTestResult(t, sub) +} + +func TestCompatibilityObjectStorePutObject(t *testing.T) { + t.Parallel() + + nc, js := connect(t) + defer nc.Close() + + // setup subscription on which tester will be sending requests + sub, err := nc.SubscribeSync("tests.object-store.put-object.>") + if err != nil { + t.Fatalf("Error subscribing to test subject: %v", err) + } + defer sub.Unsubscribe() + + msg, err := sub.NextMsg(1 * time.Hour) + if err != nil { + t.Fatalf("Error getting message: %v", err) + } + // Put object var putObjectCfg objectStepConfig[*nats.ObjectMeta] - if err := json.Unmarshal(objReq.Data, &putObjectCfg); err != nil { + if err := json.Unmarshal(msg.Data, &putObjectCfg); err != nil { t.Fatalf("Error unmarshalling message: %v", err) } - os, err = js.ObjectStore(putObjectCfg.Bucket) + os, err := js.ObjectStore(putObjectCfg.Bucket) if err != nil { t.Fatalf("Error getting object store: %v", err) } @@ -94,23 +171,130 @@ func TestObjectStoreCompatibility(t *testing.T) { if err != nil { t.Fatalf("Error getting content: %v", err) } + data, err := io.ReadAll(resp.Body) + if err != nil { + t.Fatalf("Error reading content: %v", err) + } defer resp.Body.Close() - if _, err := os.Put(putObjectCfg.Config, resp.Body); err != nil { + if _, err := os.Put(putObjectCfg.Config, bytes.NewBuffer(data)); err != nil { t.Fatalf("Error putting object: %v", err) } - if err := objReq.Respond(nil); err != nil { + if err := msg.Respond(nil); err != nil { t.Fatalf("Error responding to message: %v", err) } - validateStepResult(t, sub) + validateTestResult(t, sub) } -func validateStepResult(t *testing.T, sub *nats.Subscription) { +func TestCompatibilityObjectStoreUpdateMetadata(t *testing.T) { + t.Parallel() + + nc, js := connect(t) + defer nc.Close() + + // setup subscription on which tester will be sending requests + sub, err := nc.SubscribeSync("tests.object-store.update-metadata.>") + if err != nil { + t.Fatalf("Error subscribing to test subject: %v", err) + } + defer sub.Unsubscribe() + + msg, err := sub.NextMsg(1 * time.Hour) + if err != nil { + t.Fatalf("Error getting message: %v", err) + } + // Update object metadata + var putObjectCfg objectStepConfig[*nats.ObjectMeta] + if err := json.Unmarshal(msg.Data, &putObjectCfg); err != nil { + t.Fatalf("Error unmarshalling message: %v", err) + } + os, err := js.ObjectStore(putObjectCfg.Bucket) + if err != nil { + t.Fatalf("Error getting object store: %v", err) + } + if err := os.UpdateMeta(putObjectCfg.Object, putObjectCfg.Config); err != nil { + t.Fatalf("Error putting object: %v", err) + } + if err := msg.Respond(nil); err != nil { + t.Fatalf("Error responding to message: %v", err) + } + validateTestResult(t, sub) +} + +func TestCompatibilityObjectStoreWatch(t *testing.T) { + t.Skip("Skipping test until watch behavior is sorted out in compatibility-tests") + t.Parallel() + + type config struct { + Bucket string `json:"bucket"` + Object string `json:"object"` + } + + nc, js := connect(t) + defer nc.Close() + + // setup subscription on which tester will be sending requests + sub, err := nc.SubscribeSync("tests.object-store.watch.>") + if err != nil { + t.Fatalf("Error subscribing to test subject: %v", err) + } + defer sub.Unsubscribe() + + msg, err := sub.NextMsg(1 * time.Hour) + if err != nil { + t.Fatalf("Error getting message: %v", err) + } + // Watch object + var cfg config + if err := json.Unmarshal(msg.Data, &cfg); err != nil { + t.Fatalf("Error unmarshalling message: %v", err) + } + os, err := js.ObjectStore(cfg.Bucket) + if err != nil { + t.Fatalf("Error getting object store: %v", err) + } + time.Sleep(5 * time.Second) + watcher, err := os.Watch() + if err != nil { + t.Fatalf("Error getting watcher: %v", err) + } + var info *nats.ObjectInfo + select { + case info = <-watcher.Updates(): + fmt.Println(info.Digest) + case <-time.After(30 * time.Second): + t.Fatalf("Timeout waiting for object update") + } + + if err := msg.Respond([]byte(info.Digest)); err != nil { + t.Fatalf("Error responding to message: %v", err) + } + validateTestResult(t, sub) +} + +func validateTestResult(t *testing.T, sub *nats.Subscription) { t.Helper() stepEnd, err := sub.NextMsg(5 * time.Second) if err != nil { t.Fatalf("Error getting message: %v", err) } - if len(stepEnd.Header["STATUS"]) > 0 { - t.Fatalf("Test step failed: %v", stepEnd.Header["STATUS"][0]) + if strings.Contains(string(stepEnd.Subject), "fail") { + t.Fatalf("Test step failed: %v", string(stepEnd.Subject)) + } +} + +func connect(t *testing.T) (*nats.Conn, nats.JetStreamContext) { + t.Helper() + natsURL := os.Getenv("NATS_URL") + if natsURL == "" { + natsURL = nats.DefaultURL + } + nc, err := nats.Connect(natsURL, nats.Timeout(1*time.Hour)) + if err != nil { + t.Fatalf("Error connecting to NATS: %v", err) + } + js, err := nc.JetStream() + if err != nil { + t.Fatalf("Error getting JetStream context: %v", err) } + return nc, js } From 3bf8209a7893ef4405a6781ef8a1b160b4a2d95c Mon Sep 17 00:00:00 2001 From: Piotr Piotrowski Date: Tue, 22 Aug 2023 13:51:02 +0200 Subject: [PATCH 04/11] Add dockerfile for compatibility tests Signed-off-by: Piotr Piotrowski --- test/compat_test.go | 3 +++ test/configs/docker/Dockerfile | 6 ++++++ 2 files changed, 9 insertions(+) create mode 100644 test/configs/docker/Dockerfile diff --git a/test/compat_test.go b/test/compat_test.go index 98d6f5362..9930f7dec 100644 --- a/test/compat_test.go +++ b/test/compat_test.go @@ -1,3 +1,6 @@ +//go:build compat +// +build compat + package test import ( diff --git a/test/configs/docker/Dockerfile b/test/configs/docker/Dockerfile new file mode 100644 index 000000000..d5607cab9 --- /dev/null +++ b/test/configs/docker/Dockerfile @@ -0,0 +1,6 @@ +FROM golang:1.20 +WORKDIR /usr/src/nats.go +COPY . /usr/src/nats.go +RUN go mod tidy -modfile go_test.mod +ENV NATS_URL=localhost:4222 +CMD ["go", "test", "-v", "-run", "TestCompatibility", "-modfile", "go_test.mod", "-tags", "compat", "./test/..."] \ No newline at end of file From b4896d5162cdd78b6d17fabc03bca4153cc3abf2 Mon Sep 17 00:00:00 2001 From: Tomasz Pietrek Date: Wed, 23 Aug 2023 20:43:13 +0200 Subject: [PATCH 05/11] Run tests in Dockerfile Signed-off-by: Tomasz Pietrek --- test/configs/docker/Dockerfile | 1 + 1 file changed, 1 insertion(+) diff --git a/test/configs/docker/Dockerfile b/test/configs/docker/Dockerfile index d5607cab9..f109acbb8 100644 --- a/test/configs/docker/Dockerfile +++ b/test/configs/docker/Dockerfile @@ -2,5 +2,6 @@ FROM golang:1.20 WORKDIR /usr/src/nats.go COPY . /usr/src/nats.go RUN go mod tidy -modfile go_test.mod +RUN go test -run TestNone -modfile go_test.mod -tags compat ./test/... ENV NATS_URL=localhost:4222 CMD ["go", "test", "-v", "-run", "TestCompatibility", "-modfile", "go_test.mod", "-tags", "compat", "./test/..."] \ No newline at end of file From f84d4f74785c4f7c3ab19cd9684dd78f0530f944 Mon Sep 17 00:00:00 2001 From: Tomasz Pietrek Date: Wed, 23 Aug 2023 21:29:36 +0200 Subject: [PATCH 06/11] Add debug log Signed-off-by: Tomasz Pietrek --- test/compat_test.go | 1 + 1 file changed, 1 insertion(+) diff --git a/test/compat_test.go b/test/compat_test.go index 9930f7dec..63eb29c1d 100644 --- a/test/compat_test.go +++ b/test/compat_test.go @@ -70,6 +70,7 @@ func TestCompatibilityObjectStoreCustomBucket(t *testing.T) { t.Fatalf("Error subscribing to test subject: %v", err) } defer sub.Unsubscribe() + fmt.Println("WAITING FOR CUSTOM BUCKET RUN") // 1. Create custom bucket msg, err := sub.NextMsg(1 * time.Hour) From f3219ec2efae6480d03c6676c7ddee98a2d60680 Mon Sep 17 00:00:00 2001 From: Tomasz Pietrek Date: Thu, 24 Aug 2023 21:11:09 +0200 Subject: [PATCH 07/11] Add more logs --- test/compat_test.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/compat_test.go b/test/compat_test.go index 63eb29c1d..f1ffb6675 100644 --- a/test/compat_test.go +++ b/test/compat_test.go @@ -90,6 +90,8 @@ func TestCompatibilityObjectStoreCustomBucket(t *testing.T) { if err := msg.Respond(nil); err != nil { t.Fatalf("Error responding to message: %v", err) } + + fmt.Println("CUSTOM BUCKET RUN DONE") validateTestResult(t, sub) } From b3246f2ca62e1589754bb437c0dcfc8d6035bde7 Mon Sep 17 00:00:00 2001 From: Tomasz Pietrek Date: Fri, 25 Aug 2023 08:05:20 +0200 Subject: [PATCH 08/11] Add count to Dockerfile --- test/configs/docker/Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/configs/docker/Dockerfile b/test/configs/docker/Dockerfile index f109acbb8..4f106e5a1 100644 --- a/test/configs/docker/Dockerfile +++ b/test/configs/docker/Dockerfile @@ -4,4 +4,4 @@ COPY . /usr/src/nats.go RUN go mod tidy -modfile go_test.mod RUN go test -run TestNone -modfile go_test.mod -tags compat ./test/... ENV NATS_URL=localhost:4222 -CMD ["go", "test", "-v", "-run", "TestCompatibility", "-modfile", "go_test.mod", "-tags", "compat", "./test/..."] \ No newline at end of file +CMD go test -v -run TestCompatibility -modfile go_test.mod -tags compat ./test/... -count 1 From 3e9d96b5d4b53c8fa4a3fa8d1a631013a0196cbc Mon Sep 17 00:00:00 2001 From: Tomasz Pietrek Date: Fri, 25 Aug 2023 08:55:02 +0200 Subject: [PATCH 09/11] Fix tests Signed-off-by: Tomasz Pietrek --- test/compat_test.go | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/test/compat_test.go b/test/compat_test.go index f1ffb6675..e354faa7e 100644 --- a/test/compat_test.go +++ b/test/compat_test.go @@ -70,7 +70,6 @@ func TestCompatibilityObjectStoreCustomBucket(t *testing.T) { t.Fatalf("Error subscribing to test subject: %v", err) } defer sub.Unsubscribe() - fmt.Println("WAITING FOR CUSTOM BUCKET RUN") // 1. Create custom bucket msg, err := sub.NextMsg(1 * time.Hour) @@ -91,7 +90,6 @@ func TestCompatibilityObjectStoreCustomBucket(t *testing.T) { t.Fatalf("Error responding to message: %v", err) } - fmt.Println("CUSTOM BUCKET RUN DONE") validateTestResult(t, sub) } @@ -226,8 +224,9 @@ func TestCompatibilityObjectStoreUpdateMetadata(t *testing.T) { validateTestResult(t, sub) } -func TestCompatibilityObjectStoreWatch(t *testing.T) { - t.Skip("Skipping test until watch behavior is sorted out in compatibility-tests") +func TestCompatibilityObjectStoreWatchUpdates(t *testing.T) { + // Skipped until watching only for changes only is added. + t.Skip() t.Parallel() type config struct { @@ -239,7 +238,7 @@ func TestCompatibilityObjectStoreWatch(t *testing.T) { defer nc.Close() // setup subscription on which tester will be sending requests - sub, err := nc.SubscribeSync("tests.object-store.watch.>") + sub, err := nc.SubscribeSync("tests.object-store.watch-updates.>") if err != nil { t.Fatalf("Error subscribing to test subject: %v", err) } From 638d8723e4483951e742f945a5dbccd7da07ca1f Mon Sep 17 00:00:00 2001 From: Tomasz Pietrek Date: Fri, 25 Aug 2023 08:56:49 +0200 Subject: [PATCH 10/11] Set parallel value for test Signed-off-by: Tomasz Pietrek --- test/configs/docker/Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/configs/docker/Dockerfile b/test/configs/docker/Dockerfile index 4f106e5a1..450acedea 100644 --- a/test/configs/docker/Dockerfile +++ b/test/configs/docker/Dockerfile @@ -4,4 +4,4 @@ COPY . /usr/src/nats.go RUN go mod tidy -modfile go_test.mod RUN go test -run TestNone -modfile go_test.mod -tags compat ./test/... ENV NATS_URL=localhost:4222 -CMD go test -v -run TestCompatibility -modfile go_test.mod -tags compat ./test/... -count 1 +CMD go test -v -run TestCompatibility -modfile go_test.mod -tags compat ./test/... -count 1 -parallel 10 From 02911db80342d64a0b77916bc27619aac625e99f Mon Sep 17 00:00:00 2001 From: Piotr Piotrowski Date: Mon, 28 Aug 2023 12:50:22 +0200 Subject: [PATCH 11/11] Fix watcher test to use UpdatesOnly Signed-off-by: Piotr Piotrowski --- test/compat_test.go | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/test/compat_test.go b/test/compat_test.go index e354faa7e..8054fd236 100644 --- a/test/compat_test.go +++ b/test/compat_test.go @@ -7,7 +7,6 @@ import ( "bytes" "crypto/sha256" "encoding/json" - "fmt" "io" "net/http" "os" @@ -225,8 +224,6 @@ func TestCompatibilityObjectStoreUpdateMetadata(t *testing.T) { } func TestCompatibilityObjectStoreWatchUpdates(t *testing.T) { - // Skipped until watching only for changes only is added. - t.Skip() t.Parallel() type config struct { @@ -257,15 +254,13 @@ func TestCompatibilityObjectStoreWatchUpdates(t *testing.T) { if err != nil { t.Fatalf("Error getting object store: %v", err) } - time.Sleep(5 * time.Second) - watcher, err := os.Watch() + watcher, err := os.Watch(nats.UpdatesOnly()) if err != nil { t.Fatalf("Error getting watcher: %v", err) } var info *nats.ObjectInfo select { case info = <-watcher.Updates(): - fmt.Println(info.Digest) case <-time.After(30 * time.Second): t.Fatalf("Timeout waiting for object update") }