Skip to content

Commit

Permalink
Merge #11631
Browse files Browse the repository at this point in the history
11631: fix negative stopwatch times r=dixler a=dixler

<!--- 
Thanks so much for your contribution! If this is your first time contributing, please ensure that you have read the [CONTRIBUTING](https://github.com/pulumi/pulumi/blob/master/CONTRIBUTING.md) documentation.
-->

# Description

<!--- Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context. -->

Fixes #11188 

This PR fixes negative times showing up on the update display. This was caused by operations that did not emit a resource output event using the end time for the previous operation if it existed. This change clears the old end time if it exists.

~TODO~
- [x] write test
- [x] find and implement fix
- [x] write changelog entry

## Checklist

<!--- Please provide details if the checkbox below is to be left unchecked. -->
- [x] I have added tests that prove my fix is effective or that my feature works
<!--- 
User-facing changes require a CHANGELOG entry.
-->
- [x] I have run `make changelog` and committed the `changelog/pending/<file>` documenting my change
<!--
If the change(s) in this PR is a modification of an existing call to the Pulumi Service,
then the service should honor older versions of the CLI where this change would not exist.
You must then bump the API version in /pkg/backend/httpstate/client/api.go, as well as add
it to the service.
-->
- [ ] Yes, there are changes in this PR that warrants bumping the Pulumi Service API version
  <!-- `@Pulumi` employees: If yes, you must submit corresponding changes in the service repo. -->


Co-authored-by: Kyle Dixler <kyle@pulumi.com>
  • Loading branch information
bors[bot] and Kyle Dixler committed Dec 13, 2022
2 parents da23804 + a66ccea commit feac805
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 0 deletions.
@@ -0,0 +1,4 @@
changes:
- type: fix
scope: cli/display
description: Fixes negative durations on update display.
3 changes: 3 additions & 0 deletions pkg/backend/display/progress.go
Expand Up @@ -862,6 +862,9 @@ func (display *ProgressDisplay) processNormalEvent(event engine.Event) {
// and time elapsed.
display.opStopwatch.start[step.URN] = time.Now()

// Clear out potential event end timings for prior operations on the same resource.
delete(display.opStopwatch.end, step.URN)

row.SetStep(step)
} else if event.Type == engine.ResourceOutputsEvent {
isRefresh := display.getStepOp(row.Step()) == deploy.OpRefresh
Expand Down
28 changes: 28 additions & 0 deletions tests/integration/integration_nodejs_test.go
Expand Up @@ -1166,6 +1166,34 @@ func TestESMTSCompiled(t *testing.T) {
})
}

// Test that the resource stopwatch doesn't contain a negative time.
func TestNoNegativeTimingsOnRefresh(t *testing.T) {
if runtime.GOOS == WindowsOS {
t.Skip("Skip on windows because we lack yarn")
}
t.Parallel()

dir := filepath.Join("empty", "nodejs")
e := ptesting.NewEnvironment(t)
defer func() {
if !t.Failed() {
e.DeleteEnvironment()
}
}()
e.ImportDirectory(dir)

e.RunCommand("yarn", "link", "@pulumi/pulumi")
e.RunCommand("yarn", "install")
e.RunCommand("pulumi", "login", "--cloud-url", e.LocalURL())
e.RunCommand("pulumi", "stack", "init", "negative-timings")
e.RunCommand("pulumi", "stack", "select", "negative-timings")
e.RunCommand("pulumi", "up", "--yes")
stdout, _ := e.RunCommand("pulumi", "destroy", "--skip-preview", "--refresh=true")
// Assert there are no negative times in the output.
assert.NotContainsf(t, stdout, " (-",
"`pulumi destroy --skip-preview --refresh=true` contains a negative time")
}

// Test that the about command works as expected. Because about parses the
// results of each runtime independently, we have an integration test in each
// language.
Expand Down

0 comments on commit feac805

Please sign in to comment.