Skip to content

Commit b852413

Browse files
authored
fix TestClientOnResponseError parallel tests (#710)
In case of using `t.Parallel()` inside a for loop, the loop variables must be copied, otherwise only the last test will be executed. ```go for _, test := range tests { t.Run(test.name, func(t *testing.T) { t.Parallel() ``` changed to ```go for _, test := range tests { test := test t.Run(test.name, func(t *testing.T) { t.Parallel() ``` also the AuthServer must be created within the test, otherwise some tests fail. `t.Log(test.Name)` can be used to verify the issue: ```go for _, test := range tests { t.Run(test.name, func(t *testing.T) { t.Parallel() t.Log("Test name:", test.name) ```
1 parent 106e689 commit b852413

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

client_test.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -780,9 +780,6 @@ func TestNewWithLocalAddr(t *testing.T) {
780780
}
781781

782782
func TestClientOnResponseError(t *testing.T) {
783-
ts := createAuthServer(t)
784-
defer ts.Close()
785-
786783
tests := []struct {
787784
name string
788785
setup func(*Client)
@@ -862,8 +859,12 @@ func TestClientOnResponseError(t *testing.T) {
862859
}
863860

864861
for _, test := range tests {
862+
test := test
865863
t.Run(test.name, func(t *testing.T) {
866864
t.Parallel()
865+
ts := createAuthServer(t)
866+
defer ts.Close()
867+
867868
var assertErrorHook = func(r *Request, err error) {
868869
assertNotNil(t, r)
869870
v, ok := err.(*ResponseError)

0 commit comments

Comments
 (0)