From e4f813cd1b93d0e65e736d3214cad8005523e557 Mon Sep 17 00:00:00 2001 From: Adam Babik Date: Mon, 15 Jan 2024 08:05:45 +0100 Subject: [PATCH] Reduce parallelism in command pkg tests --- Makefile | 9 +++-- internal/command/command_native.go | 7 +--- internal/command/command_test.go | 10 ++--- internal/command/command_virtual.go | 14 +++---- internal/command/command_virtual_test.go | 16 -------- internal/command/config_code_block.go | 48 ++++++++++++------------ internal/runnerv2service/service_test.go | 12 ++---- 7 files changed, 47 insertions(+), 69 deletions(-) diff --git a/Makefile b/Makefile index 77fdce8b1..e3aa04888 100644 --- a/Makefile +++ b/Makefile @@ -29,7 +29,7 @@ wasm: .PHONY: test/execute test/execute: PKGS ?= "./..." test/execute: build test/prep-git-project - @TZ=UTC go test -ldflags="$(LDTESTFLAGS)" -timeout=30s -covermode=atomic -coverprofile=cover.out -coverpkg=./... $(PKGS) + TZ=UTC go test -ldflags="$(LDTESTFLAGS)" -timeout=60s -covermode=atomic -coverprofile=cover.out -coverpkg=./... $(PKGS) .PHONY: test/prep-git-project test/prep-git-project: @@ -37,12 +37,15 @@ test/prep-git-project: @cp -r -f internal/project/testdata/git-project/.gitignore.bkp internal/project/testdata/git-project/.gitignore @cp -r -f internal/project/testdata/git-project/nested/.gitignore.bkp internal/project/testdata/git-project/nested/.gitignore -.PHONY: test -test: test/execute +.PHONY: test/clean-git-project +test/clean-git-project: @rm -r -f internal/project/testdata/git-project/.git @rm -r -f internal/project/testdata/git-project/.gitignore @rm -r -f internal/project/testdata/git-project/nested/.gitignore +.PHONY: test +test: test/prep-git-project test/execute test/clean-git-project + .PHONY: test/update-snapshots test/update-snapshots: @TZ=UTC UPDATE_SNAPSHOTS=true go test ./... diff --git a/internal/command/command_native.go b/internal/command/command_native.go index 3b564a8da..ace384451 100644 --- a/internal/command/command_native.go +++ b/internal/command/command_native.go @@ -39,15 +39,10 @@ func (c *NativeCommand) Start(ctx context.Context) (err error) { logger: c.logger, } - source := []envSource{c.opts.GetEnv} - if c.opts.Session != nil { - source = append(source, c.opts.Session.GetEnv) - } - cfg, err := normalizeConfig( c.cfg, argsNormalizer, - &envNormalizer{sources: source}, + &envNormalizer{sources: []envSource{c.opts.Session.GetEnv}}, ) if err != nil { return diff --git a/internal/command/command_test.go b/internal/command/command_test.go index 0ab0bf403..9261a5b1d 100644 --- a/internal/command/command_test.go +++ b/internal/command/command_test.go @@ -38,8 +38,6 @@ func init() { } func TestExecutionCommandFromCodeBlocks(t *testing.T) { - t.Parallel() - logger, err := zap.NewDevelopment() require.NoError(t, err) defer logger.Sync() @@ -112,6 +110,8 @@ func TestExecutionCommandFromCodeBlocks(t *testing.T) { t.Run("NativeCommand", func(t *testing.T) { t.Parallel() + tc := tc + t.Run(tc.name, func(t *testing.T) { t.Parallel() @@ -130,6 +130,8 @@ func TestExecutionCommandFromCodeBlocks(t *testing.T) { t.Run("VirtualCommand", func(t *testing.T) { t.Parallel() + tc := tc + t.Run(tc.name, func(t *testing.T) { t.Parallel() @@ -189,7 +191,7 @@ func testExecuteNativeCommand( command, err := NewNative(cfg, options) require.NoError(t, err) - ctx, cancel := context.WithTimeout(context.Background(), time.Second) + ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) defer cancel() require.NoError(t, command.Start(ctx)) @@ -240,8 +242,6 @@ func testExecuteVirtualCommand( } func TestCommandWithSession(t *testing.T) { - t.Parallel() - setterCfg := &Config{ ProgramName: "bash", Source: &runnerv2alpha1.ProgramConfig_Commands{ diff --git a/internal/command/command_virtual.go b/internal/command/command_virtual.go index 8c25fce9d..8e2da1b71 100644 --- a/internal/command/command_virtual.go +++ b/internal/command/command_virtual.go @@ -48,7 +48,12 @@ type readCloser struct { done chan struct{} } -func (r *readCloser) Read(p []byte) (n int, err error) { +func (r *readCloser) Read(p []byte) (int, error) { + var ( + n int + err error + ) + readc := make(chan struct{}) go func() { @@ -119,15 +124,10 @@ func (c *VirtualCommand) Start(ctx context.Context) (err error) { logger: c.logger, } - source := []envSource{c.opts.GetEnv} - if c.opts.Session != nil { - source = append(source, c.opts.Session.GetEnv) - } - cfg, err := normalizeConfig( c.cfg, argsNormalizer, - &envNormalizer{sources: source}, + &envNormalizer{sources: []envSource{c.opts.Session.GetEnv}}, ) if err != nil { return diff --git a/internal/command/command_virtual_test.go b/internal/command/command_virtual_test.go index f2d0439a9..1dc5d4760 100644 --- a/internal/command/command_virtual_test.go +++ b/internal/command/command_virtual_test.go @@ -18,8 +18,6 @@ import ( func TestVirtualCommand(t *testing.T) { t.Run("OptionsIsNil", func(t *testing.T) { - t.Parallel() - cmd, err := NewVirtual(testConfigBasicProgram, nil) require.NoError(t, err) require.NoError(t, cmd.Start(context.Background())) @@ -27,8 +25,6 @@ func TestVirtualCommand(t *testing.T) { }) t.Run("Output", func(t *testing.T) { - t.Parallel() - stdout := bytes.NewBuffer(nil) opts := &VirtualCommandOptions{ Stdout: stdout, @@ -41,8 +37,6 @@ func TestVirtualCommand(t *testing.T) { }) t.Run("Getters", func(t *testing.T) { - t.Parallel() - cmd, err := NewVirtual(&Config{ ProgramName: "sleep", Arguments: []string{"1"}, @@ -56,8 +50,6 @@ func TestVirtualCommand(t *testing.T) { }) t.Run("SetWinsize", func(t *testing.T) { - t.Parallel() - stdout := bytes.NewBuffer(nil) cmd, err := NewVirtual( @@ -88,10 +80,7 @@ func TestVirtualCommandFromCodeBlocksWithInputUsingPipe(t *testing.T) { defer logger.Sync() t.Run("Cat", func(t *testing.T) { - t.Parallel() - source := "```sh\ncat - | tr a-z A-Z\n```" - doc := document.New([]byte(source), idResolver) node, err := doc.Root() require.NoError(t, err) @@ -128,10 +117,7 @@ func TestVirtualCommandFromCodeBlocksWithInputUsingPipe(t *testing.T) { }) t.Run("Read", func(t *testing.T) { - t.Parallel() - source := "```sh\nread name\necho \"My name is $name\"\n```" - doc := document.New([]byte(source), idResolver) node, err := doc.Root() require.NoError(t, err) @@ -166,8 +152,6 @@ func TestVirtualCommandFromCodeBlocksWithInputUsingPipe(t *testing.T) { }) t.Run("SimulateCtrlC", func(t *testing.T) { - t.Parallel() - // Using sh start bash. We need to go deeper... source := "```sh\nbash\n```" diff --git a/internal/command/config_code_block.go b/internal/command/config_code_block.go index cf77bd9ef..6fdb5c31a 100644 --- a/internal/command/config_code_block.go +++ b/internal/command/config_code_block.go @@ -16,6 +16,30 @@ type configBuilder struct { block *document.CodeBlock } +func (b *configBuilder) Build() (*Config, error) { + cfg := &Config{ + ProgramName: b.programPath(), + Directory: b.dir(), + Interactive: b.block.Interactive(), + } + + if isShellLanguage(filepath.Base(cfg.ProgramName)) { + cfg.Mode = runnerv2alpha1.CommandMode_COMMAND_MODE_INLINE + cfg.Source = &runnerv2alpha1.ProgramConfig_Commands{ + Commands: &runnerv2alpha1.ProgramConfig_CommandList{ + Items: b.block.Lines(), + }, + } + } else { + cfg.Mode = runnerv2alpha1.CommandMode_COMMAND_MODE_FILE + cfg.Source = &runnerv2alpha1.ProgramConfig_Script{ + Script: prepareScriptFromLines(cfg.ProgramName, b.block.Lines()), + } + } + + return cfg, nil +} + func (b *configBuilder) dir() string { var dirs []string @@ -55,30 +79,6 @@ func (b *configBuilder) programPath() string { return interpreter } -func (b *configBuilder) Build() (*Config, error) { - cfg := &Config{ - ProgramName: b.programPath(), - Directory: b.dir(), - Interactive: b.block.Interactive(), - } - - if isShellLanguage(filepath.Base(cfg.ProgramName)) { - cfg.Mode = runnerv2alpha1.CommandMode_COMMAND_MODE_INLINE - cfg.Source = &runnerv2alpha1.ProgramConfig_Commands{ - Commands: &runnerv2alpha1.ProgramConfig_CommandList{ - Items: b.block.Lines(), - }, - } - } else { - cfg.Mode = runnerv2alpha1.CommandMode_COMMAND_MODE_FILE - cfg.Source = &runnerv2alpha1.ProgramConfig_Script{ - Script: prepareScriptFromLines(cfg.ProgramName, b.block.Lines()), - } - } - - return cfg, nil -} - func resolveDir(parentDir string, candidates []string) string { for _, dir := range candidates { dir := filepath.FromSlash(dir) diff --git a/internal/runnerv2service/service_test.go b/internal/runnerv2service/service_test.go index 87a7a3582..3df78400d 100644 --- a/internal/runnerv2service/service_test.go +++ b/internal/runnerv2service/service_test.go @@ -20,8 +20,6 @@ import ( ) func TestRunnerServiceServerExecute(t *testing.T) { - t.Parallel() - lis, stop := testStartRunnerServiceServer(t) t.Cleanup(stop) _, client := testCreateRunnerServiceClient(t, lis) @@ -134,8 +132,6 @@ func TestRunnerServiceServerExecute(t *testing.T) { } func TestRunnerServiceServerExecute_Input(t *testing.T) { - t.Parallel() - lis, stop := testStartRunnerServiceServer(t) t.Cleanup(stop) _, client := testCreateRunnerServiceClient(t, lis) @@ -258,8 +254,6 @@ func TestRunnerServiceServerExecute_Input(t *testing.T) { } func TestRunnerServiceServerExecute_WithStop(t *testing.T) { - t.Parallel() - lis, stop := testStartRunnerServiceServer(t) t.Cleanup(stop) _, client := testCreateRunnerServiceClient(t, lis) @@ -306,13 +300,13 @@ func TestRunnerServiceServerExecute_WithStop(t *testing.T) { } func TestRunnerServiceServerExecute_Winsize(t *testing.T) { - t.Parallel() - lis, stop := testStartRunnerServiceServer(t) t.Cleanup(stop) _, client := testCreateRunnerServiceClient(t, lis) t.Run("DefaultWinsize", func(t *testing.T) { + t.Parallel() + stream, err := client.Execute(context.Background()) require.NoError(t, err) @@ -343,6 +337,8 @@ func TestRunnerServiceServerExecute_Winsize(t *testing.T) { }) t.Run("SetWinsizeInInitialRequest", func(t *testing.T) { + t.Parallel() + stream, err := client.Execute(context.Background()) require.NoError(t, err)