Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

test: set test flags from within an init to limit maximum test parallelism#19575

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
Emyrk merged 6 commits intomainfromstevenmasley/limit_parallel
Sep 17, 2025
Merged
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 55 additions & 0 deletionscoderd/coderdtest/initflags.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
package coderdtest
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Only applies to this pkg? What about others likeclitest?

Copy link
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

We importcoderdtest in nearly every test. Any test that spins up a coderd will inherit thisinit function.

If there are some pkgs that do not import this, they probably do not need the parallism limit

dannykopping reacted with thumbs up emoji

import (
"flag"
"fmt"
"runtime"
"strconv"
"testing"
)

const (
// MaxTestParallelism is set to match our MakeFile's `make test` target.
MaxTestParallelism = 8
)

// init defines the default parallelism for tests, capping it to MaxTestParallelism.
// Any user-provided value for -test.parallel will override this.
func init() {
// Setup the test flags.
testing.Init()

// info is used for debugging panics in this init function.
info := "Resolve the issue in the file initflags.go"
_, file, line, ok := runtime.Caller(0)
if ok {
info = fmt.Sprintf("Resolve the issue in the file %s:%d", file, line)
}

// Lookup the test.parallel flag's value, and cap it to MaxTestParallelism. This
// all happens before `flag.Parse()`, so any user-provided value will overwrite
// whatever we set here.
par := flag.CommandLine.Lookup("test.parallel")
if par == nil {
// This should never happen. If you are reading this message because of a panic,
// just comment out the panic and add a `return` statement instead.
msg := "no 'test.parallel' flag found, unable to set default parallelism"
panic(msg + "\n" + info)
}

parValue, err := strconv.ParseInt(par.Value.String(), 0, 64)
if err != nil {
// This should never happen, but if it does, panic with a useful message. If you
// are reading this message because of a panic, that means the default value for
// -test.parallel is not an integer. A safe fix is to comment out the panic. This
// will assume the default value of '0', and replace it with MaxTestParallelism.
// Which is not ideal, but at least tests will run.
msg := fmt.Sprintf("failed to parse test.parallel: %v", err)

panic(msg + "\n" + info)
}

if parValue > MaxTestParallelism {
_ = par.Value.Set(fmt.Sprintf("%d", MaxTestParallelism))
}
}
Loading

[8]ページ先頭

©2009-2025 Movatter.jp