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

Add display to the engine tests #16050

Merged
merged 8 commits into from
May 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
The diff you're trying to view is too large. We only load the first 3000 changed files.
2 changes: 1 addition & 1 deletion pkg/backend/display/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ type Options struct {

// testing-only options
term terminal.Terminal
deterministicOutput bool
DeterministicOutput bool
}

func (opts Options) WithIsInteractive(isInteractive bool) Options {
Expand Down
50 changes: 47 additions & 3 deletions pkg/backend/display/progress.go
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ func ShowProgressEvents(op string, action apitype.UpdateKind, stack tokens.Stack
renderer.initializeDisplay(display)

ticker := time.NewTicker(1 * time.Second)
if opts.deterministicOutput {
if opts.DeterministicOutput {
ticker.Stop()
}
display.processEvents(ticker, events)
Expand Down Expand Up @@ -472,6 +472,25 @@ func (display *ProgressDisplay) processEndSteps() {
// Now print out all those rows that were in progress. They will now be 'done'
// since the display was marked 'done'.
if !display.isTerminal {
if display.opts.DeterministicOutput {
sort.Slice(inProgressRows, func(i, j int) bool {
if inProgressRows[i].Step().Op == "same" && inProgressRows[i].Step().URN == "" {
// This is the root stack event. Always sort it last
return false
}
if inProgressRows[j].Step().Op == "same" && inProgressRows[j].Step().URN == "" {
// This is the root stack event. Always sort it last
return true
}
if inProgressRows[i].Step().Res == nil {
return false
}
if inProgressRows[j].Step().Res == nil {
return true
}
return inProgressRows[i].Step().Res.URN < inProgressRows[j].Step().Res.URN
})
}
for _, v := range inProgressRows {
display.renderer.rowUpdated(v)
}
Expand Down Expand Up @@ -510,7 +529,32 @@ func (display *ProgressDisplay) printDiagnostics() bool {
// Since we display diagnostic information eagerly, we need to keep track of the first
// time we wrote some output so we don't inadvertently print the header twice.
wroteDiagnosticHeader := false

eventRows := make([]ResourceRow, 0, len(display.eventUrnToResourceRow))
for _, row := range display.eventUrnToResourceRow {
eventRows = append(eventRows, row)
}
if display.opts.DeterministicOutput {
sort.Slice(eventRows, func(i, j int) bool {
if eventRows[i].Step().Op == "same" && eventRows[i].Step().URN == "" {
// This is the root stack event. Always sort it last
return false
}
if eventRows[j].Step().Op == "same" && eventRows[j].Step().URN == "" {
// This is the root stack event. Always sort it last
return true
}
if eventRows[i].Step().Res == nil {
return false
}
if eventRows[j].Step().Res == nil {
return true
}
return eventRows[i].Step().Res.URN < eventRows[j].Step().Res.URN
})
}

for _, row := range eventRows {
// The header for the diagnogistics grouped by resource, e.g. "aws:apigateway:RestApi (accountsApi):"
wroteResourceHeader := false

Expand Down Expand Up @@ -1186,7 +1230,7 @@ func (display *ProgressDisplay) getStepDoneDescription(step engine.StepEventMeta
return ""
}
}
if op == deploy.OpSame || display.opts.deterministicOutput || display.opts.SuppressTimings {
if op == deploy.OpSame || display.opts.DeterministicOutput || display.opts.SuppressTimings {
return opText
}

Expand Down Expand Up @@ -1365,7 +1409,7 @@ func (display *ProgressDisplay) getStepInProgressDescription(step engine.StepEve
return ""
}

if op == deploy.OpSame || display.opts.deterministicOutput || display.opts.SuppressTimings {
if op == deploy.OpSame || display.opts.DeterministicOutput || display.opts.SuppressTimings {
return opText
}

Expand Down
4 changes: 2 additions & 2 deletions pkg/backend/display/progress_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func testProgressEvents(t *testing.T, path string, accept, interactive bool, wid
Stdout: &stdout,
Stderr: &stderr,
term: terminal.NewMockTerminal(&stdout, width, height, true),
deterministicOutput: true,
DeterministicOutput: true,
}, false)

for _, e := range events {
Expand Down Expand Up @@ -271,7 +271,7 @@ func TestProgressPolicyPacks(t *testing.T) {
Stdout: &stdout,
Stderr: &stderr,
term: terminal.NewMockTerminal(&stdout, 80, 24, true),
deterministicOutput: true,
DeterministicOutput: true,
}, false)

// Send policy pack event to the channel
Expand Down
4 changes: 2 additions & 2 deletions pkg/backend/display/tree.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func newInteractiveRenderer(term terminal.Terminal, permalink string, opts Optio
keys: make(chan string),
closed: make(chan bool),
}
if opts.deterministicOutput {
if opts.DeterministicOutput {
r.ticker.Stop()
}
go r.handleEvents()
Expand Down Expand Up @@ -189,7 +189,7 @@ func (r *treeRenderer) markDirty() {
}

r.dirty = true
if r.opts.deterministicOutput {
if r.opts.DeterministicOutput {
r.frame(true, false)
}
}
Expand Down
4 changes: 3 additions & 1 deletion pkg/backend/httpstate/snapshot_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,9 @@ func generateSnapshots(t testing.TB, r *rand.Rand, resourceCount, resourcePayloa

var journalEntries engine.JournalEntries
p := &lifecycletest.TestPlan{
Options: lifecycletest.TestUpdateOptions{HostF: hostF},
// This test generates big amounts of data so the event streams that would need to be
// checked in get too big. Skip them instead.
Options: lifecycletest.TestUpdateOptions{T: t, HostF: hostF, SkipDisplayTests: true},
Steps: []lifecycletest.TestStep{
{
Op: engine.Update,
Expand Down