Skip to content

Commit

Permalink
[FIXED] Fix tests against main server branch (#1764)
Browse files Browse the repository at this point in the history
Signed-off-by: Piotr Piotrowski <piotr@synadia.com>
  • Loading branch information
piotrpio authored Jan 15, 2025
1 parent f50c665 commit 4732ef6
Show file tree
Hide file tree
Showing 11 changed files with 67 additions and 32 deletions.
2 changes: 1 addition & 1 deletion jetstream/object.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2023-2024 The NATS Authors
// Copyright 2023-2025 The NATS Authors
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
Expand Down
28 changes: 17 additions & 11 deletions jetstream/test/jetstream_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2022-2024 The NATS Authors
// Copyright 2022-2025 The NATS Authors
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
Expand Down Expand Up @@ -301,8 +301,10 @@ func TestCreateStream(t *testing.T) {
if err != nil {
t.Fatalf("Unexpected error: %v", err)
}
if !reflect.DeepEqual(s.CachedInfo().Config.Metadata, test.metadata) {
t.Fatalf("Invalid metadata; want: %v, got: %v", test.metadata, s.CachedInfo().Config.Metadata)
for k, v := range test.metadata {
if s.CachedInfo().Config.Metadata[k] != v {
t.Fatalf("Invalid metadata; want: %v, got: %v", test.metadata, s.CachedInfo().Config.Metadata)
}
}
})
}
Expand Down Expand Up @@ -692,8 +694,10 @@ func TestUpdateStream(t *testing.T) {
if len(info.Config.Subjects) != 1 || info.Config.Subjects[0] != test.subject {
t.Fatalf("Invalid stream subjects after update: %v", info.Config.Subjects)
}
if !reflect.DeepEqual(info.Config.Metadata, test.metadata) {
t.Fatalf("Invalid metadata; want: %v, got: %v", test.metadata, info.Config.Metadata)
for k, v := range test.metadata {
if info.Config.Metadata[k] != v {
t.Fatalf("Invalid metadata; want: %v, got: %v", test.metadata, info.Config.Metadata)
}
}
})
}
Expand Down Expand Up @@ -1834,15 +1838,14 @@ func TestStreamConfigMatches(t *testing.T) {
InactiveThreshold: 10 * time.Second,
MaxAckPending: 500,
},
Metadata: map[string]string{
"foo": "bar",
},
}

