From af1aa62b3f50b545666ce9a78665636075668729 Mon Sep 17 00:00:00 2001 From: Mateusz Filipowicz Date: Wed, 26 Feb 2025 09:31:32 +0100 Subject: [PATCH] feat: retry forgetting device when device is busy (#26) --- .github/workflows/acctest.yml | 19 ++++++++++++++----- internal/provider/device/resource_device.go | 12 ++++++++++-- 2 files changed, 24 insertions(+), 7 deletions(-) diff --git a/.github/workflows/acctest.yml b/.github/workflows/acctest.yml index e0bae1c..1db3d78 100644 --- a/.github/workflows/acctest.yml +++ b/.github/workflows/acctest.yml @@ -1,15 +1,23 @@ name: Acceptance Tests on: pull_request: - paths-ignore: - - "README.md" + paths: + - "internal/**" + - "scripts/**" + - "tools/**" + - "main.go" + - "docker-compose.yaml" push: branches: - "main" tags: - "v*" - paths-ignore: - - "README.md" + paths: + - "internal/**" + - "scripts/**" + - "tools/**" + - "main.go" + - "docker-compose.yaml" schedule: - cron: "0 13 * * *" jobs: @@ -55,4 +63,5 @@ jobs: timeout_minutes: 20 max_attempts: 3 command: make testacc TEST_TIMEOUT=1h UNIFI_STDOUT=true UNIFI_VERSION=${{ matrix.unifi_download_url && 'beta' || matrix.unifi_version }} UNIFI_DOWNLOAD_URL=${{ matrix.unifi_download_url }} - retry_on: "timeout" +# retry_on: "all" + retry_on: "timeout" \ No newline at end of file diff --git a/internal/provider/device/resource_device.go b/internal/provider/device/resource_device.go index ea37af7..be751c4 100644 --- a/internal/provider/device/resource_device.go +++ b/internal/provider/device/resource_device.go @@ -260,8 +260,16 @@ func resourceDeviceDelete(ctx context.Context, d *schema.ResourceData, meta inte if site == "" { site = c.Site } - - err := c.ForgetDevice(ctx, site, mac) + err := retry.RetryContext(ctx, 1*time.Minute, func() *retry.RetryError { + internalErr := c.ForgetDevice(ctx, site, mac) + if internalErr == nil { + return nil + } + if base.IsServerErrorContains(internalErr, "api.err.DeviceBusy") { + return retry.RetryableError(internalErr) + } + return retry.NonRetryableError(internalErr) + }) if err != nil { return diag.FromErr(err) }