Skip to content

Commit c28275f

Browse files
authored
Merge pull request #320 from oboukili/319-fixes-flaky-group-test
Handle async groups API deletion ack response in tests
2 parents a06b19d + ea165bf commit c28275f

File tree

2 files changed

+22
-4
lines changed

2 files changed

+22
-4
lines changed

gitlab/resource_gitlab_group.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ func resourceGitlabGroupDelete(d *schema.ResourceData, meta interface{}) error {
208208
Refresh: func() (interface{}, string, error) {
209209
out, response, err := client.Groups.GetGroup(d.Id())
210210
if err != nil {
211-
if response.StatusCode == 404 {
211+
if response != nil && response.StatusCode == 404 {
212212
return out, "Deleted", nil
213213
}
214214
log.Printf("[ERROR] Received error: %#v", err)

gitlab/resource_gitlab_group_test.go

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,13 @@ package gitlab
22

33
import (
44
"fmt"
5-
"testing"
6-
75
"github.com/hashicorp/terraform-plugin-sdk/helper/acctest"
86
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
97
"github.com/hashicorp/terraform-plugin-sdk/terraform"
108
"github.com/xanzy/go-gitlab"
9+
"net/http"
10+
"testing"
11+
"time"
1112
)
1213

1314
func TestAccGitlabGroup_basic(t *testing.T) {
@@ -183,7 +184,24 @@ func testAccCheckGitlabGroupDisappears(group *gitlab.Group) resource.TestCheckFu
183184
conn := testAccProvider.Meta().(*gitlab.Client)
184185

185186
_, err := conn.Groups.DeleteGroup(group.ID)
186-
return err
187+
if err != nil {
188+
return err
189+
}
190+
// Fixes groups API async deletion issue
191+
// https://github.com/terraform-providers/terraform-provider-gitlab/issues/319
192+
for start := time.Now(); time.Since(start) < 15*time.Second; {
193+
g, resp, err := conn.Groups.GetGroup(group.ID)
194+
if resp != nil && resp.StatusCode == http.StatusNotFound {
195+
return nil
196+
}
197+
if g != nil && g.MarkedForDeletionOn != nil {
198+
return nil
199+
}
200+
if err != nil {
201+
return err
202+
}
203+
}
204+
return fmt.Errorf("waited for more than 15 seconds for group to be asynchronously deleted")
187205
}
188206
}
189207

0 commit comments

Comments
 (0)