Skip to content

Commit

Permalink
feat: Increase default stack poll time to 60sec and expose as option (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
daniel-butler-irl authored Oct 15, 2024
1 parent 6de68c6 commit b31c896
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 8 deletions.
1 change: 1 addition & 0 deletions testhelper/test_options.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ type TestOptions struct {
// Use OpenTofu binary on the system path. This is used to enable the OpenTofu binary to be used for testing.
// If OpenTofu is not installed, the test will fail.
// If TerraformOptions is passed with the value for TerraformBinary set, this value will be ignored.
// Deprecated: This will be removed in future versions, please use TerraformBinary instead.
EnableOpenTofu bool
// Use this to specify the path to the Terraform binary to use for testing. This is exclusive with EnableOpenTofu.
TerraformBinary string
Expand Down
7 changes: 7 additions & 0 deletions testprojects/test_options.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ type TestProjectsOptions struct {
StackConfigurationPath string
StackCatalogJsonPath string

// StackPollTimeSeconds The number of seconds to wait between polling the stack status. 0 is not valid and will default to 60 seconds.
StackPollTimeSeconds int

// StackAutoSync If set to true, when deploying or undeploying a member, a sync with Schematics will be executed if the member has not updated before the StackAutoSyncInterval.
StackAutoSync bool
// StackAutoSyncInterval The number of minutes to wait before syncing with Schematics if state has not updated. Default is 20 minutes.
Expand Down Expand Up @@ -179,6 +182,10 @@ func TestProjectOptionsDefault(originalOptions *TestProjectsOptions) *TestProjec
if newOptions.StackAutoSyncInterval == 0 {
newOptions.StackAutoSyncInterval = 20
}

if newOptions.StackPollTimeSeconds == 0 {
newOptions.StackPollTimeSeconds = 60
}
// if newOptions.ProjectLocation == ""
// a random location will be selected at project creation time in CreateProjectFromConfig

Expand Down
15 changes: 7 additions & 8 deletions testprojects/tests.go
Original file line number Diff line number Diff line change
Expand Up @@ -276,10 +276,9 @@ func (options *TestProjectsOptions) TriggerDeployAndWait() (errorList []error) {
if allMembersDeployed {
deployComplete = true
} else if !failed {
// TODO: pause 30 second then check the member states one last time
// just incase there was a delay in updating the state
// Move members deployable check to its own function
time.Sleep(30 * time.Second)
time.Sleep(time.Duration(options.StackPollTimeSeconds) * time.Second)

var errorMessage strings.Builder
membersLatest, latestMemErr := options.CloudInfoService.GetStackMembers(options.currentStackConfig)
Expand Down Expand Up @@ -316,7 +315,7 @@ func (options *TestProjectsOptions) TriggerDeployAndWait() (errorList []error) {
}

options.Logger.ShortInfo(stackStatusMessage.String())
time.Sleep(time.Duration(30) * time.Second)
time.Sleep(time.Duration(options.StackPollTimeSeconds) * time.Second)
continue
}
}
Expand Down Expand Up @@ -357,7 +356,7 @@ func (options *TestProjectsOptions) TriggerDeployAndWait() (errorList []error) {

if stackDetails.StateCode == nil {
options.Logger.ShortInfo("Stack state code is nil, skipping this time")
time.Sleep(time.Duration(30) * time.Second)
time.Sleep(time.Duration(options.StackPollTimeSeconds) * time.Second)
continue
}

Expand All @@ -371,7 +370,7 @@ func (options *TestProjectsOptions) TriggerDeployAndWait() (errorList []error) {
options.Logger.ShortInfo(fmt.Sprintf("Stack Deployed Successfully, current state: %s and state code: %s", Statuses[*stackDetails.State], Statuses[*stackDetails.StateCode]))
} else {
options.Logger.ShortInfo(fmt.Sprintf("Stack is still deploying, current state: %s and state code: %s\n%s", Statuses[*stackDetails.State], Statuses[*stackDetails.StateCode], currentDeployStatus))
time.Sleep(time.Duration(30) * time.Second)
time.Sleep(time.Duration(options.StackPollTimeSeconds) * time.Second)
}
}

Expand Down Expand Up @@ -454,7 +453,7 @@ func (options *TestProjectsOptions) TriggerUnDeploy() (bool, []error) {
memberName = fmt.Sprintf("Unknown name, ID: %s", *member.ID)
}
options.Logger.ShortInfo(fmt.Sprintf("Member %s is still in state %s, waiting for all members to complete", memberName, Statuses[*member.State]))
time.Sleep(time.Duration(30) * time.Second)
time.Sleep(time.Duration(options.StackPollTimeSeconds) * time.Second)
}
}
}
Expand Down Expand Up @@ -585,7 +584,7 @@ func (options *TestProjectsOptions) TriggerUnDeployAndWait() (errorList []error)
options.Logger.ShortInfo(fmt.Sprintf("Stack is in state %s with state code %s, treating as complete undeploy", Statuses[*stackDetails.State], Statuses[stateCode]))
} else {
options.Logger.ShortInfo(fmt.Sprintf("Stack is still undeploying, current state: %s and state code: %s\n%s", Statuses[*stackDetails.State], Statuses[stateCode], currentUndeployStatus+strings.Join(memberStates, "\n")))
time.Sleep(30 * time.Second)
time.Sleep(time.Duration(options.StackPollTimeSeconds) * time.Second)
}
}
}
Expand Down Expand Up @@ -771,7 +770,7 @@ func (options *TestProjectsOptions) TestTearDown() {
break
}
options.Logger.ShortInfo("Pipeline actions are still running, waiting...")
time.Sleep(30 * time.Second)
time.Sleep(time.Duration(options.StackPollTimeSeconds) * time.Second)
}

// Check if timeout was reached
Expand Down

0 comments on commit b31c896

Please sign in to comment.