-
Notifications
You must be signed in to change notification settings - Fork 18
/
url_lock_test.go
43 lines (35 loc) · 924 Bytes
/
url_lock_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
package httpcache
import (
"context"
"net/http/httptest"
"testing"
"github.com/caddyserver/caddy/v2"
"github.com/caddyserver/caddy/v2/modules/caddyhttp"
"github.com/stretchr/testify/suite"
)
func BenchmarkURLLock(b *testing.B) {
c := getDefaultConfig()
lock := NewURLLock(c)
r := httptest.NewRequest("GET", "http://localhost:8000/test.txt", nil)
repl := caddyhttp.NewTestReplacer(r)
ctx := context.WithValue(r.Context(), caddy.ReplacerCtxKey, repl)
r.WithContext(ctx)
b.ResetTimer()
for n := 0; n < b.N; n++ {
key := getKey(c.CacheKeyTemplate, r) // this function has some impact
loc := lock.Acquire(key)
loc.Unlock()
}
}
type URLLockTestSuite struct {
suite.Suite
}
func (suite *URLLockTestSuite) TestAcquireAndUnLock() {
c := getDefaultConfig()
lock := NewURLLock(c)
l := lock.Acquire("hello")
l.Unlock()
}
func TestURLLockTestSuite(t *testing.T) {
suite.Run(t, new(URLLockTestSuite))
}