blob: cc6ce708bbf9172c57abaae44ebccf1d0f0f539a (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
|
package dedupe_test
import (
"crypto/md5"
"github.com/crypto-smoke/meshtastic-go/dedupe"
"testing"
"time"
)
func TestPacketDeduplicatorSeen(t *testing.T) {
hasher := md5.New()
expiresAfter := 100 * time.Millisecond
dedup := dedupe.NewDeduplicator(hasher, expiresAfter)
sender := uint32(1)
packetID := uint32(1)
// Test Seen with new packetID
if dedup.Seen(sender, packetID) {
t.Error("Expected the packet to not have been seen")
}
// Test Seen with same packetID again
if !dedup.Seen(sender, packetID) {
t.Error("Expected the packet to have been seen")
}
// Wait for expiration
time.Sleep(expiresAfter + 100*time.Millisecond)
// Test Seen with same packetID after expiration
if dedup.Seen(sender, packetID) {
t.Error("Expected the packet to not have been seen after expiration")
}
}
func TestPacketDeduplicatorSeenData(t *testing.T) {
hasher := md5.New()
expiresAfter := 100 * time.Millisecond
dedup := dedupe.NewDeduplicator(hasher, expiresAfter)
data := []byte("test data")
// Test SeenData with new data
if dedup.SeenData(data) {
t.Error("Expected the data to not have been seen")
}
// Test SeenData with same data again
if !dedup.SeenData(data) {
t.Error("Expected the data to have been seen")
}
// Wait for expiration
time.Sleep(expiresAfter + 100*time.Millisecond)
// Test SeenData with same data after expiration
if dedup.SeenData(data) {
t.Error("Expected the data to not have been seen after expiration")
}
}
|