forked from dunglas/mercure
-
Notifications
You must be signed in to change notification settings - Fork 0
/
topic_selector_ristretto_test.go
47 lines (35 loc) · 1.65 KB
/
topic_selector_ristretto_test.go
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
package mercure
import (
"testing"
"time"
"github.com/dgraph-io/ristretto"
"github.com/stretchr/testify/assert"
)
func TestMatchRistretto(t *testing.T) {
cache, _ := ristretto.NewCache(&ristretto.Config[string, interface{}]{
NumCounters: TopicSelectorStoreRistrettoDefaultCacheNumCounters,
MaxCost: TopicSelectorStoreRistrettoCacheMaxCost,
BufferItems: 64,
})
tss := &TopicSelectorStore{cache, false}
assert.True(t, tss.match("https://example.com/foo/bar", "https://example.com/{foo}/bar"))
// wait for value to pass through ristretto's buffers
cache.Wait()
_, found := tss.cache.Get("t_https://example.com/{foo}/bar")
assert.True(t, found)
_, found = tss.cache.Get("m_https://example.com/{foo}/bar_https://example.com/foo/bar")
assert.True(t, found)
assert.True(t, tss.match("https://example.com/foo/bar", "https://example.com/{foo}/bar"))
assert.False(t, tss.match("https://example.com/foo/bar/baz", "https://example.com/{foo}/bar"))
// wait for value to pass through ristretto's buffers, see https://discuss.dgraph.io/t/there-should-be-a-test-only-blocking-mode/8424
time.Sleep(10 * time.Millisecond)
_, found = tss.cache.Get("t_https://example.com/{foo}/bar")
assert.True(t, found)
_, found = tss.cache.Get("m_https://example.com/{foo}/bar_https://example.com/foo/bar")
assert.True(t, found)
assert.True(t, tss.match("https://example.com/kevin/dunglas", "https://example.com/{fistname}/{lastname}"))
assert.True(t, tss.match("https://example.com/foo/bar", "*"))
assert.True(t, tss.match("https://example.com/foo/bar", "https://example.com/foo/bar"))
assert.True(t, tss.match("foo", "foo"))
assert.False(t, tss.match("foo", "bar"))
}