Skip to content

Commit

Permalink
feat: improve test speed
Browse files Browse the repository at this point in the history
- Don't use postgres charms that require storage when running offer tests.
- Be more aggressive in destroying offers, wait 30s instead of 5m for offer connections to disappear before adding force flag.
  • Loading branch information
kian99 committed Aug 29, 2024
1 parent 8d5ec5f commit daa7397
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 11 deletions.
8 changes: 4 additions & 4 deletions internal/juju/offers.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,17 +197,17 @@ func (c offersClient) DestroyOffer(input *DestroyOfferInput) error {
}

forceDestroy := false
//This code loops until it detects 0 connections in the offer or 3 minutes elapses
//This code loops until it detects 0 connections in the offer or 30s elapses
if len(offer.Connections) > 0 {
end := time.Now().Add(5 * time.Minute)
end := time.Now().Add(30 * time.Second)
for ok := true; ok; ok = len(offer.Connections) > 0 {
//if we have been failing to destroy offer for 5 minutes then force destroy
//if we have been failing to destroy offer for 30s then force destroy
//TODO: investigate cleaner solution (acceptance tests fail even if timeout set to 20m)
if time.Now().After(end) {
forceDestroy = true
break
}
time.Sleep(10 * time.Second)
time.Sleep(5 * time.Second)
offer, err = client.ApplicationOffer(input.OfferURL)
if err != nil {
return err
Expand Down
4 changes: 2 additions & 2 deletions internal/provider/data_source_offer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,15 +73,15 @@ resource "juju_application" "this" {
name = "this"
charm {
name = "postgresql"
name = "juju-qa-dummy-source"
%s
}
}
resource "juju_offer" "this" {
model = juju_model.this.name
application_name = juju_application.this.name
endpoint = "db"
endpoint = "sink"
name = %q
}
Expand Down
11 changes: 6 additions & 5 deletions internal/provider/resource_offer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func TestAcc_ResourceOffer(t *testing.T) {
resource.TestCheckResourceAttr("juju_integration.int", "model", destModelName),

resource.TestCheckTypeSetElemNestedAttrs("juju_integration.int", "application.*",
map[string]string{"name": "apptwo", "endpoint": "db", "offer_url": ""}),
map[string]string{"name": "apptwo", "endpoint": "source", "offer_url": ""}),

resource.TestCheckTypeSetElemNestedAttrs("juju_integration.int", "application.*",
map[string]string{"name": "", "endpoint": "", "offer_url": fmt.Sprintf("%v/%v.%v", "admin",
Expand Down Expand Up @@ -65,15 +65,15 @@ resource "juju_application" "appone" {
name = "appone"
charm {
name = "postgresql"
name = "juju-qa-dummy-source"
base = "[email protected]"
}
}
resource "juju_offer" "offerone" {
model = juju_model.modelone.name
application_name = juju_application.appone.name
endpoint = "db"
endpoint = "sink"
}
resource "juju_model" "modeldest" {
Expand All @@ -85,8 +85,8 @@ resource "juju_application" "apptwo" {
name = "apptwo"
charm {
name = "hello-juju"
base = "ubuntu@20.04"
name = "juju-qa-dummy-sink"
base = "ubuntu@22.04"
}
}
Expand All @@ -95,6 +95,7 @@ resource "juju_integration" "int" {
application {
name = juju_application.apptwo.name
endpoint = "source"
}
application {
Expand Down

0 comments on commit daa7397

Please sign in to comment.