Skip to content

Commit

Permalink
Merge pull request #151 from mihaelabalutoiu/add-timeout
Browse files Browse the repository at this point in the history
Log `orgPool/repoPool` details on timeout exceeded
  • Loading branch information
gabriel-samfira authored Aug 14, 2023
2 parents e2b617e + 475cc64 commit bf509ad
Showing 1 changed file with 34 additions and 12 deletions.
46 changes: 34 additions & 12 deletions test/integration/e2e.go
Original file line number Diff line number Diff line change
Expand Up @@ -502,8 +502,8 @@ func GracefulCleanup() {
DeleteInstance(repoInstanceName)
DeleteInstance(orgInstanceName)

WaitRepoPoolNoInstances()
WaitOrgPoolNoInstances()
WaitRepoPoolNoInstances(1 * time.Minute)
WaitOrgPoolNoInstances(1 * time.Minute)

DeleteRepoPool()
DeleteOrgPool()
Expand Down Expand Up @@ -715,7 +715,7 @@ func DisableRepoPool() {
log.Printf("repo pool %s disabled", repoPoolID)
}

func WaitRepoPoolNoInstances() {
func WaitRepoPoolNoInstances(timeout time.Duration) {
if repoID == "" {
log.Println(">>> No repo ID provided, skipping repo pool wait no instances")
return
Expand All @@ -725,15 +725,26 @@ func WaitRepoPoolNoInstances() {
return
}

for {
var timeWaited time.Duration = 0
var pool *params.Pool
var err error

for timeWaited < timeout {
log.Println(">>> Wait until repo pool has no instances")
pool, err := getRepoPool(cli, authToken, repoID, repoPoolID)
pool, err = getRepoPool(cli, authToken, repoID, repoPoolID)
handleError(err)
if len(pool.Instances) == 0 {
break
}
time.Sleep(5 * time.Second)
timeWaited += 5 * time.Second
}
printResponse(pool)
for _, instance := range pool.Instances {
printResponse(instance)
}

panic(fmt.Sprintf("Failed to wait for repo pool %s to have no instances", repoPoolID))
}

func WaitRepoInstance(timeout time.Duration) {
Expand All @@ -753,7 +764,7 @@ func WaitRepoInstance(timeout time.Duration) {
}
}
time.Sleep(5 * time.Second)
timeWaited += 5
timeWaited += 5 * time.Second
}
repo, err := getRepo(cli, authToken, repoID)
handleError(err)
Expand Down Expand Up @@ -917,7 +928,7 @@ func DisableOrgPool() {
log.Printf("org pool %s disabled", orgPoolID)
}

func WaitOrgPoolNoInstances() {
func WaitOrgPoolNoInstances(timeout time.Duration) {
if orgID == "" {
log.Println(">>> No org ID provided, skipping wait for org pool no instances")
return
Expand All @@ -927,15 +938,26 @@ func WaitOrgPoolNoInstances() {
return
}

for {
var timeWaited time.Duration = 0
var pool *params.Pool
var err error

for timeWaited < timeout {
log.Println(">>> Wait until org pool has no instances")
pool, err := getOrgPool(cli, authToken, orgID, orgPoolID)
pool, err = getOrgPool(cli, authToken, orgID, orgPoolID)
handleError(err)
if len(pool.Instances) == 0 {
break
}
time.Sleep(5 * time.Second)
timeWaited += 5 * time.Second
}
printResponse(pool)
for _, instance := range pool.Instances {
printResponse(instance)
}

panic(fmt.Sprintf("Failed to wait for org pool %s to have no instances", orgPoolID))
}

func WaitOrgInstance(timeout time.Duration) {
Expand All @@ -955,7 +977,7 @@ func WaitOrgInstance(timeout time.Duration) {
}
}
time.Sleep(5 * time.Second)
timeWaited += 5
timeWaited += 5 * time.Second
}
org, err := getOrg(cli, authToken, orgID)
handleError(err)
Expand Down Expand Up @@ -1193,10 +1215,10 @@ func main() {
///////////////
// instances //
///////////////
WaitRepoInstance(180)
WaitRepoInstance(2 * time.Minute)
ListRepoInstances()

WaitOrgInstance(180)
WaitOrgInstance(2 * time.Minute)
ListOrgInstances()

ListInstances()
Expand Down

0 comments on commit bf509ad

Please sign in to comment.