s, err := js.CreateStream(context.Background(), cfg)
if err != nil {
t.Fatalf("Unexpected error: %v", err)
}
// server will set metadata values, so we need to clear them
s.CachedInfo().Config.Metadata = nil
if !reflect.DeepEqual(s.CachedInfo().Config, cfg) {
t.Fatalf("StreamConfig doesn't match: %#v", s.CachedInfo().Config)
}
Expand Down Expand Up @@ -1872,6 +1875,8 @@ func TestStreamConfigMatches(t *testing.T) {
if err != nil {
t.Fatalf("Unexpected error: %v", err)
}
// server will set metadata values, so we need to clear them
s.CachedInfo().Config.Metadata = nil
if !reflect.DeepEqual(s.CachedInfo().Config, cfgMirror) {
t.Fatalf("StreamConfig doesn't match: %#v", s.CachedInfo().Config)
}
Expand Down Expand Up @@ -1903,6 +1908,8 @@ func TestStreamConfigMatches(t *testing.T) {
if err != nil {
t.Fatalf("Unexpected error: %v", err)
}
// server will set metadata values, so we need to clear them
s.CachedInfo().Config.Metadata = nil
if !reflect.DeepEqual(s.CachedInfo().Config, cfgSourcing) {
t.Fatalf("StreamConfig doesn't match: %#v", s.CachedInfo().Config)
}
Expand Down Expand Up @@ -1950,15 +1957,14 @@ func TestConsumerConfigMatches(t *testing.T) {
Replicas: 1,
MemoryStorage: true,
FilterSubjects: []string{"foo.1", "foo.2"},
Metadata: map[string]string{
"foo": "bar",
},
}

c, err := s.CreateConsumer(context.Background(), cfg)
if err != nil {
t.Fatalf("Unexpected error: %v", err)
}
// server will set metadata values, so we need to clear them
c.CachedInfo().Config.Metadata = nil
if !reflect.DeepEqual(c.CachedInfo().Config, cfg) {
t.Fatalf("ConsumerConfig doesn't match")
}
Expand Down
4 changes: 3 additions & 1 deletion jetstream/test/kv_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2023-2024 The NATS Authors
// Copyright 2023-2025 The NATS Authors
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
Expand Down Expand Up @@ -1680,6 +1680,8 @@ func TestKeyValueCreate(t *testing.T) {
if err != nil {
t.Fatalf("Error getting stream: %v", err)
}
// server will set metadata values, so we need to clear them
stream.CachedInfo().Config.Metadata = nil
if !reflect.DeepEqual(stream.CachedInfo().Config, expectedStreamConfig) {
t.Fatalf("Expected stream config to be %+v, got %+v", expectedStreamConfig, stream.CachedInfo().Config)
}
Expand Down
8 changes: 5 additions & 3 deletions jetstream/test/object_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2023-2024 The NATS Authors
// Copyright 2023-2025 The NATS Authors
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
Expand Down Expand Up @@ -477,8 +477,10 @@ func TestObjectMetadata(t *testing.T) {
expectOk(t, err)
status, err := obs.Status(ctx)
expectOk(t, err)
if !reflect.DeepEqual(status.Metadata(), bucketMetadata) {
t.Fatalf("invalid bucket metadata: %+v", status.Metadata())
for k, v := range bucketMetadata {
if status.Metadata()[k] != v {
t.Fatalf("invalid bucket metadata: %+v", status.Metadata())
}
}

// Simple with no Meta.
Expand Down
10 changes: 9 additions & 1 deletion jetstream/test/ordered_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2022-2023 The NATS Authors
// Copyright 2022-2025 The NATS Authors
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
Expand Down Expand Up @@ -2109,6 +2109,14 @@ func TestOrderedConsumerConfig(t *testing.T) {
cfg := c.CachedInfo().Config
test.expected.Name = cfg.Name

if test.config.Metadata != nil {
for k, v := range test.config.Metadata {
if cfg.Metadata[k] != v {
t.Fatalf("Expected config %+v, got %+v", test.expected, cfg)
}
}
}
test.expected.Metadata = cfg.Metadata
if !reflect.DeepEqual(test.expected, cfg) {
t.Fatalf("Expected config %+v, got %+v", test.expected, cfg)
}
Expand Down
8 changes: 5 additions & 3 deletions jetstream/test/stream_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2022-2023 The NATS Authors
// Copyright 2022-2025 The NATS Authors
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
Expand Down Expand Up @@ -268,8 +268,10 @@ func TestCreateConsumer(t *testing.T) {
if !reflect.DeepEqual(test.consumerConfig.FilterSubjects, ci.CachedInfo().Config.FilterSubjects) {
t.Fatalf("Invalid filter subjects; want: %v; got: %v", test.consumerConfig.FilterSubjects, ci.CachedInfo().Config.FilterSubjects)
}
if !reflect.DeepEqual(test.consumerConfig.Metadata, ci.CachedInfo().Config.Metadata) {
t.Fatalf("Invalid metadata; want: %v; got: %v", test.consumerConfig.Metadata, ci.CachedInfo().Config.Metadata)
for k, v := range test.consumerConfig.Metadata {
if ci.CachedInfo().Config.Metadata[k] != v {
t.Fatalf("Invalid metadata; want: %v; got: %v", test.consumerConfig.Metadata, ci.CachedInfo().Config.Metadata)
}
}
})
}
Expand Down
1 change: 1 addition & 0 deletions js.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ type JetStream interface {
// PullSubscribe creates a Subscription that can fetch messages.
// See important note in Subscribe(). Additionally, for an ephemeral pull consumer, the "durable" value must be
// set to an empty string.
// When using PullSubscribe, the messages are fetched using Fetch() and FetchBatch() methods.
PullSubscribe(subj, durable string, opts ...SubOpt) (*Subscription, error)
}

Expand Down
15 changes: 9 additions & 6 deletions test/js_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2020-2024 The NATS Authors
// Copyright 2020-2025 The NATS Authors
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
Expand Down Expand Up @@ -2289,7 +2289,7 @@ func TestJetStreamManagement(t *testing.T) {
if si == nil || si.Config.Name != "foo" {
t.Fatalf("StreamInfo is not correct %+v", si)
}
if !reflect.DeepEqual(si.Config.Metadata, map[string]string{"foo": "bar", "baz": "quux"}) {
if v1, v2 := si.Config.Metadata["foo"], si.Config.Metadata["baz"]; v1 != "bar" || v2 != "quux" {
t.Fatalf("Metadata is not correct %+v", si.Config.Metadata)
}
if si.Config.Compression != nats.S2Compression {
Expand Down Expand Up @@ -2406,7 +2406,7 @@ func TestJetStreamManagement(t *testing.T) {
if ci == nil || ci.Name != "dlc" || ci.Stream != "foo" {
t.Fatalf("ConsumerInfo is not correct %+v", ci)
}
if !reflect.DeepEqual(ci.Config.Metadata, map[string]string{"foo": "bar", "baz": "quux"}) {
if v1, v2 := ci.Config.Metadata["foo"], ci.Config.Metadata["baz"]; v1 != "bar" || v2 != "quux" {
t.Fatalf("Metadata is not correct %+v", ci.Config.Metadata)
}
})
Expand Down Expand Up @@ -2955,15 +2955,14 @@ func TestStreamConfigMatches(t *testing.T) {
InactiveThreshold: 10 * time.Second,
MaxAckPending: 500,
},
Metadata: map[string]string{
"foo": "bar",
},
}

s, err := js.AddStream(&cfg)
if err != nil {
t.Fatalf("Unexpected error: %v", err)
}
// server will set metadata values, so we need to clear them
s.Config.Metadata = nil
if !reflect.DeepEqual(s.Config, cfg) {
t.Fatalf("StreamConfig doesn't match: %#v", s.Config)
}
Expand Down Expand Up @@ -2993,6 +2992,8 @@ func TestStreamConfigMatches(t *testing.T) {
if err != nil {
t.Fatalf("Unexpected error: %v", err)
}
// server will set metadata values, so we need to clear them
s.Config.Metadata = nil
if !reflect.DeepEqual(s.Config, cfgMirror) {
t.Fatalf("StreamConfig doesn't match: %#v", s.Config)
}
Expand Down Expand Up @@ -3024,6 +3025,8 @@ func TestStreamConfigMatches(t *testing.T) {
if err != nil {
t.Fatalf("Unexpected error: %v", err)
}
// server will set metadata values, so we need to clear them
s.Config.Metadata = nil
if !reflect.DeepEqual(s.Config, cfgSourcing) {
t.Fatalf("StreamConfig doesn't match: %#v", s.Config)
}
Expand Down
4 changes: 3 additions & 1 deletion test/kv_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2021-2023 The NATS Authors
// Copyright 2021-2025 The NATS Authors
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
Expand Down Expand Up @@ -1504,6 +1504,8 @@ func TestKeyValueCreate(t *testing.T) {
if err != nil {
t.Fatalf("Error getting stream info: %v", err)
}
// Metadata is set by the server, so we need to set it here.
expectedStreamConfig.Metadata = si.Config.Metadata
if !reflect.DeepEqual(si.Config, expectedStreamConfig) {
t.Fatalf("Expected stream config to be %+v, got %+v", expectedStreamConfig, si.Config)
}
Expand Down
11 changes: 9 additions & 2 deletions test/norace_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2019-2023 The NATS Authors
// Copyright 2019-2025 The NATS Authors
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
Expand Down Expand Up @@ -736,7 +736,14 @@ func TestNoRaceJetStreamChanSubscribeStall(t *testing.T) {
toSend := 100_000
for i := 0; i < toSend; i++ {
// Use plain NATS here for speed.
nc.Publish("STALL", msg)
if _, err := js.PublishAsync("STALL", msg); err != nil {
t.Fatalf("Unexpected error: %v", err)
}
}
select {
case <-js.PublishAsyncComplete():
case <-time.After(5 * time.Second):
t.Fatalf("Timeout waiting for messages")
}
nc.Flush()

Expand Down
8 changes: 5 additions & 3 deletions test/object_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2022-2023 The NATS Authors
// Copyright 2022-2025 The NATS Authors
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
Expand Down Expand Up @@ -409,8 +409,10 @@ func TestObjectMetadata(t *testing.T) {
expectOk(t, err)
status, err := obs.Status()
expectOk(t, err)
if !reflect.DeepEqual(status.Metadata(), bucketMetadata) {
t.Fatalf("invalid bucket metadata: %+v", status.Metadata())
for k, v := range bucketMetadata {
if status.Metadata()[k] != v {
t.Fatalf("invalid bucket metadata: %+v", status.Metadata())
}
}

// Simple with no Meta.
Expand Down

0 comments on commit 4732ef6

Please sign in to comment.