internal/pkg: in-flight error resolution
Test / Create distribution (push) Successful in 55s
Test / Sandbox (push) Successful in 2m58s
Test / Hakurei (push) Successful in 4m28s
Test / Sandbox (race detector) (push) Successful in 5m55s
Test / Hakurei (race detector) (push) Successful in 7m35s
Test / ShareFS (push) Successful in 8m31s
Test / Flake checks (push) Successful in 1m32s
Test / Create distribution (push) Successful in 55s
Test / Sandbox (push) Successful in 2m58s
Test / Hakurei (push) Successful in 4m28s
Test / Sandbox (race detector) (push) Successful in 5m55s
Test / Hakurei (race detector) (push) Successful in 7m35s
Test / ShareFS (push) Successful in 8m31s
Test / Flake checks (push) Successful in 1m32s
The DCE is a slow and overcomplicated solution to a simple problem. This change replaces the DCE by resolving errors in-flight. Signed-off-by: Ophestra <cat@gensokyo.uk>
This commit is contained in:
+44
-64
@@ -11,6 +11,7 @@ import (
|
||||
"io"
|
||||
"io/fs"
|
||||
"log"
|
||||
"maps"
|
||||
"net/http"
|
||||
"os"
|
||||
"path/filepath"
|
||||
@@ -861,14 +862,11 @@ func TestCache(t *testing.T) {
|
||||
cure: func(f *pkg.FContext) error {
|
||||
panic("attempting to cure impossible artifact")
|
||||
},
|
||||
}, nil, nil, pkg.WNew, &pkg.DependencyCureError{
|
||||
{
|
||||
A: failingFile,
|
||||
Err: struct {
|
||||
_ []byte
|
||||
stub.UniqueError
|
||||
}{UniqueError: 0xbad},
|
||||
},
|
||||
}, nil, nil, pkg.WNew, pkg.InputError{
|
||||
failingFile: struct {
|
||||
_ []byte
|
||||
stub.UniqueError
|
||||
}{UniqueError: 0xbad},
|
||||
}},
|
||||
})
|
||||
|
||||
@@ -1949,7 +1947,7 @@ errors during scrub:
|
||||
}
|
||||
}
|
||||
|
||||
func TestDependencyCureError(t *testing.T) {
|
||||
func TestInputError(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
makeIdent := func(ident ...byte) pkg.Artifact {
|
||||
@@ -1962,56 +1960,24 @@ func TestDependencyCureError(t *testing.T) {
|
||||
|
||||
testCases := []struct {
|
||||
name string
|
||||
err pkg.DependencyCureError
|
||||
err pkg.InputError
|
||||
want string
|
||||
unwrap []error
|
||||
}{
|
||||
{"simple", pkg.DependencyCureError{
|
||||
{A: makeIdent(0xff, 9), Err: stub.UniqueError(0xbad09)},
|
||||
{A: makeIdent(0xff, 0), Err: stub.UniqueError(0xbad00)},
|
||||
{A: makeIdent(0xff, 0xf), Err: stub.UniqueError(0xbad0f)},
|
||||
{A: makeIdent(0xff, 1), Err: stub.UniqueError(0xbad01)},
|
||||
}, `errors curing dependencies:
|
||||
{"simple", pkg.InputError{
|
||||
makeIdent(0xff, 9): stub.UniqueError(0xbad09),
|
||||
makeIdent(0xff, 0): stub.UniqueError(0xbad00),
|
||||
makeIdent(0xff, 0xf): stub.UniqueError(0xbad0f),
|
||||
makeIdent(0xff, 1): stub.UniqueError(0xbad01),
|
||||
}, `errors curing inputs:
|
||||
_wAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA: unique error 765184 injected by the test suite
|
||||
_wEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA: unique error 765185 injected by the test suite
|
||||
_wkAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA: unique error 765193 injected by the test suite
|
||||
_w8AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA: unique error 765199 injected by the test suite`, []error{
|
||||
&pkg.CureError{A: makeIdent(0xff, 0), Err: stub.UniqueError(0xbad00)},
|
||||
&pkg.CureError{A: makeIdent(0xff, 1), Err: stub.UniqueError(0xbad01)},
|
||||
&pkg.CureError{A: makeIdent(0xff, 9), Err: stub.UniqueError(0xbad09)},
|
||||
&pkg.CureError{A: makeIdent(0xff, 0xf), Err: stub.UniqueError(0xbad0f)},
|
||||
}},
|
||||
|
||||
{"dedup", pkg.DependencyCureError{
|
||||
{A: makeIdent(0xff, 9), Err: stub.UniqueError(0xbad09)},
|
||||
{A: makeIdent(0xff, 0), Err: stub.UniqueError(0xbad00)},
|
||||
{A: makeIdent(0xff, 0xfd), Err: &pkg.DependencyCureError{
|
||||
{A: makeIdent(0xff, 9), Err: stub.UniqueError(0xbad09)},
|
||||
{A: makeIdent(0xff, 0xc), Err: &pkg.DependencyCureError{
|
||||
{A: makeIdent(0xff, 0xf), Err: stub.UniqueError(0xbad0f)},
|
||||
{A: makeIdent(0xff, 0), Err: stub.UniqueError(0xbad00)},
|
||||
}},
|
||||
{A: makeIdent(0xff, 0), Err: stub.UniqueError(0xbad00)},
|
||||
{A: makeIdent(0xff, 0), Err: stub.UniqueError(0xbad00)},
|
||||
}},
|
||||
{A: makeIdent(0xff, 0xff), Err: &pkg.DependencyCureError{
|
||||
{A: makeIdent(0xff, 9), Err: stub.UniqueError(0xbad09)},
|
||||
{A: makeIdent(0xff, 0xc), Err: &pkg.DependencyCureError{
|
||||
{A: makeIdent(0xff, 0), Err: stub.UniqueError(0xbad00)},
|
||||
}},
|
||||
{A: makeIdent(0xff, 0), Err: stub.UniqueError(0xbad00)},
|
||||
}},
|
||||
{A: makeIdent(0xff, 0xf), Err: stub.UniqueError(0xbad0f)},
|
||||
{A: makeIdent(0xff, 1), Err: stub.UniqueError(0xbad01)},
|
||||
}, `errors curing dependencies:
|
||||
_wAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA: unique error 765184 injected by the test suite
|
||||
_wEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA: unique error 765185 injected by the test suite
|
||||
_wkAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA: unique error 765193 injected by the test suite
|
||||
_w8AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA: unique error 765199 injected by the test suite`, []error{
|
||||
&pkg.CureError{A: makeIdent(0xff, 0), Err: stub.UniqueError(0xbad00)},
|
||||
&pkg.CureError{A: makeIdent(0xff, 1), Err: stub.UniqueError(0xbad01)},
|
||||
&pkg.CureError{A: makeIdent(0xff, 9), Err: stub.UniqueError(0xbad09)},
|
||||
&pkg.CureError{A: makeIdent(0xff, 0xf), Err: stub.UniqueError(0xbad0f)},
|
||||
stub.UniqueError(0xbad00),
|
||||
stub.UniqueError(0xbad01),
|
||||
stub.UniqueError(0xbad09),
|
||||
stub.UniqueError(0xbad0f),
|
||||
}},
|
||||
}
|
||||
for _, tc := range testCases {
|
||||
@@ -2022,7 +1988,19 @@ func TestDependencyCureError(t *testing.T) {
|
||||
t.Errorf("Error:\n%s\nwant\n%s", got, tc.want)
|
||||
}
|
||||
|
||||
if unwrap := tc.err.Unwrap(); !reflect.DeepEqual(unwrap, tc.unwrap) {
|
||||
unwrap, unwrapM := tc.err.Unwrap(), make(map[error]struct{})
|
||||
for _, a := range unwrap {
|
||||
unwrapM[a] = struct{}{}
|
||||
}
|
||||
|
||||
wantUnwrapM := make(map[error]struct{})
|
||||
for _, a := range tc.unwrap {
|
||||
wantUnwrapM[a] = struct{}{}
|
||||
}
|
||||
|
||||
if len(unwrap) != len(unwrapM) ||
|
||||
len(tc.unwrap) != len(wantUnwrapM) ||
|
||||
!maps.Equal(unwrapM, wantUnwrapM) {
|
||||
t.Errorf("Unwrap: %#v, want %#v", unwrap, tc.unwrap)
|
||||
}
|
||||
})
|
||||
@@ -2055,19 +2033,21 @@ func (a earlyFailureF) Cure(*pkg.FContext) error {
|
||||
func BenchmarkEarlyDCE(b *testing.B) {
|
||||
msg := message.New(log.New(os.Stderr, "dce: ", 0))
|
||||
msg.SwapVerbose(testing.Verbose())
|
||||
c, err := pkg.Open(b.Context(), msg, check.MustAbs(b.TempDir()), nil)
|
||||
if err != nil {
|
||||
b.Fatal(err)
|
||||
}
|
||||
_, _, err = c.Cure(earlyFailureF(8))
|
||||
if !errors.Is(err, stub.UniqueError(0xcafe)) {
|
||||
b.Fatalf("Cure: error = %v", err)
|
||||
}
|
||||
c.Close()
|
||||
dce := err.(*pkg.DependencyCureError)
|
||||
|
||||
for b.Loop() {
|
||||
dce.Unwrap()
|
||||
b.StopTimer()
|
||||
c, err := pkg.Open(b.Context(), msg, check.MustAbs(b.TempDir()), nil)
|
||||
if err != nil {
|
||||
b.Fatal(err)
|
||||
}
|
||||
b.StartTimer()
|
||||
_, _, err = c.Cure(earlyFailureF(8))
|
||||
b.StopTimer()
|
||||
if !errors.Is(err, stub.UniqueError(0xcafe)) {
|
||||
b.Fatalf("Cure: error = %v", err)
|
||||
}
|
||||
c.Close()
|
||||
b.StartTimer()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user