-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsubscription_config_test.go
More file actions
94 lines (83 loc) · 3.23 KB
/
subscription_config_test.go
File metadata and controls
94 lines (83 loc) · 3.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
// Copyright (c) 2025 Uber Technologies, Inc.
//
// 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
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package messagequeue
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestSubscriptionConfig_FieldsAreIndependent(t *testing.T) {
// Create two configs and modify one to ensure they're independent
config1 := DefaultSubscriptionConfig("worker-1", "consumer-1")
config2 := DefaultSubscriptionConfig("worker-2", "consumer-2")
// Modify config1
config1.PollIntervalMs = 500
config1.BatchSize = 100
config1.Retry.MaxAttempts = 5
config1.DLQ.TopicSuffix = "_failed"
// Verify config2 is unaffected
assert.Equal(t, "worker-2", config2.SubscriberName)
assert.Equal(t, "consumer-2", config2.ConsumerGroup)
assert.Equal(t, int64(100), config2.PollIntervalMs)
assert.Equal(t, 10, config2.BatchSize)
assert.Equal(t, 3, config2.Retry.MaxAttempts)
assert.Equal(t, "_dlq", config2.DLQ.TopicSuffix)
}
func TestSubscriptionConfig_CustomValues(t *testing.T) {
config := DefaultSubscriptionConfig("my-worker", "my-consumer")
// Override with custom values (in milliseconds)
config.PollIntervalMs = 200
config.BatchSize = 50
config.VisibilityTimeoutMs = 120000
config.LeaseRenewalIntervalMs = 20000
config.LeaseDurationMs = 60000
config.Retry.MaxAttempts = 5
config.Retry.InitialBackoffMs = 2000
config.Retry.MaxBackoffMs = 60000
config.Retry.BackoffMultiplier = 3.0
config.DLQ.Enabled = false
config.DLQ.TopicSuffix = "_dead"
// Verify all custom values
assert.Equal(t, "my-worker", config.SubscriberName)
assert.Equal(t, "my-consumer", config.ConsumerGroup)
assert.Equal(t, int64(200), config.PollIntervalMs)
assert.Equal(t, 50, config.BatchSize)
assert.Equal(t, int64(120000), config.VisibilityTimeoutMs)
assert.Equal(t, int64(20000), config.LeaseRenewalIntervalMs)
assert.Equal(t, int64(60000), config.LeaseDurationMs)
assert.Equal(t, 5, config.Retry.MaxAttempts)
assert.Equal(t, int64(2000), config.Retry.InitialBackoffMs)
assert.Equal(t, int64(60000), config.Retry.MaxBackoffMs)
assert.Equal(t, 3.0, config.Retry.BackoffMultiplier)
assert.False(t, config.DLQ.Enabled)
assert.Equal(t, "_dead", config.DLQ.TopicSuffix)
}
func TestSubscriptionConfig_DifferentConsumerGroups(t *testing.T) {
// Test that different consumer groups get independent configs
tests := []struct {
subscriberName string
consumerGroup string
}{
{"worker-1", "group-A"},
{"worker-1", "group-B"},
{"worker-2", "group-A"},
}
for _, tt := range tests {
t.Run(tt.subscriberName+"_"+tt.consumerGroup, func(t *testing.T) {
config := DefaultSubscriptionConfig(tt.subscriberName, tt.consumerGroup)
require.Equal(t, tt.subscriberName, config.SubscriberName)
require.Equal(t, tt.consumerGroup, config.ConsumerGroup)
})
}
}