Skip to content

Commit 34bbf7e

Browse files
authored
Merge pull request #772 from SimoneDutto/fix-flaky-TestAcc_CustomResourcesAddedToPlanMicrok8s
#772 There is a Juju timing issue by which if the app is created and after it the resource is updated sometimes the update is not applied. This is most likely an issue that is not affecting any user because it is just a scenario presented in our tests.The fix is just to sleep between step 1 and step 2. For future reference: - this seems to be a very specific issue with the way we update resources, when the test is failing and you check the model you see something like this: ``` runner@pkrvmxyh4eaekms:~/work/terraform-provider-juju/terraform-provider-juju$ juju resources test-app Resource Supplied by Revision coredns-image store 65 [Updates Available] Resource Revision coredns-image 0 ``` I think the reason is that the application is created and the resource update is queue but not applied because the application has not reached a specific state where you can actually update the resource. - i couldn't reproduce the issue locally - we can't wait for the resource to be populated in `Create` because we don't have the resource specified all of the time in our plan. - we can't wait for the application to reach a non `waiting` status, because it takes a long time for most charms, and it will just create longer tests. # QA i couldn't reproduce the issue even with this very specific plan. ```terraform terraform { required_providers { juju = { source = "juju/juju" } } } variable "custom_resource" { type = bool default = false } provider "juju" {} resource "juju_model" "development" { name = "dev2" } resource "juju_application" "this" { name = "this" model = juju_model.development.name charm { name = "coredns" channel = "latest/stable" } resources = var.custom_resource == true ? { "coredns-image" = "docker.io/coredns/coredns:latest" } : null } ``` `terraform apply -var custom_resource=false -auto-approve && terraform apply -var custom_resource=true -auto-approve`
2 parents 038a85f + 17826f9 commit 34bbf7e

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

internal/provider/resource_application_test.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -480,6 +480,18 @@ func TestAcc_CustomResourcesAddedToPlanMicrok8s(t *testing.T) {
480480
resource.TestCheckNoResourceAttr("juju_application.this", "resources"),
481481
),
482482
},
483+
// In the next step we verify the plan has no changes. First waiting 30 seconds
484+
// to avoid a race condition in Juju where updating the resource revision too
485+
// quickly means that the change doesn't take immediate effect.
486+
{
487+
Config: testAccResourceApplicationWithoutCustomResources(modelName, "latest/stable"),
488+
Check: resource.ComposeTestCheckFunc(
489+
resource.TestCheckNoResourceAttr("juju_application.this", "resources"),
490+
),
491+
PreConfig: func() {
492+
time.Sleep(30 * time.Second)
493+
},
494+
},
483495
{
484496
// Add a custom resource
485497
Config: testAccResourceApplicationWithCustomResources(modelName, "latest/stable", "coredns-image", "ghcr.io/canonical/test:6a873fb35b0170dfe49ed27ba8ee6feb8e475131"),

0 commit comments

Comments
 (0)