Skip to content

Commit b41bd08

Browse files
Merge pull request #1096 from beautytiger/dev-191029-tfatal
fix: t.Fatal should be used in main goroutine
2 parents aee13fb + 9f6f5f2 commit b41bd08

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"
@@ -2376,16 +2377,14 @@ func TestCreateInstallPlanWithPermissions(t *testing.T) {
23762377
require.NoError(t, err)
23772378

23782379
done := make(chan struct{})
2379-
quit := make(chan struct{})
2380-
defer close(quit)
2380+
errExit := make(chan error)
23812381
go func() {
23822382
for {
23832383
select {
2384-
case <-quit:
2385-
return
23862384
case evt, ok := <-crWatcher.ResultChan():
23872385
if !ok {
2388-
t.Fatal("cr watch channel closed unexpectedly")
2386+
errExit <- errors.New("cr watch channel closed unexpectedly")
2387+
return
23892388
}
23902389
if evt.Type == watch.Deleted {
23912390
cr, ok := evt.Object.(*rbacv1.ClusterRole)
@@ -2395,11 +2394,13 @@ func TestCreateInstallPlanWithPermissions(t *testing.T) {
23952394
delete(createdClusterRoleNames, cr.GetName())
23962395
if len(createdClusterRoleNames) == 0 && len(createdClusterRoleBindingNames) == 0 && len(createdServiceAccountNames) == 0 {
23972396
done <- struct{}{}
2397+
return
23982398
}
23992399
}
24002400
case evt, ok := <-crbWatcher.ResultChan():
24012401
if !ok {
2402-
t.Fatal("crb watch channel closed unexpectedly")
2402+
errExit <- errors.New("crb watch channel closed unexpectedly")
2403+
return
24032404
}
24042405
if evt.Type == watch.Deleted {
24052406
crb, ok := evt.Object.(*rbacv1.ClusterRoleBinding)
@@ -2409,11 +2410,13 @@ func TestCreateInstallPlanWithPermissions(t *testing.T) {
24092410
delete(createdClusterRoleBindingNames, crb.GetName())
24102411
if len(createdClusterRoleNames) == 0 && len(createdClusterRoleBindingNames) == 0 && len(createdServiceAccountNames) == 0 {
24112412
done <- struct{}{}
2413+
return
24122414
}
24132415
}
24142416
case evt, ok := <-saWatcher.ResultChan():
24152417
if !ok {
2416-
t.Fatal("sa watch channel closed unexpectedly")
2418+
errExit <- errors.New("sa watch channel closed unexpectedly")
2419+
return
24172420
}
24182421
if evt.Type == watch.Deleted {
24192422
sa, ok := evt.Object.(*corev1.ServiceAccount)
@@ -2423,17 +2426,24 @@ func TestCreateInstallPlanWithPermissions(t *testing.T) {
24232426
delete(createdServiceAccountNames, sa.GetName())
24242427
if len(createdClusterRoleNames) == 0 && len(createdClusterRoleBindingNames) == 0 && len(createdServiceAccountNames) == 0 {
24252428
done <- struct{}{}
2429+
return
24262430
}
24272431
}
24282432
case <-time.After(pollDuration):
24292433
done <- struct{}{}
2434+
return
24302435
}
24312436
}
24322437
}()
24332438

24342439
t.Logf("Deleting CSV '%v' in namespace %v", stableCSVName, testNamespace)
24352440
require.NoError(t, crc.OperatorsV1alpha1().ClusterServiceVersions(testNamespace).DeleteCollection(&metav1.DeleteOptions{}, metav1.ListOptions{}))
2436-
<-done
2441+
select {
2442+
case <-done:
2443+
break
2444+
case err := <-errExit:
2445+
t.Fatal(err)
2446+
}
24372447

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

0 commit comments

Comments
 (0)