From 53a6b558ac11084999d3a023c4d37757f7e521b5 Mon Sep 17 00:00:00 2001 From: Shriram Sharma Date: Wed, 25 May 2022 08:29:04 -0700 Subject: [PATCH] changes made as per review comments Signed-off-by: Shriram Sharma --- admiral/pkg/controller/common/types_test.go | 24 +++++++++++++++------ 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/admiral/pkg/controller/common/types_test.go b/admiral/pkg/controller/common/types_test.go index a22599b7..9c6f785f 100644 --- a/admiral/pkg/controller/common/types_test.go +++ b/admiral/pkg/controller/common/types_test.go @@ -3,6 +3,7 @@ package common import ( "context" "strings" + "sync" "testing" "time" @@ -200,10 +201,14 @@ func TestSidecarEgressGet(t *testing.T) { ctx, cancel := context.WithDeadline(context.Background(), time.Now().Add(3*time.Second)) defer cancel() + var wg sync.WaitGroup + wg.Add(2) + // Producer go routine go func(ctx context.Context) { for { select { case <-ctx.Done(): + wg.Done() return default: egressMap.Put("pkey1", string(uuid.NewUUID()), "fqdn", map[string]string{"pkey2": "pkey2"}) @@ -211,15 +216,20 @@ func TestSidecarEgressGet(t *testing.T) { } }(ctx) - for { - select { - case <-ctx.Done(): - return - default: - assert.NotNil(t, egressMap.Get("pkey1")) + // Consumer go routine + go func(ctx context.Context) { + for { + select { + case <-ctx.Done(): + wg.Done() + return + default: + assert.NotNil(t, egressMap.Get("pkey1")) + } } - } + }(ctx) + wg.Wait() } func TestSidecarEgressRange(t *testing.T) {