From d9685564d6b31a9e26447ed4f720709262ad9160 Mon Sep 17 00:00:00 2001 From: Ayush Rangwala Date: Sat, 20 Jan 2024 01:52:12 +0530 Subject: [PATCH] Add wait for connection to be deleted Signed-off-by: Ayush Rangwala --- test/e2e/interconnections/create_test.go | 16 +++--------- test/helper/helper.go | 33 ++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 13 deletions(-) diff --git a/test/e2e/interconnections/create_test.go b/test/e2e/interconnections/create_test.go index 4a378f82..d7beb34a 100644 --- a/test/e2e/interconnections/create_test.go +++ b/test/e2e/interconnections/create_test.go @@ -43,19 +43,9 @@ func TestInterconnections_Create(t *testing.T) { out := helper.ExecuteAndCaptureOutput(t, root) - // Need to find the current user's default org - // as orgId is not populated in project. Its created using default org - user, _, err := apiClient.UsersApi. - FindCurrentUser(context.Background()). - Include([]string{"default_organization_id"}). - Execute() - if err != nil { - t.Fatal(err) - } - - conns, _, err := apiClient.InterconnectionsApi. - OrganizationListInterconnections(context.Background(), user.GetDefaultOrganizationId()). - Execute() + conns, err := apiClient.InterconnectionsApi. + ProjectListInterconnections(context.Background(), project.GetId()). + ExecuteWithPagination() if err != nil { t.Fatal(err) } diff --git a/test/helper/helper.go b/test/helper/helper.go index 3cfa4e48..b72cd49b 100644 --- a/test/helper/helper.go +++ b/test/helper/helper.go @@ -586,5 +586,38 @@ func CleanupInterconnection(t *testing.T, connectionId string) { t.Fatalf("Error when calling `InterconnectionsApi.DeleteInterconnection`` for %v: %v\n", connectionId, err) } + if err := waitForInterconnectionDeleted(apiClient, connectionId, 5*time.Minute); err != nil { + t.Fatal(err) + } + CleanupInterconnectionVC(t, connectionId) } + +func waitForInterconnectionDeleted(apiClient *metalv1.APIClient, connId string, timeout time.Duration) error { + ctx, cancelFunc := context.WithTimeout(context.Background(), timeout) + defer cancelFunc() + + ticker := time.NewTicker(2 * time.Second) + defer ticker.Stop() + + for { + select { + case <-ctx.Done(): + return errors.New("Timeout while waiting for connection to be deleted") + case <-ticker.C: + conn, _, err := apiClient.InterconnectionsApi.GetInterconnection(context.Background(), connId).Execute() + if err != nil { + if strings.Contains(err.Error(), "Not Found") { + return nil + } + return err + } + + if conn == nil { + return nil + } + + fmt.Printf("Connection not deleted. Current status: [%s]", conn.GetStatus()) + } + } +}