Skip to content

Commit

Permalink
Prevent deadlock in TestDynamicEnqueueRequest (elastic#4949)
Browse files Browse the repository at this point in the history
* Prevent deadlock in TestDynamicEnqueueRequest

* Randomize watched resource name

* Update pkg/controller/common/watches/handler_integration_test.go

Co-authored-by: Thibault Richard <thbkrkr@users.noreply.github.com>

Co-authored-by: Thibault Richard <thbkrkr@users.noreply.github.com>
  • Loading branch information
2 people authored and fantapsody committed Jan 3, 2023
1 parent 1a78616 commit bb3ef71
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions pkg/controller/common/watches/handler_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"github.com/stretchr/testify/require"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/util/rand"
"sigs.k8s.io/controller-runtime/pkg/controller"
"sigs.k8s.io/controller-runtime/pkg/manager"
"sigs.k8s.io/controller-runtime/pkg/reconcile"
Expand All @@ -39,7 +40,10 @@ func TestDynamicEnqueueRequest(t *testing.T) {
requests := make(chan reconcile.Request)
addToManager := func(mgr manager.Manager, params operator.Parameters) error {
reconcileFunc := reconcile.Func(func(ctx context.Context, req reconcile.Request) (reconcile.Result, error) {
requests <- req
select {
case requests <- req:
case <-ctx.Done():
}
return reconcile.Result{}, nil
})
ctrl, err := controller.New("test-reconciler", mgr, controller.Options{Reconciler: reconcileFunc})
Expand All @@ -54,7 +58,7 @@ func TestDynamicEnqueueRequest(t *testing.T) {
// Fixtures
watched := types.NamespacedName{
Namespace: "default",
Name: "watched1",
Name: "watched-" + rand.String(10),
}
testObj := &corev1.Secret{
ObjectMeta: k8s.ToObjectMeta(watched),
Expand Down

0 comments on commit bb3ef71

Please sign in to comment.