HTTP plugin: warn on uncached repeated GET requests (#31932)
This commit is contained in:
parent
f56aae4aa0
commit
01b4c38231
2 changed files with 57 additions and 0 deletions
|
|
@ -9,6 +9,7 @@ import (
|
|||
|
||||
"github.com/evcc-io/evcc/util"
|
||||
"github.com/samber/lo"
|
||||
"github.com/stretchr/testify/require"
|
||||
"github.com/stretchr/testify/suite"
|
||||
)
|
||||
|
||||
|
|
@ -162,3 +163,21 @@ func (suite *httpTestSuite) TestSetPath() {
|
|||
suite.Require().NoError(s("4711"))
|
||||
suite.Require().Equal("/foo/bar/4711", suite.h.req.URL.String())
|
||||
}
|
||||
|
||||
func TestRepeatedGet(t *testing.T) {
|
||||
url := "http://repeated.test/uncached"
|
||||
t0 := time.Now()
|
||||
|
||||
require.False(t, repeatedGet(url, t0)) // first sighting
|
||||
require.True(t, repeatedGet(url, t0.Add(500*time.Millisecond))) // repeated within 1s: warn
|
||||
require.False(t, repeatedGet(url, t0.Add(600*time.Millisecond))) // already warned: silent
|
||||
|
||||
spaced := "http://repeated.test/spaced"
|
||||
require.False(t, repeatedGet(spaced, t0))
|
||||
require.False(t, repeatedGet(spaced, t0.Add(2*time.Second))) // >1s apart: no warn
|
||||
|
||||
// query params are stripped before keying, so cache-busting still counts as a repeat
|
||||
require.Equal(t, "http://q.test/path", stripQuery("http://q.test/path?ts=1&x=2#frag"))
|
||||
require.False(t, repeatedGet(stripQuery("http://q.test/path?ts=1"), t0))
|
||||
require.True(t, repeatedGet(stripQuery("http://q.test/path?ts=2"), t0.Add(300*time.Millisecond)))
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue