Fix sid for split messages

When message is split we need to copy message arguments to avoid
rewriting them with new message. Subject, reply and size were correctly
copied by sid wasn't. That led to dropping some messages in clustered
mode if they were split, and the second part was long enough to overwrite
sid in the original buffer.
This commit is contained in:
Oleg Shaldybin
2015-04-07 22:23:47 -07:00
parent 7f794ad78f
commit 1b39a9fe94
3 changed files with 38 additions and 1 deletions

View File

@@ -341,3 +341,31 @@ func TestSplitDanglingArgBuf(t *testing.T) {
t.Fatalf("Expected c.argBuf to be nil: %q\n", c.argBuf)
}
}
func TestSplitMsgArg(t *testing.T) {
_, c, _ := setupClient()
b := make([]byte, 1024)
copy(b, []byte("MSG hello.world RSID:14:8 6040\r\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"))
c.parse(b)
copy(b, []byte("BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB\r\n"))
c.parse(b)
wantSubject := "hello.world"
wantSid := "RSID:14:8"
wantSzb := "6040"
if string(c.pa.subject) != wantSubject {
t.Fatalf("Incorrect subject: want %q, got %q", wantSubject, c.pa.subject)
}
if string(c.pa.sid) != wantSid {
t.Fatalf("Incorrect sid: want %q, got %q", wantSid, c.pa.sid)
}
if string(c.pa.szb) != wantSzb {
t.Fatalf("Incorrect szb: want %q, got %q", wantSzb, c.pa.szb)
}
}