Preserve cancellation after profile lookups
This commit is contained in:
@@ -33,7 +33,7 @@ func (r *resolvingRepository) GetProfile(ctx context.Context, id string) (*domai
|
||||
return nil, err
|
||||
}
|
||||
|
||||
profile, err := r.source.GetProfile(ctx, requestedID)
|
||||
profile, err := r.getRawProfile(ctx, requestedID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -61,7 +61,7 @@ func (r *resolvingRepository) GetProfile(ctx context.Context, id string) (*domai
|
||||
return nil, fmt.Errorf("%w: profile inheritance chain exceeds %d profiles: %s", ErrInvalidProfile, maximumProfileChainLength, joinProfileChain(chainIDs, baseID))
|
||||
}
|
||||
|
||||
base, err := r.source.GetProfile(ctx, baseID)
|
||||
base, err := r.getRawProfile(ctx, baseID)
|
||||
if err != nil {
|
||||
if errors.Is(err, ErrProfileNotFound) {
|
||||
return nil, fmt.Errorf("%w: base profile %q is missing in chain %s", ErrInvalidProfile, baseID, joinProfileChain(chainIDs, baseID))
|
||||
@@ -88,6 +88,17 @@ func (r *resolvingRepository) GetProfile(ctx context.Context, id string) (*domai
|
||||
return resolved, nil
|
||||
}
|
||||
|
||||
func (r *resolvingRepository) getRawProfile(ctx context.Context, id string) (*domain.ExecutionProfile, error) {
|
||||
profile, err := r.source.GetProfile(ctx, id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := ctx.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return profile, nil
|
||||
}
|
||||
|
||||
func joinProfileChain(chain []string, next string) string {
|
||||
return strings.Join(append(append([]string(nil), chain...), next), " -> ")
|
||||
}
|
||||
|
||||
@@ -321,6 +321,19 @@ func TestResolvingRepositoryIsFreshAndCancellationAware(t *testing.T) {
|
||||
t.Fatalf("base calls after cancellation = %d, want 2", got)
|
||||
}
|
||||
|
||||
terminalLookup, cancelTerminalLookup := context.WithCancel(context.Background())
|
||||
repo.afterGet = func(id string) {
|
||||
if id == "base" {
|
||||
cancelTerminalLookup()
|
||||
}
|
||||
}
|
||||
if _, err := resolver.GetProfile(terminalLookup, "leaf"); !errors.Is(err, context.Canceled) {
|
||||
t.Fatalf("terminal lookup cancellation error = %v", err)
|
||||
}
|
||||
if got := repo.callCount("base"); got != 3 {
|
||||
t.Fatalf("base calls after terminal cancellation = %d, want 3", got)
|
||||
}
|
||||
|
||||
repo.afterGet = nil
|
||||
var wg sync.WaitGroup
|
||||
errors := make(chan error, 8)
|
||||
|
||||
Reference in New Issue
Block a user