Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: config overwritten by default values #416

Merged
merged 1 commit into from
Aug 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Fix: config overwritten by default values
  • Loading branch information
Neng Wan committed Aug 15, 2022
commit 70a803e3fd1a073c499b3408686fe036d5063589
2 changes: 1 addition & 1 deletion app.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ func GetConfigByPrefix(config *viper.Viper, prefix string, trimPrefix bool) *vip
if trimPrefix {
key = k[len(prefix):]
}
subConfig.SetDefault(key, v)
subConfig.Set(key, v)
}
return subConfig
}
2 changes: 1 addition & 1 deletion extensions/busext/amqp.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ func (b *BusExt) Push(exchange, routingKey string, data amqp.Publishing) error {

func (b *BusExt) doPush(ctx context.Context, exchange, routingKey string, data amqp.Publishing, result chan error) {
log.Printf("Trying to publish: %s\n", data.Headers["id"])
for i := 0; i <= b.publishRetry; i++ {
for i := 0; i < b.publishRetry; i++ {
// clear staled confirmnation
// 有可能在超时之后才收到 confirm,会堵塞 channel,最终造成死锁
select {
Expand Down
6 changes: 6 additions & 0 deletions extensions/busext/amqp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,12 @@ func TestPushConsume(t *testing.T) {
time.Sleep(2 * time.Second)
assert.Len(t, result, 100)

// check config works
assert.NotEqual(t, defaultPublishRetry, bus.publishRetry)
assert.Equal(t, 5, bus.publishRetry)
assert.NotEqual(t, defaultPushTimeout, bus.pushTimeout)
assert.Equal(t, time.Second * 3, bus.pushTimeout)

// mock amqp 的 publish, 使其 sleep 一个远比设置的 pushTimeout 长的时间, 模拟其卡死的情况
bus.publishFunc = func(exchange, key string, mandatory, immediate bool, msg amqp.Publishing) error {
dur := 100 * bus.pushTimeout
Expand Down
3 changes: 2 additions & 1 deletion testdata/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ defaults: &defaults
bus_queues:
- test
bus_resend_delay: "1s"
bus_publish_retry: 3
bus_publish_retry: 5
bus_push_timeout: "3s"
bus_prefetch: 10
bus_quit_consumer_on_empty_queue: false
bus_bindings:
Expand Down