(, ), , :
package foo_test
var forceSequential chan bool = make(chan bool, 1)
func Test1(t *testing.T) {
forceSequential <- true
<- forceSequential
}
func Test2(t *testing.T) {
forceSequential <- true
<- forceSequential
}
func Test3(t *testing.T) {
forceSequential <- true
<- forceSequential
}
, , . :
package foo_test
var (
chan1 bool = make(chan bool, 1)
chan2 bool = make(chan bool, 1)
)
func Test1(t *testing.T) {
chan1 <- true
}
func Test2(t *testing.T) {
<- chan1
chan2 <- true
}
func Test3(t *testing.T) {
<- chan2
}
But then again, does not do this . If your tests (and, accordingly, your code) depend on the global state for proper execution, you are doing something wrong . Fix it and you will not have problems with parallel tests.
source
share