mirror of
https://github.com/pomerium/pomerium.git
synced 2025-07-09 12:58:22 +02:00
authorize: cache warming (#5439)
* authorize: cache warming * add Authorize to test? * remove tracing querier * only update connection when it changes
This commit is contained in:
parent
b674d5c19d
commit
6e1fabec0b
9 changed files with 254 additions and 186 deletions
|
@ -9,34 +9,6 @@ import (
|
|||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestLocalCache(t *testing.T) {
|
||||
ctx, clearTimeout := context.WithTimeout(context.Background(), time.Second*10)
|
||||
defer clearTimeout()
|
||||
|
||||
callCount := 0
|
||||
update := func(_ context.Context) ([]byte, error) {
|
||||
callCount++
|
||||
return []byte("v1"), nil
|
||||
}
|
||||
c := NewLocalCache()
|
||||
v, err := c.GetOrUpdate(ctx, []byte("k1"), update)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, []byte("v1"), v)
|
||||
assert.Equal(t, 1, callCount)
|
||||
|
||||
v, err = c.GetOrUpdate(ctx, []byte("k1"), update)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, []byte("v1"), v)
|
||||
assert.Equal(t, 1, callCount)
|
||||
|
||||
c.Invalidate([]byte("k1"))
|
||||
|
||||
v, err = c.GetOrUpdate(ctx, []byte("k1"), update)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, []byte("v1"), v)
|
||||
assert.Equal(t, 2, callCount)
|
||||
}
|
||||
|
||||
func TestGlobalCache(t *testing.T) {
|
||||
ctx, clearTimeout := context.WithTimeout(context.Background(), time.Second*10)
|
||||
defer clearTimeout()
|
||||
|
@ -70,4 +42,10 @@ func TestGlobalCache(t *testing.T) {
|
|||
})
|
||||
return err != nil
|
||||
}, time.Second, time.Millisecond*10, "should honor TTL")
|
||||
|
||||
c.Set(time.Now().Add(time.Hour), []byte("k2"), []byte("v2"))
|
||||
v, err = c.GetOrUpdate(ctx, []byte("k2"), update)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, []byte("v2"), v)
|
||||
assert.Equal(t, 2, callCount)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue