Skip to content

Commit 792968f

Browse files
authored
[QT-644] Concurrently decode scenarios if possible (#116)
Fix incorrect logic that led to us always decoding scenarios using the serial method. Now we'll actually utilize all of our cores when decoding a scenario that has a matrix and our machine has more than 2 CPUs. * Fix concurrency path bug * Fix a data race on the eval context during decode * Fix our concurrent wait logic * Improve collection workers in concurrent decode * Bump version * Please new linters Signed-off-by: Ryan Cragun <[email protected]>
1 parent 63139d0 commit 792968f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+277
-238
lines changed

acceptance/acceptance_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ func requireEqualOperationResponses(t *testing.T, expected *pb.OperationResponse
245245
sortResponses(expectedResponses)
246246
sortResponses(gotResponses)
247247

248-
for i := range expected.Responses {
248+
for i := range expected.GetResponses() {
249249
got := gotResponses[i]
250250
expected := expectedResponses[i]
251251

acceptance/fmt_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,10 @@ func TestAcc_Cmd_Fmt(t *testing.T) {
4747
got := &pb.FormatResponse{}
4848
require.NoErrorf(t, protojson.Unmarshal(out, got), string(out))
4949
require.Len(t, got.GetResponses(), len(expected.GetResponses()))
50-
for i := range expected.Responses {
51-
got := got.Responses[i]
52-
expected := expected.Responses[i]
53-
require.Equal(t, expected.Path, got.Path)
54-
require.Equal(t, expected.Changed, got.Changed)
50+
for i := range expected.GetResponses() {
51+
got := got.GetResponses()[i]
52+
expected := expected.GetResponses()[i]
53+
require.Equal(t, expected.GetPath(), got.GetPath())
54+
require.Equal(t, expected.GetChanged(), got.GetChanged())
5555
}
5656
}

acceptance/scenario_check_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ func TestAcc_Cmd_Scenario_Check(t *testing.T) {
8282
},
8383
}
8484

85-
expected.Responses = append(expected.Responses, &pb.Operation_Response{
85+
expected.Responses = append(expected.GetResponses(), &pb.Operation_Response{
8686
Op: &pb.Ref_Operation{
8787
Scenario: scenarioRef,
8888
},
@@ -189,7 +189,7 @@ func TestAcc_Cmd_Scenario_Check_WithWarnings(t *testing.T) {
189189
}
190190
}
191191

192-
expected.Responses = append(expected.Responses, &pb.Operation_Response{
192+
expected.Responses = append(expected.GetResponses(), &pb.Operation_Response{
193193
Op: &pb.Ref_Operation{
194194
Scenario: scenarioRef,
195195
},

acceptance/scenario_e2e_aws_test.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import (
88
"path/filepath"
99
"testing"
1010

11-
"github.com/stretchr/testify/assert"
1211
"github.com/stretchr/testify/require"
1312

1413
"github.com/hashicorp/enos/proto/hashicorp/enos/v1/pb"
@@ -98,7 +97,7 @@ func TestAcc_Cmd_Scenario_E2E_AWS(t *testing.T) {
9897
// Lets try one more time to destroy resources that might have been
9998
// created
10099
out, err := enos.run(context.Background(), fmt.Sprintf("scenario destroy --chdir %s --out %s", path, outDir))
101-
assert.NoErrorf(t, err, string(out))
100+
require.NoErrorf(t, err, string(out))
102101
})
103102

104103
expected := &pb.OperationResponses{
@@ -149,7 +148,7 @@ func TestAcc_Cmd_Scenario_E2E_AWS(t *testing.T) {
149148
},
150149
}
151150

152-
expected.Responses = append(expected.Responses, res)
151+
expected.Responses = append(expected.GetResponses(), res)
153152
}
154153

155154
cmd := fmt.Sprintf("scenario run --chdir %s --out %s --format json", path, outDir)

acceptance/scenario_list_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,8 @@ func TestAcc_Cmd_Scenario_List(t *testing.T) {
121121
got := &pb.ListScenariosResponse{}
122122
require.NoError(t, protojson.Unmarshal(out, got))
123123
require.Len(t, got.GetScenarios(), len(test.out.GetScenarios()))
124-
for i := range test.out.Scenarios {
125-
require.Equal(t, test.out.Scenarios[i].String(), got.Scenarios[i].String())
124+
for i := range test.out.GetScenarios() {
125+
require.Equal(t, test.out.GetScenarios()[i].String(), got.GetScenarios()[i].String())
126126
}
127127
})
128128
}

acceptance/scenario_sample_list_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,8 @@ func TestAcc_Cmd_Scenario_Sample_List(t *testing.T) {
6161
got := &pb.ListSamplesResponse{}
6262
require.NoError(t, protojson.Unmarshal(out, got))
6363
require.Len(t, got.GetSamples(), len(test.out.GetSamples()))
64-
for i := range test.out.Samples {
65-
require.Equal(t, test.out.Samples[i].String(), got.Samples[i].String())
64+
for i := range test.out.GetSamples() {
65+
require.Equal(t, test.out.GetSamples()[i].String(), got.GetSamples()[i].String())
6666
}
6767
})
6868
}

internal/command/enos/cmd/fmt.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ func runFmtCmd(cmd *cobra.Command, args []string) error {
114114
return nil
115115
}
116116

117-
if fmtCfg.Recursive {
117+
if fmtCfg.GetRecursive() {
118118
err = filepath.Walk(path, readRawFiles)
119119
} else {
120120
err = readRawFiles(path, nil, nil)
@@ -148,7 +148,7 @@ func runFmtCmd(cmd *cobra.Command, args []string) error {
148148

149149
/// Scan STDIN for content if we've been told to use STDIN either implicitly
150150
// of explicitly.
151-
if (argP == "-" || argP == "") && len(req.Files) == 0 {
151+
if (argP == "-" || argP == "") && len(req.GetFiles()) == 0 {
152152
bytes, err := io.ReadAll(cmd.InOrStdin())
153153
if err != nil {
154154
res.Diagnostics = diagnostics.FromErr(err)

internal/command/enos/cmd/scenario_sample_observe.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,14 @@ func (t *sampleObserveFilter) Proto() *pb.Sample_Filter {
2929
if i == 0 {
3030
f.Subsets = []*pb.Sample_Subset_ID{}
3131
}
32-
f.Subsets = append(f.Subsets, &pb.Sample_Subset_ID{Name: t.OnlySubsets[i]})
32+
f.Subsets = append(f.GetSubsets(), &pb.Sample_Subset_ID{Name: t.OnlySubsets[i]})
3333
}
3434

3535
for i := range t.ExcludeSubsets {
3636
if i == 0 {
3737
f.ExcludeSubsets = []*pb.Sample_Subset_ID{}
3838
}
39-
f.ExcludeSubsets = append(f.ExcludeSubsets, &pb.Sample_Subset_ID{Name: t.ExcludeSubsets[i]})
39+
f.ExcludeSubsets = append(f.GetExcludeSubsets(), &pb.Sample_Subset_ID{Name: t.ExcludeSubsets[i]})
4040
}
4141

4242
return f

internal/diagnostics/diagnostics.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ func hasSeverity(sev pb.Diagnostic_Severity, diags ...[]*pb.Diagnostic) bool {
5959
}
6060

6161
for _, diag := range combined {
62-
if diag.Severity == sev {
62+
if diag.GetSeverity() == sev {
6363
return true
6464
}
6565
}
@@ -118,14 +118,14 @@ func FromTFJSON(in []tfjson.Diagnostic) []*pb.Diagnostic {
118118
Filename: din.Range.Filename,
119119
}
120120

121-
if d.Range.Start != nil {
121+
if d.GetRange().GetStart() != nil {
122122
d.Range.Start = &pb.Range_Pos{
123123
Line: int64(din.Range.Start.Line),
124124
Column: int64(din.Range.Start.Column),
125125
Byte: int64(din.Range.Start.Byte),
126126
}
127127
}
128-
if d.Range.End != nil {
128+
if d.GetRange().GetEnd() != nil {
129129
d.Range.End = &pb.Range_Pos{
130130
Line: int64(din.Range.End.Line),
131131
Column: int64(din.Range.End.Column),
@@ -150,7 +150,7 @@ func FromTFJSON(in []tfjson.Diagnostic) []*pb.Diagnostic {
150150
if i == 0 {
151151
d.Snippet.Values = []*pb.Diagnostic_ExpressionValue{}
152152
}
153-
d.Snippet.Values = append(d.Snippet.Values, &pb.Diagnostic_ExpressionValue{
153+
d.Snippet.Values = append(d.GetSnippet().GetValues(), &pb.Diagnostic_ExpressionValue{
154154
Traversal: expr.Traversal,
155155
Statement: expr.Statement,
156156
})
@@ -321,7 +321,7 @@ func FromHCL(files map[string]*hcl.File, diags hcl.Diagnostics) []*pb.Diagnostic
321321
}
322322
}
323323
sort.Slice(values, func(i, j int) bool {
324-
return values[i].Traversal < values[j].Traversal
324+
return values[i].GetTraversal() < values[j].GetTraversal()
325325
})
326326
pbDiag.Snippet.Values = values
327327
}
@@ -393,7 +393,7 @@ func String(diag *pb.Diagnostic, opts ...StringOpt) string {
393393
width = int(cfg.uiSettings.GetWidth())
394394
}
395395

396-
switch diag.Severity {
396+
switch diag.GetSeverity() {
397397
case pb.Diagnostic_SEVERITY_ERROR:
398398
buf.WriteString(cfg.color.Color("[bold][red]Error: [reset]"))
399399
leftRuleLine = cfg.color.Color("[red]│[reset] ")
@@ -415,22 +415,22 @@ func String(diag *pb.Diagnostic, opts ...StringOpt) string {
415415
// We don't wrap the summary, since we expect it to be terse, and since
416416
// this is where we put the text of a native Go error it may not always
417417
// be pure text that lends itself well to word-wrapping.
418-
fmt.Fprintf(&buf, cfg.color.Color("[bold]%s[reset]\n\n"), diag.Summary)
418+
fmt.Fprintf(&buf, cfg.color.Color("[bold]%s[reset]\n\n"), diag.GetSummary())
419419

420420
appendSourceSnippets(&buf, diag, cfg.color)
421421

422-
if diag.Detail != "" {
422+
if diag.GetDetail() != "" {
423423
paraWidth := width - leftRuleWidth - 1 // leave room for the left rule
424424
if paraWidth > 0 {
425-
lines := strings.Split(diag.Detail, "\n")
425+
lines := strings.Split(diag.GetDetail(), "\n")
426426
for _, line := range lines {
427427
if !strings.HasPrefix(line, " ") {
428428
line = wordwrap.WrapString(line, uint(paraWidth))
429429
}
430430
fmt.Fprintf(&buf, "%s\n", line)
431431
}
432432
} else {
433-
fmt.Fprintf(&buf, "%s\n", diag.Detail)
433+
fmt.Fprintf(&buf, "%s\n", diag.GetDetail())
434434
}
435435
}
436436

internal/flightplan/decoder.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,7 @@ func DecodeProto(
432432

433433
hclDiags := dec.Parse()
434434
if len(hclDiags) > 0 {
435-
res.Diagnostics = append(res.Diagnostics, diagnostics.FromHCL(dec.ParserFiles(), hclDiags)...)
435+
res.Diagnostics = append(res.GetDiagnostics(), diagnostics.FromHCL(dec.ParserFiles(), hclDiags)...)
436436
}
437437

438438
if diagnostics.HasErrors(res.GetDiagnostics()) {
@@ -441,7 +441,7 @@ func DecodeProto(
441441

442442
fp, hclDiags := dec.Decode(ctx)
443443
if len(hclDiags) > 0 {
444-
res.Diagnostics = append(res.Diagnostics, diagnostics.FromHCL(dec.ParserFiles(), hclDiags)...)
444+
res.Diagnostics = append(res.GetDiagnostics(), diagnostics.FromHCL(dec.ParserFiles(), hclDiags)...)
445445
}
446446

447447
return fp, res

0 commit comments

Comments
 (0)