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

Commitb63dfe7

Browse files
authored
perf(cli): optimize CPU consumption of help pages (#9607)
This change reduces the CPU consumption of --help by ~50%.Also, this change removes ANSI escape codes from our golden files. Idon't think those were worth the inability to parallelize golden file tests andglobal state fragility.
1 parent7311ffb commitb63dfe7

File tree

93 files changed

+861
-835
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

93 files changed

+861
-835
lines changed

‎cli/clitest/clitest.go‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import (
2929

3030
// New creates a CLI instance with a configuration pointed to a
3131
// temporary testing directory.
32-
funcNew(t*testing.T,args...string) (*clibase.Invocation, config.Root) {
32+
funcNew(t testing.TB,args...string) (*clibase.Invocation, config.Root) {
3333
varroot cli.RootCmd
3434

3535
cmd,err:=root.Command(root.AGPL())
@@ -56,7 +56,7 @@ func (l *logWriter) Write(p []byte) (n int, err error) {
5656
}
5757

5858
funcNewWithCommand(
59-
t*testing.T,cmd*clibase.Cmd,args...string,
59+
t testing.TB,cmd*clibase.Cmd,args...string,
6060
) (*clibase.Invocation, config.Root) {
6161
configDir:=config.Root(t.TempDir())
6262
logger:=slogtest.Make(t,nil)

‎cli/clitest/golden.go‎

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,9 @@ import (
1111
"strings"
1212
"testing"
1313

14-
"github.com/muesli/termenv"
1514
"github.com/stretchr/testify/require"
1615

1716
"github.com/coder/coder/v2/cli/clibase"
18-
"github.com/coder/coder/v2/cli/cliui"
1917
"github.com/coder/coder/v2/cli/config"
2018
"github.com/coder/coder/v2/coderd/coderdtest"
2119
"github.com/coder/coder/v2/coderd/database/dbtestutil"
@@ -50,12 +48,8 @@ func DefaultCases() []CommandHelpCase {
5048

5149
// TestCommandHelp will test the help output of the given commands
5250
// using golden files.
53-
//
54-
//nolint:tparallel,paralleltest
5551
funcTestCommandHelp(t*testing.T,getRootfunc(t*testing.T)*clibase.Cmd,cases []CommandHelpCase) {
56-
// ANSI256 escape codes are far easier for humans to parse in a diff,
57-
// but TrueColor is probably more popular with modern terminals.
58-
cliui.TestColor(t,termenv.ANSI)
52+
t.Parallel()
5953
rootClient,replacements:=prepareTestData(t)
6054

6155
root:=getRoot(t)

‎cli/cliui/agent_test.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@ func TestAgent(t *testing.T) {
340340
line:=s.Text()
341341
t.Log(line)
342342
iflen(tc.want)==0 {
343-
require.Fail(t,"unexpected line: "+line)
343+
require.Fail(t,"unexpected line",line)
344344
}
345345
require.Contains(t,line,tc.want[0])
346346
tc.want=tc.want[1:]

‎cli/cliui/cliui.go‎

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
package cliui
22

33
import (
4+
"flag"
45
"os"
5-
"testing"
6+
"sync"
67
"time"
78

89
"github.com/muesli/termenv"
@@ -30,29 +31,29 @@ type Styles struct {
3031
Wrap pretty.Style
3132
}
3233

33-
varcolor=termenv.NewOutput(os.Stdout).ColorProfile()
34-
35-
// TestColor sets the color profile to the given profile for the duration of the
36-
// test.
37-
// WARN: Must not be used in parallel tests.
38-
funcTestColor(t*testing.T,tprofile termenv.Profile) {
39-
old:=color
40-
color=tprofile
41-
t.Cleanup(func() {
42-
color=old
43-
})
44-
}
34+
var (
35+
color termenv.Profile
36+
colorOnce sync.Once
37+
)
4538

4639
var (
47-
Green=color.Color("#04B575")
48-
Red=color.Color("#ED567A")
49-
Fuchsia=color.Color("#EE6FF8")
50-
Yellow=color.Color("#ECFD65")
51-
Blue=color.Color("#5000ff")
40+
Green=Color("#04B575")
41+
Red=Color("#ED567A")
42+
Fuchsia=Color("#EE6FF8")
43+
Yellow=Color("#ECFD65")
44+
Blue=Color("#5000ff")
5245
)
5346

5447
// Color returns a color for the given string.
5548
funcColor(sstring) termenv.Color {
49+
colorOnce.Do(func() {
50+
color=termenv.NewOutput(os.Stdout).ColorProfile()
51+
ifflag.Lookup("test.v")!=nil {
52+
// Use a consistent colorless profile in tests so that results
53+
// are deterministic.
54+
color=termenv.Ascii
55+
}
56+
})
5657
returncolor.Color(s)
5758
}
5859

‎cli/cliui/resources_internal_test.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ func TestRenderAgentVersion(t *testing.T) {
4444
t.Run(testCase.name,func(t*testing.T) {
4545
t.Parallel()
4646
actual:=renderAgentVersion(testCase.agentVersion,testCase.serverVersion)
47-
assert.Equal(t,testCase.expected,actual)
47+
assert.Equal(t,testCase.expected,(actual))
4848
})
4949
}
5050
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp