diff --git a/command/build_parallel_test.go b/command/build_parallel_test.go index 88c5dc9e5..3b4f42dac 100644 --- a/command/build_parallel_test.go +++ b/command/build_parallel_test.go @@ -75,8 +75,8 @@ func testMetaParallel(t *testing.T, builder *ParallelTestBuilder, locked *Locked } func TestBuildParallel_1(t *testing.T) { - // testfile that running 6 builds, with first one locks 'forever', other - // builds should go through. + // testfile has 6 builds, with first one locks 'forever', other builds + // should go through. b := NewParallelTestBuilder(5) locked := &LockedBuilder{unlock: make(chan interface{})} @@ -86,7 +86,7 @@ func TestBuildParallel_1(t *testing.T) { args := []string{ fmt.Sprintf("-parallel=true"), - filepath.Join(testFixture("parallel"), "template.json"), + filepath.Join(testFixture("parallel"), "1lock.json"), } wg := errgroup.Group{} @@ -102,3 +102,32 @@ func TestBuildParallel_1(t *testing.T) { close(locked.unlock) // unlock locking one wg.Wait() // wait for termination } + +func TestBuildParallel_2(t *testing.T) { + // testfile has 6 builds, 2 of them lock 'forever', other builds + // should go through. + b := NewParallelTestBuilder(4) + locked := &LockedBuilder{unlock: make(chan interface{})} + + c := &BuildCommand{ + Meta: testMetaParallel(t, b, locked), + } + + args := []string{ + fmt.Sprintf("-parallel-builds=3"), + filepath.Join(testFixture("parallel"), "2lock.json"), + } + + wg := errgroup.Group{} + + wg.Go(func() error { + if code := c.Run(args); code != 0 { + fatalCommand(t, c.Meta) + } + return nil + }) + + b.wg.Wait() // ran 4 times + close(locked.unlock) // unlock locking one + wg.Wait() // wait for termination +} diff --git a/command/test-fixtures/parallel/template.json b/command/test-fixtures/parallel/1lock.json similarity index 100% rename from command/test-fixtures/parallel/template.json rename to command/test-fixtures/parallel/1lock.json diff --git a/command/test-fixtures/parallel/2lock.json b/command/test-fixtures/parallel/2lock.json new file mode 100644 index 000000000..59da8a36d --- /dev/null +++ b/command/test-fixtures/parallel/2lock.json @@ -0,0 +1,10 @@ +{ + "builders": [ + {"type": "lock", "name": "build0"}, + {"type": "parallel-test", "name": "build1"}, + {"type": "parallel-test", "name": "build2"}, + {"type": "lock", "name": "build3"}, + {"type": "parallel-test", "name": "build4"}, + {"type": "parallel-test", "name": "build5"} + ] +} \ No newline at end of file