Skip to content

Commit 2b35517

Browse files
authored
TEST_LOG_LEVEL inconsistent (#7128)
1 parent 4030317 commit 2b35517

File tree

5 files changed

+44
-18
lines changed

5 files changed

+44
-18
lines changed

Makefile-test.mk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ endif
6565

6666
.PHONY: test
6767
test: gotestsum ## Run tests.
68-
$(GOTESTSUM) --junitfile $(ARTIFACTS)/junit.xml -- $(GOFLAGS) $(GO_TEST_FLAGS) $(shell $(GO_CMD) list $(GO_TEST_TARGET)/... | grep -v '/test/') -coverpkg=$(GO_TEST_TARGET)/... -coverprofile $(ARTIFACTS)/cover.out
68+
TEST_LOG_LEVEL=$(TEST_LOG_LEVEL) $(GOTESTSUM) --junitfile $(ARTIFACTS)/junit.xml -- $(GOFLAGS) $(GO_TEST_FLAGS) $(shell $(GO_CMD) list $(GO_TEST_TARGET)/... | grep -v '/test/') -coverpkg=$(GO_TEST_TARGET)/... -coverprofile $(ARTIFACTS)/cover.out
6969

7070
.PHONY: test-integration
7171
test-integration: gomod-download envtest ginkgo dep-crds kueuectl ginkgo-top ## Run integration tests for all singlecluster suites.

pkg/util/testing/context.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ import (
2727
ctrl "sigs.k8s.io/controller-runtime"
2828
)
2929

30+
const DefaultLogLevel = -3
31+
3032
func LogLevelWithDefault(defaultLogLevel int) int {
3133
level, err := strconv.Atoi(os.Getenv("TEST_LOG_LEVEL"))
3234
if err != nil {
@@ -36,8 +38,15 @@ func LogLevelWithDefault(defaultLogLevel int) int {
3638
}
3739

3840
func NewLogger(t *testing.T) logr.Logger {
41+
// Map TEST_LOG_LEVEL to testr verbosity so that lower (more negative)
42+
// values increase verbosity consistently with integration/e2e logging.
43+
level := LogLevelWithDefault(DefaultLogLevel)
44+
// testr expects higher Verbosity for more logs. Our convention is
45+
// more negative TEST_LOG_LEVEL means more verbose. Translate by negating
46+
// the level, so -3 => 3. Positive levels result in negative verbosity
47+
// which effectively disables extra V logs.
3948
return testr.NewWithOptions(t, testr.Options{
40-
Verbosity: LogLevelWithDefault(2),
49+
Verbosity: -level,
4150
})
4251
}
4352

site/content/en/docs/contribution_guidelines/testing.md

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,18 @@ E2E_K8S_FULL_VERSION=1.34.1 make test-e2e
7272
For running a subset of tests, see [Running subset of tests](#running-subset-of-integration-or-e2e-tests).
7373

7474
## Increase logging verbosity
75-
You can change log level (for example, set -5 to increase verbosity) using `TEST_LOG_LEVEL` variables.
76-
By default, `TEST_LOG_LEVEL=-3`.
75+
`TEST_LOG_LEVEL` controls test logging uniformly for all targets:
76+
77+
- `go test`, `make test` (unit tests)
78+
- `make test-integration` (integration tests)
79+
- `make test-*-e2e` (e2e tests)
80+
81+
Use more negative values for more verbose logs and higher (positive) values for quieter logs. For example:
82+
```shell
83+
TEST_LOG_LEVEL=-5 make test-integration # more verbose
84+
TEST_LOG_LEVEL=-1 make test # less verbose than default
85+
```
86+
Default is `TEST_LOG_LEVEL=-3`.
7787

7888
## Debug tests in VSCode
7989
It is possible to debug unit and integration tests in VSCode.

site/content/zh-CN/docs/contribution_guidelines/testing.md

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,18 @@ E2E_K8S_FULL_VERSION=1.34.1 make test-e2e
7272
关于运行测试子集,请参阅 [运行测试子集](#running-subset-of-integration-or-e2e-tests)
7373

7474
## 增加日志详细程度 {#increase-logging-verbosity}
75-
你可以使用 `TEST_LOG_LEVEL` 变量更改日志级别(例如,设置 -5 来增加详细程度)。
76-
默认情况下,`TEST_LOG_LEVEL=-3`
75+
`TEST_LOG_LEVEL` 统一控制所有测试目标的日志级别:
76+
77+
- `go test``make test`(单元测试)
78+
- `make test-integration`(集成测试)
79+
- `make test-*-e2e`(端到端测试)
80+
81+
使用更小的负数获取更详细的日志,使用更大的正数降低日志量。例如:
82+
```shell
83+
TEST_LOG_LEVEL=-5 make test-integration # 更详细
84+
TEST_LOG_LEVEL=-1 make test # 比默认更少
85+
```
86+
默认值为 `TEST_LOG_LEVEL=-3`
7787

7888
## 在 VSCode 中调试测试 {#debug-tests-in-vscode}
7989
可以在 VSCode 中调试单元测试和集成测试。

test/util/util.go

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -72,17 +72,13 @@ import (
7272
"sigs.k8s.io/kueue/pkg/scheduler/preemption"
7373
"sigs.k8s.io/kueue/pkg/util/admissioncheck"
7474
utiltas "sigs.k8s.io/kueue/pkg/util/tas"
75-
"sigs.k8s.io/kueue/pkg/util/testing"
75+
utiltesting "sigs.k8s.io/kueue/pkg/util/testing"
7676
"sigs.k8s.io/kueue/pkg/workload"
7777
"sigs.k8s.io/kueue/pkg/workloadslicing"
7878
)
7979

80-
const (
81-
defaultLogLevel = -3
82-
)
83-
8480
var SetupLogger = sync.OnceFunc(func() {
85-
ctrl.SetLogger(NewTestingLogger(ginkgo.GinkgoWriter, testing.LogLevelWithDefault(defaultLogLevel)))
81+
ctrl.SetLogger(NewTestingLogger(ginkgo.GinkgoWriter))
8682
})
8783

8884
type objAsPtr[T any] interface {
@@ -116,7 +112,7 @@ func expectObjectToBeDeletedWithTimeout[PtrT objAsPtr[T], T any](ctx context.Con
116112
}
117113
gomega.EventuallyWithOffset(2, func(g gomega.Gomega) {
118114
newObj := PtrT(new(T))
119-
g.Expect(k8sClient.Get(ctx, client.ObjectKeyFromObject(o), newObj)).Should(testing.BeNotFoundError())
115+
g.Expect(k8sClient.Get(ctx, client.ObjectKeyFromObject(o), newObj)).Should(utiltesting.BeNotFoundError())
120116
}, timeout, Interval).Should(gomega.Succeed())
121117
}
122118

@@ -375,15 +371,15 @@ func ExpectWorkloadToFinish(ctx context.Context, k8sClient client.Client, wlKey
375371
gomega.EventuallyWithOffset(1, func(g gomega.Gomega) {
376372
var wl kueue.Workload
377373
g.Expect(k8sClient.Get(ctx, wlKey, &wl)).To(gomega.Succeed())
378-
g.Expect(wl.Status.Conditions).To(testing.HaveConditionStatusTrue(kueue.WorkloadFinished), "it's finished")
374+
g.Expect(wl.Status.Conditions).To(utiltesting.HaveConditionStatusTrue(kueue.WorkloadFinished), "it's finished")
379375
}, LongTimeout, Interval).Should(gomega.Succeed())
380376
}
381377

382378
func ExpectPodsReadyCondition(ctx context.Context, k8sClient client.Client, wlKey client.ObjectKey) {
383379
gomega.EventuallyWithOffset(1, func(g gomega.Gomega) {
384380
var wl kueue.Workload
385381
g.Expect(k8sClient.Get(ctx, wlKey, &wl)).To(gomega.Succeed())
386-
g.Expect(wl.Status.Conditions).To(testing.HaveConditionStatusTrue(kueue.WorkloadPodsReady), "pods are ready")
382+
g.Expect(wl.Status.Conditions).To(utiltesting.HaveConditionStatusTrue(kueue.WorkloadPodsReady), "pods are ready")
387383
}, LongTimeout, Interval).Should(gomega.Succeed())
388384
}
389385

@@ -1006,11 +1002,12 @@ func ExpectPreemptedCondition(ctx context.Context, k8sClient client.Client, reas
10061002
}, Timeout, Interval).Should(gomega.Succeed())
10071003
}
10081004

1009-
func NewTestingLogger(writer io.Writer, level int) logr.Logger {
1005+
func NewTestingLogger(writer io.Writer) logr.Logger {
10101006
opts := func(o *zap.Options) {
10111007
o.TimeEncoder = zapcore.RFC3339NanoTimeEncoder
10121008
o.ZapOpts = []zaplog.Option{zaplog.AddCaller()}
10131009
}
1010+
level := utiltesting.LogLevelWithDefault(utiltesting.DefaultLogLevel)
10141011
return zap.New(
10151012
zap.WriteTo(writer),
10161013
zap.UseDevMode(true),
@@ -1030,7 +1027,7 @@ func ExpectClusterQueuesToBeActive(ctx context.Context, c client.Client, cqs ...
10301027
readCq := &kueue.ClusterQueue{}
10311028
for _, cq := range cqs {
10321029
g.Expect(c.Get(ctx, client.ObjectKeyFromObject(cq), readCq)).To(gomega.Succeed())
1033-
g.Expect(readCq.Status.Conditions).To(testing.HaveConditionStatusTrue(kueue.ClusterQueueActive))
1030+
g.Expect(readCq.Status.Conditions).To(utiltesting.HaveConditionStatusTrue(kueue.ClusterQueueActive))
10341031
}
10351032
}, Timeout, Interval).Should(gomega.Succeed())
10361033
}
@@ -1040,7 +1037,7 @@ func ExpectLocalQueuesToBeActive(ctx context.Context, c client.Client, lqs ...*k
10401037
readLq := &kueue.LocalQueue{}
10411038
for _, lq := range lqs {
10421039
g.Expect(c.Get(ctx, client.ObjectKeyFromObject(lq), readLq)).To(gomega.Succeed())
1043-
g.Expect(readLq.Status.Conditions).To(testing.HaveConditionStatusTrue(kueue.LocalQueueActive))
1040+
g.Expect(readLq.Status.Conditions).To(utiltesting.HaveConditionStatusTrue(kueue.LocalQueueActive))
10441041
}
10451042
}, Timeout, Interval).Should(gomega.Succeed())
10461043
}

0 commit comments

Comments
 (0)