Skip to content

Commit 9f6f5f2

Browse files
author
Guangming Wang
committed
fix: t.Fatal should be used in main goroutine
Signed-off-by: Guangming Wang <[email protected]>
1 parent 8b65924 commit 9f6f5f2

File tree

1 file changed

+18
-8
lines changed

1 file changed

+18
-8
lines changed

test/e2e/installplan_e2e_test.go

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package e2e
22

33
import (
44
"encoding/json"
5+
"errors"
56
"fmt"
67
"strings"
78
"testing"
@@ -2370,16 +2371,14 @@ func TestCreateInstallPlanWithPermissions(t *testing.T) {
23702371
require.NoError(t, err)
23712372

23722373
done := make(chan struct{})
2373-
quit := make(chan struct{})
2374-
defer close(quit)
2374+
errExit := make(chan error)
23752375
go func() {
23762376
for {
23772377
select {
2378-
case <-quit:
2379-
return
23802378
case evt, ok := <-crWatcher.ResultChan():
23812379
if !ok {
2382-
t.Fatal("cr watch channel closed unexpectedly")
2380+
errExit <- errors.New("cr watch channel closed unexpectedly")
2381+
return
23832382
}
23842383
if evt.Type == watch.Deleted {
23852384
cr, ok := evt.Object.(*rbacv1.ClusterRole)
@@ -2389,11 +2388,13 @@ func TestCreateInstallPlanWithPermissions(t *testing.T) {
23892388
delete(createdClusterRoleNames, cr.GetName())
23902389
if len(createdClusterRoleNames) == 0 && len(createdClusterRoleBindingNames) == 0 && len(createdServiceAccountNames) == 0 {
23912390
done <- struct{}{}
2391+
return
23922392
}
23932393
}
23942394
case evt, ok := <-crbWatcher.ResultChan():
23952395
if !ok {
2396-
t.Fatal("crb watch channel closed unexpectedly")
2396+
errExit <- errors.New("crb watch channel closed unexpectedly")
2397+
return
23972398
}
23982399
if evt.Type == watch.Deleted {
23992400
crb, ok := evt.Object.(*rbacv1.ClusterRoleBinding)
@@ -2403,11 +2404,13 @@ func TestCreateInstallPlanWithPermissions(t *testing.T) {
24032404
delete(createdClusterRoleBindingNames, crb.GetName())
24042405
if len(createdClusterRoleNames) == 0 && len(createdClusterRoleBindingNames) == 0 && len(createdServiceAccountNames) == 0 {
24052406
done <- struct{}{}
2407+
return
24062408
}
24072409
}
24082410
case evt, ok := <-saWatcher.ResultChan():
24092411
if !ok {
2410-
t.Fatal("sa watch channel closed unexpectedly")
2412+
errExit <- errors.New("sa watch channel closed unexpectedly")
2413+
return
24112414
}
24122415
if evt.Type == watch.Deleted {
24132416
sa, ok := evt.Object.(*corev1.ServiceAccount)
@@ -2417,17 +2420,24 @@ func TestCreateInstallPlanWithPermissions(t *testing.T) {
24172420
delete(createdServiceAccountNames, sa.GetName())
24182421
if len(createdClusterRoleNames) == 0 && len(createdClusterRoleBindingNames) == 0 && len(createdServiceAccountNames) == 0 {
24192422
done <- struct{}{}
2423+
return
24202424
}
24212425
}
24222426
case <-time.After(pollDuration):
24232427
done <- struct{}{}
2428+
return
24242429
}
24252430
}
24262431
}()
24272432

24282433
t.Logf("Deleting CSV '%v' in namespace %v", stableCSVName, testNamespace)
24292434
require.NoError(t, crc.OperatorsV1alpha1().ClusterServiceVersions(testNamespace).DeleteCollection(&metav1.DeleteOptions{}, metav1.ListOptions{}))
2430-
<-done
2435+
select {
2436+
case <-done:
2437+
break
2438+
case err := <-errExit:
2439+
t.Fatal(err)
2440+
}
24312441

24322442
require.Emptyf(t, createdClusterRoleNames, "unexpected cluster role remain: %v", createdClusterRoleNames)
24332443
require.Emptyf(t, createdClusterRoleBindingNames, "unexpected cluster role binding remain: %v", createdClusterRoleBindingNames)

0 commit comments

Comments
 (0)