From 7a8eefebe2f00608e3edea96588380f5f5719dad Mon Sep 17 00:00:00 2001 From: Nilesh Choudhary Date: Wed, 26 Feb 2025 11:12:32 +0000 Subject: [PATCH] Refactored the channel for test --- apps/confidential/confidential_test.go | 12 +++--------- apps/managedidentity/managedidentity_test.go | 2 +- 2 files changed, 4 insertions(+), 10 deletions(-) diff --git a/apps/confidential/confidential_test.go b/apps/confidential/confidential_test.go index 9c7910e7..cd1b3020 100644 --- a/apps/confidential/confidential_test.go +++ b/apps/confidential/confidential_test.go @@ -866,7 +866,7 @@ func TestRefreshInMultipleRequests(t *testing.T) { return fixedTime } var wg sync.WaitGroup - done := make(chan struct{}) + // done := make(chan struct{}) ch := make(chan error, 1) firstTenantChecker := false @@ -916,22 +916,16 @@ func TestRefreshInMultipleRequests(t *testing.T) { } }() } - // Wait for all goroutines in a separate goroutine - go func() { - wg.Wait() - close(done) - close(ch) - }() + wg.Wait() select { case err := <-ch: t.Fatal(err) default: } - // Wait for all goroutines to complete - <-done if !secondTenantChecker && !firstTenantChecker { t.Error("Error should be called at least once") } + close(ch) } func TestRefreshIn(t *testing.T) { diff --git a/apps/managedidentity/managedidentity_test.go b/apps/managedidentity/managedidentity_test.go index a236d827..3f3c6cad 100644 --- a/apps/managedidentity/managedidentity_test.go +++ b/apps/managedidentity/managedidentity_test.go @@ -1209,7 +1209,7 @@ func TestRefreshInMultipleRequests(t *testing.T) { if !requestChecker { t.Error("Error should be called at least once") } - + close(ch) } func TestShouldRefresh(t *testing.T) {