Skip to content

Commit

Permalink
Merge #11052
Browse files Browse the repository at this point in the history
11052: fix(ci): Split programgen tests over multiple jobs r=AaronFriel a=AaronFriel

Attempt to fix ongoing CI issue #11022 where the `pkg/codegen/go` tests seem to hang runners. Applies a similar strategy as was used for `pkg/codegen/nodejs` tests to split them out over multiple jobs, generalized to handle additional languages.

Previously, we would split the `pkg` module by package into 3 jobs using `gotestsum`, **except** for the package `pkg/codegen/nodejs` which would be split _by test_ into 4 jobs, for 7 total jobs.

With this change, instead of special casing `pkg/codegen/nodejs`, each language's programgen tests are split into 6 packages, and relies on `gotestsum` to divide packages among a combined 7 jobs.

The numbers 6 and 7 were chosen arbitrarily. 6 batches per language as this divides the tests fairly evenly, and 7 jobs total as that preserves the total number of jobs.

The `test_pkg_$LANG` makefile targets weren't very descriptive and their meaning would change with this PR, there are new targets `test_codegen_$LANG` which replace their use.

Co-authored-by: Aaron Friel <mayreply@aaronfriel.com>
  • Loading branch information
bors[bot] and AaronFriel committed Oct 18, 2022
2 parents 547a559 + d6226d5 commit 862ef18
Show file tree
Hide file tree
Showing 38 changed files with 912 additions and 117 deletions.
11 changes: 8 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,12 @@ jobs:
find test-results -type f -empty -print -delete || true
echo "::endgroup::"
echo "::group::Remove old test timing data"
# Timing data prior to this date is unreliable. Codegen tests modified in #11052 and
# merged Monday Oct 17 at 6PM Pacific.
find test-results -type f ! -newermt "2022-10-17T18:00-07:00" -print -delete || true
echo "::endgroup::"
echo "::group::Test matrix variables"
readarray -td' ' VERSION_SETS_TO_TEST < <(echo -n "$TEST_VERSION_SETS"); declare -p VERSION_SETS_TO_TEST;
readarray -td' ' INTEGRATION_PLATFORMS < <(echo -n "$INPUT_INTEGRATION_TEST_PLATFORMS"); declare -p INTEGRATION_PLATFORMS;
Expand All @@ -121,10 +127,9 @@ jobs:
--kind unit-test \
--platform ubuntu-latest \
--version-set current \
--partition-module pkg 3 \
--partition-module pkg 7 \
--partition-module sdk 1 \
--partition-module tests 2 \
--partition-package github.com/pulumi/pulumi/pkg/v3/codegen/nodejs pkg/codegen/nodejs 4
--partition-module tests 2
)
INTEGRATION_TEST_MATRIX=$(
Expand Down
31 changes: 7 additions & 24 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,10 @@ SUB_PROJECTS := $(SDKS:%=sdk/%)
include build/common.mk

PROJECT := github.com/pulumi/pulumi/pkg/v3/cmd/pulumi
# To enable excluding longest running tests to run in separate workers
PKG_CODEGEN_NODEJS := github.com/pulumi/pulumi/pkg/v3/codegen/nodejs
PKG_CODEGEN_PYTHON := github.com/pulumi/pulumi/pkg/v3/codegen/python
PKG_CODEGEN_DOTNET := github.com/pulumi/pulumi/pkg/v3/codegen/dotnet
PKG_CODEGEN_GO := github.com/pulumi/pulumi/pkg/v3/codegen/go

PKG_CODEGEN := github.com/pulumi/pulumi/pkg/v3/codegen
# nodejs and python codegen tests are much slower than go/dotnet:
PROJECT_PKGS := $(shell cd ./pkg && go list ./... | grep -v -E '^(${PKG_CODEGEN_NODEJS}|${PKG_CODEGEN_PYTHON})$$')
PROJECT_PKGS := $(shell cd ./pkg && go list ./... | grep -v -E '^${PKG_CODEGEN}/(dotnet|go|nodejs|python)')
INTEGRATION_PKG := github.com/pulumi/pulumi/tests/integration
TESTS_PKGS := $(shell cd ./tests && go list -tags all ./... | grep -v tests/templates | grep -v ^${INTEGRATION_PKG}$)
VERSION := $(if ${PULUMI_VERSION},${PULUMI_VERSION},$(shell ./scripts/pulumi-version.sh))
Expand Down Expand Up @@ -116,28 +113,14 @@ test_fast:: build get_schemas

test_all:: test_pkg test_integration

test_pkg_nodejs: get_schemas
# this is not invoked as part of test_pkg_rest, in order to improve CI velocity by running this
# target in a separate CI job.
@cd pkg && $(GO_TEST) ${PKG_CODEGEN_NODEJS}

test_pkg_python: get_schemas
# this is not invoked as part of test_pkg_rest, in order to improve CI velocity by running this
# target in a separate CI job.
@cd pkg && $(GO_TEST) ${PKG_CODEGEN_PYTHON}

test_pkg_dotnet: get_schemas
# invoked as part of "test_pkg_rest", listed separately to update codegen just for dotnet
@cd pkg && $(GO_TEST) ${PKG_CODEGEN_DOTNET}

test_pkg_go: get_schemas
# invoked as part of "test_pkg_rest", listed separately to update codegen just for go
@cd pkg && $(GO_TEST) ${PKG_CODEGEN_GO}
lang=$(subst test_codegen_,,$(word 1,$(subst !, ,$@)))
test_codegen_%: get_schemas
@cd pkg && $(GO_TEST) ${PKG_CODEGEN}/${lang}/...

test_pkg_rest: get_schemas
@cd pkg && $(GO_TEST) ${PROJECT_PKGS}

test_pkg:: test_pkg_nodejs test_pkg_python test_pkg_rest
test_pkg:: test_pkg_rest test_codegen_dotnet test_codegen_go test_codegen_nodejs test_codegen_python

subset=$(subst test_integration_,,$(word 1,$(subst !, ,$@)))
test_integration_%:
Expand Down
17 changes: 0 additions & 17 deletions pkg/codegen/dotnet/gen_program_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,6 @@ import (
"github.com/pulumi/pulumi/pkg/v3/codegen/testing/test"
)

func TestGenerateProgram(t *testing.T) {
t.Parallel()

test.TestProgramCodegen(t,
test.ProgramCodegenOptions{
Language: "dotnet",
Extension: "cs",
OutputFile: "Program.cs",
Check: func(t *testing.T, path string, dependencies codegen.StringSet) {
Check(t, path, dependencies, "../../../../../../../sdk/dotnet/Pulumi")
},
GenProgram: GenerateProgram,
TestCases: test.PulumiPulumiProgramTests,
},
)
}

func TestGenerateProgramVersionSelection(t *testing.T) {
t.Parallel()

Expand Down
30 changes: 30 additions & 0 deletions pkg/codegen/dotnet/gen_program_test/batch1/gen_program_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 30 additions & 0 deletions pkg/codegen/dotnet/gen_program_test/batch2/gen_program_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 30 additions & 0 deletions pkg/codegen/dotnet/gen_program_test/batch3/gen_program_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 30 additions & 0 deletions pkg/codegen/dotnet/gen_program_test/batch4/gen_program_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 30 additions & 0 deletions pkg/codegen/dotnet/gen_program_test/batch5/gen_program_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 30 additions & 0 deletions pkg/codegen/dotnet/gen_program_test/batch6/gen_program_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions pkg/codegen/dotnet/test.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,3 +126,18 @@ func dotnetDependencies(deps codegen.StringSet) []dep {
}
return result
}

func GenerateProgramBatchTest(t *testing.T, testCases []test.ProgramTest) {
test.TestProgramCodegen(t,
test.ProgramCodegenOptions{
Language: "dotnet",
Extension: "cs",
OutputFile: "Program.cs",
Check: func(t *testing.T, path string, dependencies codegen.StringSet) {
Check(t, path, dependencies, "../../../../../../../sdk/dotnet/Pulumi")
},
GenProgram: GenerateProgram,
TestCases: testCases,
},
)
}
79 changes: 79 additions & 0 deletions pkg/codegen/gen_program_test/generate.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
// Copyright 2016-2022, Pulumi Corporation.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

//go:generate go run ./generate.go

package main

import (
"fmt"
"os"
"path/filepath"
)

// Split codegen tests into separate packages to extract greater parallelism, breaking up the
// slowest set(s) of tests.
func main() {
template := `// Copyright 2016-2022, Pulumi Corporation.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// Code generated by "codegen/gen_program_test/generate.go"; DO NOT EDIT.
package %s
import (
"os"
"testing"
codegen "github.com/pulumi/pulumi/pkg/v3/codegen/%s"
"github.com/pulumi/pulumi/pkg/v3/codegen/testing/test"
)
func TestGenerateProgram(t *testing.T) {
os.Chdir("../../../%[2]s") // chdir into codegen/%[2]s
codegen.GenerateProgramBatchTest(t, test.ProgramTestBatch(%d, %d))
}`

n := 6
for _, lang := range []string{"dotnet", "go", "nodejs", "python"} {
os.RemoveAll(filepath.Join("../", lang, "gen_program_test"))
for i := 1; i <= n; i++ {
packageName := fmt.Sprintf("batch%d", i)
dir := filepath.Join("../", lang, "gen_program_test", packageName)
err := os.MkdirAll(dir, 0755)
if err != nil {
panic(fmt.Sprintf("unexpected error generating codegen tests: %v", err))
}
testPath := filepath.Join(dir, "gen_program_test.go")

sourceCode := fmt.Sprintf(template, packageName, lang, i, n)
err = os.WriteFile(testPath, []byte(sourceCode), 0755) //nolint:gosec
if err != nil {
panic(fmt.Sprintf("unexpected error generating codegen tests: %v", err))
}
}
}

}

0 comments on commit 862ef18

Please sign in to comment.