fix kafka message persistence completion

This commit is contained in:
richjohnrambo
2026-10-12 09:19:28 +08:00
parent c219ef6455
commit 5d792f9f96
4 changed files with 84 additions and 3 deletions
+28
View File
@@ -8,6 +8,7 @@ import (
"time"
"github.com/segmentio/kafka-go"
"github.com/tinode/chat/server/store"
"github.com/tinode/chat/server/store/types"
)
@@ -253,3 +254,30 @@ func TestRunKafkaMessageSingleRetriesStopsOnSuccess(t *testing.T) {
t.Fatalf("calls operation=%d failed=%d, want 3/2", operationCalls, markFailedCalls)
}
}
func TestFinishKafkaMessagePersistTreatsMissingConsumeStateAsSucceeded(t *testing.T) {
oldInfrastructure := store.HTTPInfrastructure
oldKafkaBus := kafkaBus
defer func() {
store.HTTPInfrastructure = oldInfrastructure
kafkaBus = oldKafkaBus
}()
store.HTTPInfrastructure = &testHTTPInfrastructureStore{markSucceededErr: types.ErrNotFound}
kafkaBus = &kafkaRuntime{config: kafkaConfig{ConsumerGroup: "test-consumer"}}
err := finishKafkaMessagePersist(context.Background(), &kafkaMessagePersistItem{
envelope: kafkaEnvelope{EventID: "msg.persist.8.p2pA.1"},
tenantID: types.TenantID(8),
payload: kafkaMessagePersistPayload{
MessageKind: "p2p",
Message: types.Message{
Topic: "p2pA",
SeqId: 1,
},
},
})
if err != nil {
t.Fatalf("finishKafkaMessagePersist() error = %v, want nil", err)
}
}