Browse Source
fix: extend ignore404Error to match 404 Not Found string from S3 sink… (#8741)
fix: extend ignore404Error to match 404 Not Found string from S3 sink… (#8741)
* fix: extend ignore404Error to match 404 Not Found string from S3 sink errors * test: add unit tests for isIgnorable404 error matching * improve: pre-compute ignorable 404 string and simplify isIgnorable404 * test: replace init() with TestMain for global HTTP client setupfix/subscribe-metadata-slow-consumer-blocked
committed by
GitHub
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 93 additions and 9 deletions
@ -0,0 +1,73 @@ |
|||||
|
package command |
||||
|
|
||||
|
import ( |
||||
|
"context" |
||||
|
"fmt" |
||||
|
"net/http" |
||||
|
"net/http/httptest" |
||||
|
"os" |
||||
|
"testing" |
||||
|
|
||||
|
util_http "github.com/seaweedfs/seaweedfs/weed/util/http" |
||||
|
) |
||||
|
|
||||
|
func TestMain(m *testing.M) { |
||||
|
util_http.InitGlobalHttpClient() |
||||
|
os.Exit(m.Run()) |
||||
|
} |
||||
|
|
||||
|
// readUrlError starts a test HTTP server returning the given status code
|
||||
|
// and returns the error produced by ReadUrlAsStream.
|
||||
|
//
|
||||
|
// The error format is defined in ReadUrlAsStream:
|
||||
|
// https://github.com/seaweedfs/seaweedfs/blob/3a765df2ff90839acb9acf910b73513417fa84d1/weed/util/http/http_global_client_util.go#L353
|
||||
|
func readUrlError(t *testing.T, statusCode int) error { |
||||
|
t.Helper() |
||||
|
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
||||
|
http.Error(w, http.StatusText(statusCode), statusCode) |
||||
|
})) |
||||
|
defer server.Close() |
||||
|
|
||||
|
_, err := util_http.ReadUrlAsStream(context.Background(), |
||||
|
server.URL+"/437,03f591a3a2b95e?readDeleted=true", "", |
||||
|
nil, false, true, 0, 1024, func(data []byte) {}) |
||||
|
if err == nil { |
||||
|
t.Fatal("expected error from ReadUrlAsStream, got nil") |
||||
|
} |
||||
|
return err |
||||
|
} |
||||
|
|
||||
|
func TestIsIgnorable404_WrappedErrNotFound(t *testing.T) { |
||||
|
readErr := readUrlError(t, http.StatusNotFound) |
||||
|
// genProcessFunction wraps sink errors with %w:
|
||||
|
// https://github.com/seaweedfs/seaweedfs/blob/3a765df2ff90839acb9acf910b73513417fa84d1/weed/command/filer_sync.go#L496
|
||||
|
genErr := fmt.Errorf("create entry1 : %w", readErr) |
||||
|
|
||||
|
if !isIgnorable404(genErr) { |
||||
|
t.Errorf("expected ignorable, got not: %v", genErr) |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
func TestIsIgnorable404_BrokenUnwrapChain(t *testing.T) { |
||||
|
readErr := readUrlError(t, http.StatusNotFound) |
||||
|
// AWS SDK v1 wraps transport errors via awserr.New which uses origErr.Error()
|
||||
|
// instead of %w, so errors.Is cannot unwrap through it:
|
||||
|
// https://github.com/aws/aws-sdk-go/blob/v1.55.8/aws/corehandlers/handlers.go#L173
|
||||
|
// https://github.com/aws/aws-sdk-go/blob/v1.55.8/aws/awserr/types.go#L15
|
||||
|
awsSdkErr := fmt.Errorf("RequestError: send request failed\n"+ |
||||
|
"caused by: Put \"https://s3.amazonaws.com/bucket/key\": %s", readErr.Error()) |
||||
|
genErr := fmt.Errorf("create entry1 : %w", awsSdkErr) |
||||
|
|
||||
|
if !isIgnorable404(genErr) { |
||||
|
t.Errorf("expected ignorable, got not: %v", genErr) |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
func TestIsIgnorable404_NonIgnorableError(t *testing.T) { |
||||
|
readErr := readUrlError(t, http.StatusForbidden) |
||||
|
genErr := fmt.Errorf("create entry1 : %w", readErr) |
||||
|
|
||||
|
if isIgnorable404(genErr) { |
||||
|
t.Errorf("expected not ignorable, got ignorable: %v", genErr) |
||||
|
} |
||||
|
} |
||||
Write
Preview
Loading…
Cancel
Save
Reference in new issue