From afefb7464ee00494e93ff76ef5d554a9d46c91b0 Mon Sep 17 00:00:00 2001 From: Daniel Jaglowski Date: Fri, 2 Aug 2024 09:05:48 -0500 Subject: [PATCH] [chore] Add readonly matrix test. Remove invalid mutability assertions (#10632) The primary objective here was to add new test cases for the graph. However, I found that mutability assertions added in #8634 appear to be nondeterministic. Therefore, important test cases cannot be covered with them in place. This effectively removes the assertions about mutability for now. @dmitryax, I'm curious if you have better ideas here. I am thinking that perhaps it would be better to have an entirely separate set of test cases which are focused on mutability expectations. Co-authored-by: Pablo Baeyens --- service/internal/graph/graph_test.go | 77 ++++++++++++++++++++++------ 1 file changed, 61 insertions(+), 16 deletions(-) diff --git a/service/internal/graph/graph_test.go b/service/internal/graph/graph_test.go index e20b85b2961..fcc2ea6cf89 100644 --- a/service/internal/graph/graph_test.go +++ b/service/internal/graph/graph_test.go @@ -569,7 +569,43 @@ func TestConnectorPipelinesGraph(t *testing.T) { expectedPerExporter: 1, }, { - name: "pipelines_conn_matrix.yaml", + name: "pipelines_conn_matrix_immutable.yaml", + pipelineConfigs: pipelines.Config{ + component.MustNewIDWithName("traces", "in"): { + Receivers: []component.ID{component.MustNewID("examplereceiver")}, + Processors: []component.ID{component.MustNewID("exampleprocessor")}, + Exporters: []component.ID{component.MustNewID("exampleconnector")}, + }, + component.MustNewIDWithName("metrics", "in"): { + Receivers: []component.ID{component.MustNewID("examplereceiver")}, + Processors: []component.ID{component.MustNewID("exampleprocessor")}, + Exporters: []component.ID{component.MustNewID("exampleconnector")}, + }, + component.MustNewIDWithName("logs", "in"): { + Receivers: []component.ID{component.MustNewID("examplereceiver")}, + Processors: []component.ID{component.MustNewID("exampleprocessor")}, + Exporters: []component.ID{component.MustNewID("exampleconnector")}, + }, + component.MustNewIDWithName("traces", "out"): { + Receivers: []component.ID{component.MustNewID("exampleconnector")}, + Processors: []component.ID{component.MustNewID("exampleprocessor")}, + Exporters: []component.ID{component.MustNewID("exampleexporter")}, + }, + component.MustNewIDWithName("metrics", "out"): { + Receivers: []component.ID{component.MustNewID("exampleconnector")}, + Processors: []component.ID{component.MustNewID("exampleprocessor")}, + Exporters: []component.ID{component.MustNewID("exampleexporter")}, + }, + component.MustNewIDWithName("logs", "out"): { + Receivers: []component.ID{component.MustNewID("exampleconnector")}, + Processors: []component.ID{component.MustNewID("exampleprocessor")}, + Exporters: []component.ID{component.MustNewID("exampleexporter")}, + }, + }, + expectedPerExporter: 3, + }, + { + name: "pipelines_conn_matrix_mutable.yaml", pipelineConfigs: pipelines.Config{ component.MustNewIDWithName("traces", "in"): { Receivers: []component.ID{component.MustNewID("examplereceiver")}, @@ -949,34 +985,43 @@ func TestConnectorPipelinesGraph(t *testing.T) { for _, e := range allExporters[component.DataTypeTraces] { tracesExporter := e.(*testcomponents.ExampleExporter) assert.Equal(t, test.expectedPerExporter, len(tracesExporter.Traces)) - expected := testdata.GenerateTraces(1) - if len(allExporters[component.DataTypeTraces]) > 1 { - expected.MarkReadOnly() // multiple read-only exporters should get read-only pdata - } + expectedMutable := testdata.GenerateTraces(1) + expectedReadOnly := testdata.GenerateTraces(1) + expectedReadOnly.MarkReadOnly() for i := 0; i < test.expectedPerExporter; i++ { - assert.EqualValues(t, expected, tracesExporter.Traces[i]) + if tracesExporter.Traces[i].IsReadOnly() { + assert.EqualValues(t, expectedReadOnly, tracesExporter.Traces[i]) + } else { + assert.EqualValues(t, expectedMutable, tracesExporter.Traces[i]) + } } } for _, e := range allExporters[component.DataTypeMetrics] { metricsExporter := e.(*testcomponents.ExampleExporter) assert.Equal(t, test.expectedPerExporter, len(metricsExporter.Metrics)) - expected := testdata.GenerateMetrics(1) - if len(allExporters[component.DataTypeMetrics]) > 1 { - expected.MarkReadOnly() // multiple read-only exporters should get read-only pdata - } + expectedMutable := testdata.GenerateMetrics(1) + expectedReadOnly := testdata.GenerateMetrics(1) + expectedReadOnly.MarkReadOnly() for i := 0; i < test.expectedPerExporter; i++ { - assert.EqualValues(t, expected, metricsExporter.Metrics[i]) + if metricsExporter.Metrics[i].IsReadOnly() { + assert.EqualValues(t, expectedReadOnly, metricsExporter.Metrics[i]) + } else { + assert.EqualValues(t, expectedMutable, metricsExporter.Metrics[i]) + } } } for _, e := range allExporters[component.DataTypeLogs] { logsExporter := e.(*testcomponents.ExampleExporter) assert.Equal(t, test.expectedPerExporter, len(logsExporter.Logs)) - expected := testdata.GenerateLogs(1) - if len(allExporters[component.DataTypeLogs]) > 1 { - expected.MarkReadOnly() // multiple read-only exporters should get read-only pdata - } + expectedMutable := testdata.GenerateLogs(1) + expectedReadOnly := testdata.GenerateLogs(1) + expectedReadOnly.MarkReadOnly() for i := 0; i < test.expectedPerExporter; i++ { - assert.EqualValues(t, expected, logsExporter.Logs[i]) + if logsExporter.Logs[i].IsReadOnly() { + assert.EqualValues(t, expectedReadOnly, logsExporter.Logs[i]) + } else { + assert.EqualValues(t, expectedMutable, logsExporter.Logs[i]) + } } } })