test(wecom): add dedupe helper coverage and align constant usage

Use wecomMaxProcessedMessages in tests and add a concurrent same-message test
to lock in race-safety behavior for markMessageProcessed.
This commit is contained in:
esubaalew
2026-02-24 14:55:24 +03:00
parent db17cdc86d
commit 1e2ab4a5e5
+33 -2
View File
@@ -9,15 +9,46 @@ func TestMarkMessageProcessed_DuplicateDetection(t *testing.T) {
var mu sync.RWMutex
processed := make(map[string]bool)
if ok := markMessageProcessed(&mu, &processed, "msg-1", 1000); !ok {
if ok := markMessageProcessed(&mu, &processed, "msg-1", wecomMaxProcessedMessages); !ok {
t.Fatalf("first message should be accepted")
}
if ok := markMessageProcessed(&mu, &processed, "msg-1", 1000); ok {
if ok := markMessageProcessed(&mu, &processed, "msg-1", wecomMaxProcessedMessages); ok {
t.Fatalf("duplicate message should be rejected")
}
}
func TestMarkMessageProcessed_ConcurrentSameMessage(t *testing.T) {
var mu sync.RWMutex
processed := make(map[string]bool)
const goroutines = 64
var wg sync.WaitGroup
wg.Add(goroutines)
results := make(chan bool, goroutines)
for i := 0; i < goroutines; i++ {
go func() {
defer wg.Done()
results <- markMessageProcessed(&mu, &processed, "msg-concurrent", wecomMaxProcessedMessages)
}()
}
wg.Wait()
close(results)
successes := 0
for ok := range results {
if ok {
successes++
}
}
if successes != 1 {
t.Fatalf("expected exactly 1 successful mark, got %d", successes)
}
}
func TestMarkMessageProcessed_RotationClearsMapAtBoundary(t *testing.T) {
var mu sync.RWMutex
processed := make(map[string]bool)