Skip to content

fix: stop running tests that exec sh scripts in parallel #11834

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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 26, 2024
Merged
Changes from all 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
25 changes: 10 additions & 15 deletions provisioner/terraform/provision_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import (
"runtime"
"sort"
"strings"
"syscall"
"testing"
"time"

Expand Down Expand Up @@ -126,8 +125,10 @@ func sendApply(sess proto.DRPCProvisioner_SessionClient, transition proto.Worksp
}}})
}

// below we exec fake_cancel.sh, which causes the kernel to execute it, and if more than
// one process tries to do this simultaneously, it can cause "text file busy"
// nolint: paralleltest
func TestProvision_Cancel(t *testing.T) {
t.Parallel()
if runtime.GOOS == "windows" {
t.Skip("This test uses interrupts and is not supported on Windows")
}
Expand Down Expand Up @@ -158,24 +159,16 @@ func TestProvision_Cancel(t *testing.T) {
}
for _, tt := range tests {
tt := tt
// below we exec fake_cancel.sh, which causes the kernel to execute it, and if more than
// one process tries to do this, it can cause "text file busy"
// nolint: paralleltest
t.Run(tt.name, func(t *testing.T) {
t.Parallel()

dir := t.TempDir()
binPath := filepath.Join(dir, "terraform")

// Example: exec /path/to/terrafork_fake_cancel.sh 1.2.1 apply "$@"
content := fmt.Sprintf("#!/bin/sh\nexec %q %s %s \"$@\"\n", fakeBin, terraform.TerraformVersion.String(), tt.mode)

// golang's standard OS library can sometimes leave the file descriptor open even after
// "Closing" the file (which can then lead to a "text file busy" error, so we bypass this
// and use syscall directly).
fd, err := syscall.Open(binPath, syscall.O_WRONLY|syscall.O_CREAT, 0o755)
require.NoError(t, err)
n, err := syscall.Write(fd, []byte(content))
require.NoError(t, err)
require.Equal(t, len(content), n)
err = syscall.Close(fd)
err := os.WriteFile(binPath, []byte(content), 0o755) //#nosec
require.NoError(t, err)
t.Logf("wrote fake terraform script to %s", binPath)

Expand Down Expand Up @@ -228,8 +221,10 @@ func TestProvision_Cancel(t *testing.T) {
}
}

// below we exec fake_cancel_hang.sh, which causes the kernel to execute it, and if more than
// one process tries to do this, it can cause "text file busy"
// nolint: paralleltest
func TestProvision_CancelTimeout(t *testing.T) {
t.Parallel()
if runtime.GOOS == "windows" {
t.Skip("This test uses interrupts and is not supported on Windows")
}
Expand Down