Server : LiteSpeed System : Linux in-mum-web1333.main-hosting.eu 4.18.0-553.37.1.lve.el8.x86_64 #1 SMP Mon Feb 10 22:45:17 UTC 2025 x86_64 User : u141265441 ( 141265441) PHP Version : 8.4.3 Disable Function : system, exec, shell_exec, passthru, mysql_list_dbs, ini_alter, dl, symlink, link, chgrp, leak, popen, apache_child_terminate, virtual, mb_send_mail Directory : /proc/self/root/opt/golang/1.22.0/src/cmd/go/testdata/script/ |
# Run parallel chatty tests.
# Check that multiple parallel outputs continue running.
! go test -parallel 3 chatty_parallel_test.go -v
stdout -count=1 '^=== CONT TestChattyParallel/sub-0'
stdout -count=1 '^=== CONT TestChattyParallel/sub-1'
stdout -count=1 '^=== CONT TestChattyParallel/sub-2'
stdout -count=1 '^=== (CONT|NAME) TestChattyParallel/sub-0\n chatty_parallel_test.go:38: error from sub-0$'
stdout -count=1 '^=== (CONT|NAME) TestChattyParallel/sub-1\n chatty_parallel_test.go:38: error from sub-1$'
stdout -count=1 '^=== (CONT|NAME) TestChattyParallel/sub-2\n chatty_parallel_test.go:38: error from sub-2$'
# Run parallel chatty tests with -json.
# Check that each output is attributed to the right test.
! go test -json -parallel 3 chatty_parallel_test.go -v
stdout -count=1 '"Test":"TestChattyParallel/sub-0","Output":" chatty_parallel_test.go:38: error from sub-0\\n"'
stdout -count=1 '"Test":"TestChattyParallel/sub-1","Output":" chatty_parallel_test.go:38: error from sub-1\\n"'
stdout -count=1 '"Test":"TestChattyParallel/sub-2","Output":" chatty_parallel_test.go:38: error from sub-2\\n"'
-- chatty_parallel_test.go --
package chatty_parallel_test
import (
"testing"
"fmt"
"flag"
)
// This test ensures the order of CONT lines in parallel chatty tests.
func TestChattyParallel(t *testing.T) {
t.Parallel()
// The number of concurrent tests running. This is closely tied to the
// -parallel test flag, so we grab it from the flag rather than setting it
// to some constant.
parallel := flag.Lookup("test.parallel").Value.(flag.Getter).Get().(int)
// ready is a synchronization mechanism that causes subtests to execute
// round robin.
ready := make([]chan bool, parallel)
for i := range ready {
ready[i] = make(chan bool, 1)
}
ready[0] <- true
for i := range ready {
i := i
t.Run(fmt.Sprintf("sub-%d", i), func(t *testing.T) {
t.Parallel()
// Some basic log output to precede the failures.
<-ready[i]
t.Logf("this is sub-%d", i)
ready[(i+1)%len(ready)] <- true
// The actual failure messages we care about.
<-ready[i]
t.Errorf("error from sub-%d", i)
ready[(i+1)%len(ready)] <- true
})
}
}