aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <[email protected]>2023-08-04 18:46:47 +0200
committerBjørn Erik Pedersen <[email protected]>2023-08-04 21:12:04 +0200
commit22861cb4dc4157db046d74145b5c5a3d3f2985d5 (patch)
treee43b6b2470265f368a2794e9364cd5aa36a6470a
parent16da1ade7040a401fb704e9fae858a51ff517468 (diff)
downloadhugo-22861cb4dc4157db046d74145b5c5a3d3f2985d5.tar.gz
hugo-22861cb4dc4157db046d74145b5c5a3d3f2985d5.zip
Return original error on resources.GetRemote retry timeouts
See #11327
-rw-r--r--resources/resource_factories/create/integration_test.go53
-rw-r--r--resources/resource_factories/create/remote.go3
2 files changed, 39 insertions, 17 deletions
diff --git a/resources/resource_factories/create/integration_test.go b/resources/resource_factories/create/integration_test.go
index acd2cf3a1..0a522727a 100644
--- a/resources/resource_factories/create/integration_test.go
+++ b/resources/resource_factories/create/integration_test.go
@@ -21,6 +21,7 @@ import (
"strings"
"testing"
+ qt "github.com/frankban/quicktest"
"github.com/gohugoio/hugo/hugolib"
)
@@ -67,10 +68,10 @@ func TestGetRemoteRetry(t *testing.T) {
t.Parallel()
temporaryHTTPCodes := []int{408, 429, 500, 502, 503, 504}
- numPages := 30
+ numPages := 20
handler := func(w http.ResponseWriter, r *http.Request) {
- if rand.Intn(4) == 0 {
+ if rand.Intn(3) == 0 {
w.WriteHeader(temporaryHTTPCodes[rand.Intn(len(temporaryHTTPCodes))])
return
}
@@ -81,9 +82,10 @@ func TestGetRemoteRetry(t *testing.T) {
srv := httptest.NewServer(http.HandlerFunc(handler))
t.Cleanup(func() { srv.Close() })
- files := `
+ filesTemplate := `
-- hugo.toml --
disableKinds = ["home", "taxonomy", "term"]
+timeout = "TIMEOUT"
[security]
[security.http]
urls = ['.*']
@@ -93,7 +95,7 @@ mediaTypes = ['text/plain']
{{ $opts := dict }}
{{ with resources.GetRemote $url $opts }}
{{ with .Err }}
- {{ errorf "Unable to get remote resource: %s" . }}
+ {{ errorf "Got Err: %s. Data: %v" . .Data }}
{{ else }}
Content: {{ .Content }}
{{ end }}
@@ -103,22 +105,41 @@ mediaTypes = ['text/plain']
`
for i := 0; i < numPages; i++ {
- files += fmt.Sprintf("-- content/post/p%d.md --\n", i)
+ filesTemplate += fmt.Sprintf("-- content/post/p%d.md --\n", i)
}
- files = strings.ReplaceAll(files, "URL", srv.URL)
+ filesTemplate = strings.ReplaceAll(filesTemplate, "URL", srv.URL)
- b := hugolib.NewIntegrationTestBuilder(
- hugolib.IntegrationTestConfig{
- T: t,
- TxtarString: files,
- },
- )
+ t.Run("OK", func(t *testing.T) {
+ files := strings.ReplaceAll(filesTemplate, "TIMEOUT", "60s")
+ b := hugolib.NewIntegrationTestBuilder(
+ hugolib.IntegrationTestConfig{
+ T: t,
+ TxtarString: files,
+ },
+ )
- b.Build()
+ b.Build()
- for i := 0; i < numPages; i++ {
- b.AssertFileContent(fmt.Sprintf("public/post/p%d/index.html", i), fmt.Sprintf("Content: Response for /post/p%d/.", i))
- }
+ for i := 0; i < numPages; i++ {
+ b.AssertFileContent(fmt.Sprintf("public/post/p%d/index.html", i), fmt.Sprintf("Content: Response for /post/p%d/.", i))
+ }
+ })
+
+ t.Run("Timeout", func(t *testing.T) {
+ files := strings.ReplaceAll(filesTemplate, "TIMEOUT", "100ms")
+ b, err := hugolib.NewIntegrationTestBuilder(
+ hugolib.IntegrationTestConfig{
+ T: t,
+ TxtarString: files,
+ },
+ ).BuildE()
+
+ b.Assert(err, qt.IsNotNil)
+ b.AssertLogContains("Got Err")
+ b.AssertLogContains("Retry timeout")
+ b.AssertLogContains("ContentLength:0")
+
+ })
}
diff --git a/resources/resource_factories/create/remote.go b/resources/resource_factories/create/remote.go
index ce9c80881..488e8e70a 100644
--- a/resources/resource_factories/create/remote.go
+++ b/resources/resource_factories/create/remote.go
@@ -159,7 +159,8 @@ func (c *Client) FromRemote(uri string, optionsm map[string]any) (resource.Resou
if start.IsZero() {
start = time.Now()
} else if d := time.Since(start) + nextSleep; d >= c.rs.Cfg.Timeout() {
- return nil, fmt.Errorf("timeout (configured to %s) fetching remote resource %s: last error: %w", c.rs.Cfg.Timeout(), uri, err)
+ c.rs.Logger.Errorf("Retry timeout (configured to %s) fetching remote resource.", c.rs.Cfg.Timeout())
+ return nil, err
}
time.Sleep(nextSleep)
if nextSleep < nextSleepLimit {