Skip to content

Commit

Permalink
Add wait for connection to be deleted
Browse files Browse the repository at this point in the history
Signed-off-by: Ayush Rangwala <[email protected]>
  • Loading branch information
aayushrangwala committed Jan 19, 2024
1 parent 85c1f9c commit d968556
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 13 deletions.
16 changes: 3 additions & 13 deletions test/e2e/interconnections/create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
33 changes: 33 additions & 0 deletions test/helper/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}
}
}

0 comments on commit d968556

Please sign in to comment.