Skip to content

Commit

Permalink
fix buf of sending ack to source
Browse files Browse the repository at this point in the history
  • Loading branch information
chensheng0 authored and ludanfeng committed Aug 13, 2020
1 parent 070749d commit d0e9c96
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
2 changes: 1 addition & 1 deletion rule/ruler.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ func newRuler(rule RuleInfo, clients map[string]ClientInfo) (*Ruler, error) {
}
}
if target == nil || len(data) == 0 {
if rule.Source.QOS == 1 {
if pkt.Message.QOS == 1 {
puback := packet.NewPuback()
puback.ID = pkt.ID
err := source.SendOrDrop(puback)
Expand Down
16 changes: 15 additions & 1 deletion rule/ruler_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package rule

import (
"encoding/json"
"errors"
"fmt"
"io/ioutil"
Expand Down Expand Up @@ -326,11 +327,17 @@ rules:
fmt.Println("--> test rule2 passed <--")

// test rule3
pub6 := newPublishPacket(1, 1, "group1/topic5", `{"name":"topic5"}`)
pub6 := newPublishPacket(1, 1, "group1/topic5", `{"empty":"true"}`)
err = cli6.pub(pub6)
assert.NoError(t, err)
cli5.assertS2CPacketTimeout()

pub61 := newPublishPacket(1, 1, "group1/topic5", `{"notempty":"true"}`)
err = cli6.pub(pub61)
assert.NoError(t, err)
cli5.assertS2CPacket(fmt.Sprintf("<Publish ID=1 Message=<Message Topic=\"group1/topic6\" QOS=1 Retain=false Payload=%x> Dup=false>", `{"hello"":"notempty"}`))
cli5.assertS2CPacketTimeout()

fmt.Println("--> test rule3 passed <--")

// test rule4
Expand Down Expand Up @@ -568,6 +575,13 @@ func newHttp(t *testing.T, port int, funcSucc, funcErr, funcEmpty string) {
return errors.New("func error")
})
router.Post("/"+funcEmpty, func(c *routing.Context) error {
value := map[string]string{}
err := json.Unmarshal(c.Request.Body(), &value)
assert.NoError(t, err)
if _, ok := value["empty"]; !ok {
c.Response.Header.Set("Content-Type", "application/json")
c.SetBody([]byte(`{"hello"":"notempty"}`))
}
return nil
})
go func() {
Expand Down

0 comments on commit d0e9c96

Please sign in to comment.