Pid ID refactor

This commit is contained in:
Laszlo Fogas 2019-07-19 09:17:47 +02:00
parent e2b76ac449
commit 2edc5fcfb7
2 changed files with 44 additions and 5 deletions

View file

@ -59,7 +59,9 @@ func (b *procBuilder) Build() ([]*buildItem, error) {
sort.Sort(remote.ByName(b.Yamls))
for j, y := range b.Yamls {
pidSequence := 1
for _, y := range b.Yamls {
// matrix axes
axes, err := matrix.ParseString(string(y.Data))
if err != nil {
@ -69,11 +71,11 @@ func (b *procBuilder) Build() ([]*buildItem, error) {
axes = append(axes, matrix.Axis{})
}
for i, axis := range axes {
for _, axis := range axes {
proc := &model.Proc{
BuildID: b.Curr.ID,
PID: j + i + 1,
PGID: j + i + 1,
PID: pidSequence,
PGID: pidSequence,
State: model.StatusPending,
Environ: axis,
Name: sanitizePath(y.Name),
@ -123,6 +125,7 @@ func (b *procBuilder) Build() ([]*buildItem, error) {
item.Labels = map[string]string{}
}
items = append(items, item)
pidSequence++
}
}

View file

@ -201,6 +201,42 @@ pipeline:
}
}
if buildItems[1].Proc.State != model.StatusPending {
t.Fatal("Should not run on dev branch")
t.Fatal("Should run on dev branch")
}
}
func TestTree(t *testing.T) {
build := &model.Build{}
b := procBuilder{
Repo: &model.Repo{},
Curr: build,
Last: &model.Build{},
Netrc: &model.Netrc{},
Secs: []*model.Secret{},
Regs: []*model.Registry{},
Link: "",
Yamls: []*remote.FileMeta{
&remote.FileMeta{Data: []byte(`
pipeline:
build:
image: scratch
yyy: ${DRONE_COMMIT_MESSAGE}
`)},
},
}
_, err := b.Build()
if err != nil {
t.Fatal(err)
}
if len(build.Procs) != 3 {
t.Fatal("Should generate three in total")
}
if build.Procs[1].PPID != 1 {
t.Fatal("Clone step should be a children of the stage")
}
if build.Procs[2].PPID != 1 {
t.Fatal("Build step should be a children of the stage")
}
}