Restore the cache update code from version 2.1.4 for now

This commit is contained in:
Frank Denis 2023-08-11 00:51:34 +02:00
parent 2675d73b13
commit 7033f242c0
3 changed files with 67 additions and 64 deletions

View file

@ -42,8 +42,6 @@ const (
TestStatePathErr // unparseable path to files (download only)
)
const DefaultPrefetchDelay time.Duration = 24 * time.Hour
type SourceTestData struct {
n int // subtest counter
xTransport *XTransport
@ -352,7 +350,7 @@ func prepSourceTestDownload(
}
if e.success {
e.err = ""
e.delay = e.Source.cacheTTL
e.delay = DefaultPrefetchDelay
} else {
e.delay = MinimumPrefetchInterval
}
@ -373,7 +371,7 @@ func setupSourceTestCase(t *testing.T, d *SourceTestData, i int,
}
e.Source = &Source{
name: id, urls: []*url.URL{}, format: SourceFormatV2, minisignKey: d.key,
cacheFile: e.cachePath, cacheTTL: DefaultPrefetchDelay * 3,
cacheFile: e.cachePath, cacheTTL: DefaultPrefetchDelay * 3, prefetchDelay: DefaultPrefetchDelay,
}
if cacheTest != nil {
prepSourceTestCache(t, d, e, d.sources[i], *cacheTest)
@ -407,9 +405,9 @@ func TestNewSource(t *testing.T) {
refreshDelay time.Duration
e *SourceTestExpect
}{
{"", "", 0, &SourceTestExpect{err: " ", Source: &Source{name: "short refresh delay", urls: []*url.URL{}, cacheTTL: DefaultPrefetchDelay, prefix: ""}}},
{"v1", d.keyStr, DefaultPrefetchDelay * 2, &SourceTestExpect{err: "Unsupported source format", Source: &Source{name: "old format", urls: []*url.URL{}, cacheTTL: DefaultPrefetchDelay * 2}}},
{"v2", "", DefaultPrefetchDelay * 3, &SourceTestExpect{err: "Invalid encoded public key", Source: &Source{name: "invalid public key", urls: []*url.URL{}, cacheTTL: DefaultPrefetchDelay * 3}}},
{"", "", 0, &SourceTestExpect{err: " ", Source: &Source{name: "short refresh delay", urls: []*url.URL{}, cacheTTL: DefaultPrefetchDelay, prefetchDelay: DefaultPrefetchDelay, prefix: ""}}},
{"v1", d.keyStr, DefaultPrefetchDelay * 2, &SourceTestExpect{err: "Unsupported source format", Source: &Source{name: "old format", urls: []*url.URL{}, cacheTTL: DefaultPrefetchDelay * 2, prefetchDelay: DefaultPrefetchDelay}}},
{"v2", "", DefaultPrefetchDelay * 3, &SourceTestExpect{err: "Invalid encoded public key", Source: &Source{name: "invalid public key", urls: []*url.URL{}, cacheTTL: DefaultPrefetchDelay * 3, prefetchDelay: DefaultPrefetchDelay}}},
} {
t.Run(tt.e.Source.name, func(t *testing.T) {
got, err := NewSource(
@ -480,7 +478,6 @@ func TestPrefetchSources(t *testing.T) {
s := &Source{}
*s = *e.Source
s.bin = nil
s.refresh = d.timeNow
sources = append(sources, s)
expects = append(expects, e)
}