Skip to content

Commit

Permalink
singleflight: make the check for exec support in TestPanicDoChan plat…
Browse files Browse the repository at this point in the history
…form-agnostic

The new wasip1 GOOS does not support exec, but some ios environments
(like Corellium) might. Update the test to exec itself with -test.list
as a control case.

For golang/go#58141.

Change-Id: Id69950fc394910620f6c73cb437ca75c09ad8c29
Reviewed-on: https://go-review.googlesource.com/c/sync/+/485980
Run-TryBot: Bryan Mills <[email protected]>
Commit-Queue: Bryan Mills <[email protected]>
Reviewed-by: Dmitri Shuralyov <[email protected]>
Auto-Submit: Bryan Mills <[email protected]>
Reviewed-by: Johan Brandhorst-Satzkorn <[email protected]>
TryBot-Result: Gopher Robot <[email protected]>
Reviewed-by: Dmitri Shuralyov <[email protected]>
  • Loading branch information
Bryan C. Mills authored and gopherbot committed Apr 19, 2023
1 parent 8fcdb60 commit 1ea3257
Showing 1 changed file with 18 additions and 9 deletions.
27 changes: 18 additions & 9 deletions singleflight/singleflight_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,11 +223,24 @@ func TestGoexitDo(t *testing.T) {
}
}

func TestPanicDoChan(t *testing.T) {
if runtime.GOOS == "js" {
t.Skipf("js does not support exec")
func executable(t testing.TB) string {
exe, err := os.Executable()
if err != nil {
t.Skipf("skipping: test executable not found")
}

// Control case: check whether exec.Command works at all.
// (For example, it might fail with a permission error on iOS.)
cmd := exec.Command(exe, "-test.list=^$")
cmd.Env = []string{}
if err := cmd.Run(); err != nil {
t.Skipf("skipping: exec appears not to work on %s: %v", runtime.GOOS, err)
}

return exe
}

func TestPanicDoChan(t *testing.T) {
if os.Getenv("TEST_PANIC_DOCHAN") != "" {
defer func() {
recover()
Expand All @@ -243,7 +256,7 @@ func TestPanicDoChan(t *testing.T) {

t.Parallel()

cmd := exec.Command(os.Args[0], "-test.run="+t.Name(), "-test.v")
cmd := exec.Command(executable(t), "-test.run="+t.Name(), "-test.v")
cmd.Env = append(os.Environ(), "TEST_PANIC_DOCHAN=1")
out := new(bytes.Buffer)
cmd.Stdout = out
Expand All @@ -266,10 +279,6 @@ func TestPanicDoChan(t *testing.T) {
}

func TestPanicDoSharedByDoChan(t *testing.T) {
if runtime.GOOS == "js" {
t.Skipf("js does not support exec")
}

if os.Getenv("TEST_PANIC_DOCHAN") != "" {
blocked := make(chan struct{})
unblock := make(chan struct{})
Expand Down Expand Up @@ -297,7 +306,7 @@ func TestPanicDoSharedByDoChan(t *testing.T) {

t.Parallel()

cmd := exec.Command(os.Args[0], "-test.run="+t.Name(), "-test.v")
cmd := exec.Command(executable(t), "-test.run="+t.Name(), "-test.v")
cmd.Env = append(os.Environ(), "TEST_PANIC_DOCHAN=1")
out := new(bytes.Buffer)
cmd.Stdout = out
Expand Down

0 comments on commit 1ea3257

Please sign in to comment.