mirror of https://github.com/coder/coder.git
fix: stop running tests that exec sh scripts in parallel (#11834)
Ok, so my last attempt at a fix here failed https://github.com/coder/coder/actions/runs/7666229961/job/20893608286 I have a new theory: it's not the `terraform` binary that's busy, it's actually `fake_cancel.sh` and it gets marked busy when we `exec` it from the script we write. Use of `exec` also replaces the executing code in place, rather than starting a new process/shell, so that's why the error we get says `terraform` is busy.
This commit is contained in:
parent
0ba035a16d
commit
d6baa3cab0
|
@ -14,7 +14,6 @@ import (
|
|||
"runtime"
|
||||
"sort"
|
||||
"strings"
|
||||
"syscall"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
|
@ -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")
|
||||
}
|
||||
|
@ -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)
|
||||
|
||||
|
@ -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")
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue