Skip to content

Commit 2f2bd00

Browse files
dmitshurgopherbot
authored andcommitted
internal/workflow: fix sub-workflow prefix for tasks added via expansion
Tasks added by expansions, in contrast to all other tasks, didn't handle the sub-workflow prefix. A while back I looked into it briefly, and saw that shallowClone didn't clone that one field, so figured CL 546235 would fix it. It didn't, and now it's apparent to me why not. The expansion always gets a copy of the top-level workflow definition, even if it was made by a task with some prefix. Modify addExpansion to record not just that a given task is an expansion, but also the workflow prefix at that time. We also have a test that makes it easy to verify this works now. Keep shallowClone as is, to match the behavior implied by its name, even though by now the namePrefix it clones gets overwritten anyway. For golang/go#70249. Change-Id: Ib1cb34ef121baf946fe6f2500c4bf1611aaa6db7 Reviewed-on: https://go-review.googlesource.com/c/build/+/626336 Reviewed-by: Dmitri Shuralyov <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]> Reviewed-by: Carlos Amedee <[email protected]> Auto-Submit: Dmitri Shuralyov <[email protected]>
1 parent e823c99 commit 2f2bd00

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

internal/workflow/workflow.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -422,6 +422,9 @@ func addAction(d *Definition, name string, f interface{}, inputs []metaValue, op
422422
func addExpansion[O1 any](d *Definition, name string, f interface{}, inputs []metaValue, opts []TaskOption) *expansionResult[O1] {
423423
td := addFunc(d, name, f, inputs, opts)
424424
td.isExpansion = true
425+
// Also record the workflow name prefix at the time the expansion is added.
426+
// It'll be accessed later, when starting to run this expansion.
427+
td.namePrefix = d.namePrefix
425428
return &expansionResult[O1]{td}
426429
}
427430

@@ -600,6 +603,7 @@ type Logger interface {
600603
type taskDefinition struct {
601604
name string
602605
isExpansion bool
606+
namePrefix string // Workflow name prefix; applies only when isExpansion is true.
603607
args []metaValue
604608
deps []Dependency
605609
f interface{}
@@ -845,6 +849,7 @@ func (w *Workflow) Run(ctx context.Context, listener Listener) (map[string]inter
845849
if task.def.isExpansion {
846850
runningExpansion = true
847851
defCopy := w.def.shallowClone()
852+
defCopy.namePrefix = task.def.namePrefix
848853
go func() { stateChan <- runExpansion(defCopy, taskCopy, args) }()
849854
} else {
850855
go func() { stateChan <- runTask(ctx, w.ID, listener, taskCopy, args) }()

internal/workflow/workflow_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -361,24 +361,24 @@ func TestManualRetryMultipleExpansions(t *testing.T) {
361361

362362
w := startWorkflow(t, wd, nil)
363363
listener := &errorListener{
364-
taskName: "work 1",
364+
taskName: "sub1: work 1",
365365
callback: func(string) {
366366
go func() {
367367
retried[0]++
368-
err := w.RetryTask(context.Background(), "work 1")
368+
err := w.RetryTask(context.Background(), "sub1: work 1")
369369
if err != nil {
370-
t.Errorf(`RetryTask("work 1") failed: %v`, err)
370+
t.Errorf(`RetryTask("sub1: work 1") failed: %v`, err)
371371
}
372372
}()
373373
},
374374
Listener: &errorListener{
375-
taskName: "work 2",
375+
taskName: "sub2: work 2",
376376
callback: func(string) {
377377
go func() {
378378
retried[1]++
379-
err := w.RetryTask(context.Background(), "work 2")
379+
err := w.RetryTask(context.Background(), "sub2: work 2")
380380
if err != nil {
381-
t.Errorf(`RetryTask("work 2") failed: %v`, err)
381+
t.Errorf(`RetryTask("sub2: work 2") failed: %v`, err)
382382
}
383383
}()
384384
},

0 commit comments

Comments
 (0)