Skip to content

Commit

Permalink
add wait for gateway to delete
Browse files Browse the repository at this point in the history
Signed-off-by: Ayush Rangwala <[email protected]>
  • Loading branch information
aayushrangwala committed Jan 30, 2024
1 parent e5c2c1f commit 32d0f63
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions test/helper/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,10 @@ func CleanTestGateway(t *testing.T, gatewayId string) {
if err != nil && resp.StatusCode != http.StatusNotFound {
t.Fatalf("Error when calling `MetalGatewaysApi.DeleteMetalGateway`` for %v: %v\n", gatewayId, err)
}

if err := waitForVrfGatewayDeleted(TestApiClient, gatewayId, 5*time.Minute); err != nil {
t.Fatal(err)
}
}

func CreateTestInterConnection(t *testing.T, projectId, name string) *metalv1.Interconnection {
Expand Down Expand Up @@ -814,3 +818,32 @@ func CleanTestBgpDynamicNeighbor(t *testing.T, id string) {
t.Fatalf("Error when calling `VRFsApi.DeleteBgpDynamicNeighborById``for %v: %v\n", id, err)
}
}

func waitForVrfGatewayDeleted(apiClient *metalv1.APIClient, gatewayId 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 gateway to be deleted")
case <-ticker.C:
gway, resp, err := apiClient.MetalGatewaysApi.FindMetalGatewayById(context.Background(), gatewayId).Execute()
if err != nil {
if strings.Contains(err.Error(), "Not Found") || resp.StatusCode == http.StatusNotFound {
return nil
}
return err
}

if gway == nil {
return nil
}

fmt.Printf("Gateway not deleted. Current status: [%s]", gway.VrfMetalGateway.GetId())
}
}
}

0 comments on commit 32d0f63

Please sign in to comment.