58 lines
1.7 KiB
Go
58 lines
1.7 KiB
Go
//go:build integration
|
|
|
|
package process
|
|
|
|
import (
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/nats-io/nats.go/jetstream"
|
|
|
|
stdio "git.novox.be/novox/mesh-sdk/go"
|
|
)
|
|
|
|
// 1188/AC3: given a stream accepting mail.send.sent, when the process emits it twice with the same
|
|
// message id inside the duplicate window, then the stream holds one message; with the headers stdio's
|
|
// Emit sets (stdio.go:498-509).
|
|
func TestEmitTwiceWithTheSameIDIsKeptToOneWithTheSDKsHeaders(t *testing.T) {
|
|
url, account := grantedSendProcess(t)
|
|
account.Node = "novox"
|
|
_, adminJetStream := adminJS(t, url)
|
|
stream, err := adminJetStream.CreateStream(ctxFor(t), jetstream.StreamConfig{
|
|
Name: "MAIL_EVENTS", Subjects: []string{"mesh.mod.mesh-mail.event.>"}, Duplicates: time.Minute,
|
|
})
|
|
if err != nil {
|
|
t.Fatalf("the admin could not make the events stream: %v", err)
|
|
}
|
|
|
|
conn, err := Connect(account)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
defer conn.Close()
|
|
|
|
for i := 0; i < 2; i++ {
|
|
if err := conn.Emit("mail.send.sent", map[string]any{"send": "s1"}, stdio.EmitOptions{MessageID: "send-s1"}); err != nil {
|
|
t.Fatalf("emit %d: %v", i, err)
|
|
}
|
|
}
|
|
|
|
info, err := stream.Info(ctxFor(t))
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if info.State.Msgs != 1 {
|
|
t.Fatalf("the stream holds %d messages, want exactly 1 (the second publish is a duplicate)", info.State.Msgs)
|
|
}
|
|
|
|
msg, err := stream.GetMsg(ctxFor(t), 1)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if msg.Header.Get("x-event-id") != "send-s1" || msg.Header.Get("x-source") != "mesh-mail" ||
|
|
msg.Header.Get("x-node") != "novox" || msg.Header.Get("content-type") != "application/json" ||
|
|
msg.Header.Get("x-time") == "" {
|
|
t.Errorf("the stored message's headers are not the SDK's: %v", msg.Header)
|
|
}
|
|
}
|