Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Canceling Terraform Command #301

Closed
wants to merge 3 commits into from
Closed

Commits on May 10, 2022

  1. Update TestContext_sleepTimeoutExpired to check for canceling within …

    …timeframe
    
    Add a timeout to the test to ensure that the terraform apply cancels within
    a reasonable time of the 5s timeout.
    
    Currently, this test is not canceling the terraform apply as expected. In the
    logs you can see that the test takes 1 min rather than ~5s:
    ```
        --- PASS: TestContext_sleepTimeoutExpired/sleep-0.12.31 (62.13s)
    ```
    
    ```
    === RUN   TestContext_sleepTimeoutExpired/sleep-0.12.31
        util_test.go:113: [INFO] running Terraform command: /var/folders/6y/gy9gggt14379c_k39vwb50lc0000gn/T/terraform_1378921380/terraform apply -no-color -auto-approve -input=false -lock=true -parallelism=10 -refresh=true
        util_test.go:103: CLI Output:
    	    // truncated ...
            time_sleep.sleep: Creating...
            time_sleep.sleep: Still creating... [10s elapsed]
            time_sleep.sleep: Still creating... [20s elapsed]
            time_sleep.sleep: Still creating... [30s elapsed]
            time_sleep.sleep: Still creating... [41s elapsed]
            time_sleep.sleep: Still creating... [51s elapsed]
            time_sleep.sleep: Creation complete after 1m0s [id=2022-05-06T17:40:20Z]
    
            Apply complete! Resources: 1 added, 0 changed, 0 destroyed.
    ```
    lornasong committed May 10, 2022
    Configuration menu
    Copy the full SHA
    400f9d7 View commit details
    Browse the repository at this point in the history
  2. Remove runTerraformCmd check for cmd.ProcessState

    Processes were not being killed because cmd.ProcessState was nil. With this
    change, processes will be able to make the request to Kill().
    
    Added a temporary log to printout cmd.ProcessState to demonstrate. Will be
    removed in next commit.
    
    Note: this will cause hanging `TestContext_sleepTimeoutExpired` due to a known
    Golang issue with killing a command when Stdout or Stderr are set to anything
    besides `nil` or `*os.File`. This is because the Kill does not notify the
    stdout/stderr subprocesses to stop. `cmd.Wait` (called by `cmd.Run`) waits
    indefinitely for those subprocesses to stop.
    lornasong committed May 10, 2022
    Configuration menu
    Copy the full SHA
    b4e272e View commit details
    Browse the repository at this point in the history
  3. Read logs from Stderr/out Pipe to avoid hanging

    `TestContext_sleepTimeoutExpired` can occasionally hang when killing a command
    that has Stdout or Stderr set to anything besides `nil` or `*os.File`.
    golang/go#23019
    
    Use workaround to read from StdoutPipe and StderrPipe rather than setting
    Stdout / Stderr
    lornasong committed May 10, 2022
    Configuration menu
    Copy the full SHA
    c3ccdc3 View commit details
    Browse the repository at this point in the history