-
Notifications
You must be signed in to change notification settings - Fork 55
/
PostgresSimpleQueryAsyncTests.cs
177 lines (148 loc) · 8.29 KB
/
PostgresSimpleQueryAsyncTests.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
// Copyright 2020 New Relic, Inc. All rights reserved.
// SPDX-License-Identifier: Apache-2.0
using System;
using System.Collections.Generic;
using System.Linq;
using MultiFunctionApplicationHelpers;
using NewRelic.Agent.IntegrationTestHelpers;
using NewRelic.Agent.IntegrationTestHelpers.Models;
using NewRelic.Agent.IntegrationTests.Shared;
using NewRelic.Testing.Assertions;
using Xunit;
using Xunit.Abstractions;
namespace NewRelic.Agent.UnboundedIntegrationTests.Postgres
{
public abstract class PostgresSqlSimpleQueryAsyncTestsBase<TFixture> : NewRelicIntegrationTest<TFixture> where TFixture : ConsoleDynamicMethodFixture
{
private readonly ConsoleDynamicMethodFixture _fixture;
public PostgresSqlSimpleQueryAsyncTestsBase(TFixture fixture, ITestOutputHelper output) : base(fixture)
{
_fixture = fixture;
_fixture.TestLogger = output;
_fixture.AddCommand($"PostgresSqlExerciser SimpleQueryAsync");
_fixture.AddActions
(
setupConfiguration: () =>
{
var configPath = fixture.DestinationNewRelicConfigFilePath;
var configModifier = new NewRelicConfigModifier(configPath);
configModifier.ConfigureFasterMetricsHarvestCycle(15);
configModifier.ConfigureFasterTransactionTracesHarvestCycle(15);
configModifier.ConfigureFasterSqlTracesHarvestCycle(15);
configModifier.ForceTransactionTraces()
.SetLogLevel("finest");
CommonUtils.ModifyOrCreateXmlAttributeInNewRelicConfig(configPath, new[] { "configuration", "transactionTracer" }, "explainThreshold", "1");
},
exerciseApplication: () =>
{
// Confirm transaction transform has completed before moving on to host application shutdown, and final sendDataOnExit harvest
_fixture.AgentLog.WaitForLogLine(AgentLogBase.TransactionTransformCompletedLogLineRegex, TimeSpan.FromMinutes(2)); // must be 2 minutes since this can take a while.
_fixture.AgentLog.WaitForLogLine(AgentLogBase.SqlTraceDataLogLineRegex, TimeSpan.FromMinutes(1));
}
);
_fixture.Initialize();
}
[Fact]
public void Test()
{
var expectedTransactionName = "OtherTransaction/Custom/MultiFunctionApplicationHelpers.NetStandardLibraries.PostgresSql.PostgresSqlExerciser/SimpleQueryAsync";
var expectedDatastoreCallCount = 1;
var expectedMetrics = new List<Assertions.ExpectedMetric>
{
new Assertions.ExpectedMetric { metricName = @"Datastore/all", callCount = expectedDatastoreCallCount },
new Assertions.ExpectedMetric { metricName = @"Datastore/allOther", callCount = 1 },
new Assertions.ExpectedMetric { metricName = @"Datastore/Postgres/all", callCount = expectedDatastoreCallCount },
new Assertions.ExpectedMetric { metricName = @"Datastore/Postgres/allOther", callCount = 1 },
new Assertions.ExpectedMetric { metricName = @"DotNet/Npgsql.NpgsqlConnection/OpenAsync", callCount = 1},
new Assertions.ExpectedMetric { metricName = $@"Datastore/instance/Postgres/{CommonUtils.NormalizeHostname(PostgresConfiguration.PostgresServer)}/{PostgresConfiguration.PostgresPort}", callCount = expectedDatastoreCallCount},
new Assertions.ExpectedMetric { metricName = @"Datastore/operation/Postgres/select", callCount = 1 },
new Assertions.ExpectedMetric { metricName = @"Datastore/statement/Postgres/teammembers/select", callCount = 1 },
new Assertions.ExpectedMetric { metricName = @"Datastore/statement/Postgres/teammembers/select", callCount = 1, metricScope = expectedTransactionName},
};
var unexpectedMetrics = new List<Assertions.ExpectedMetric>
{
// The datastore operation happened outside a web transaction so there should be no allWeb metrics
new Assertions.ExpectedMetric { metricName = @"Datastore/allWeb" },
new Assertions.ExpectedMetric { metricName = @"Datastore/Postgres/allWeb" },
// The operation metric should not be scoped because the statement metric is scoped instead
new Assertions.ExpectedMetric { metricName = @"Datastore/operation/Postgres/select", callCount = 1, metricScope = expectedTransactionName }
};
var expectedTransactionTraceSegments = new List<string>
{
"Datastore/statement/Postgres/teammembers/select"
};
var expectedTransactionEventIntrinsicAttributes = new List<string>
{
"databaseDuration"
};
var expectedSqlTraces = new List<Assertions.ExpectedSqlTrace>
{
new Assertions.ExpectedSqlTrace
{
TransactionName = expectedTransactionName,
Sql = "SELECT * FROM newrelic.teammembers WHERE firstname = ?",
DatastoreMetricName = "Datastore/statement/Postgres/teammembers/select",
HasExplainPlan = false
}
};
var metrics = _fixture.AgentLog.GetMetrics().ToList();
var transactionSample = _fixture.AgentLog.TryGetTransactionSample(expectedTransactionName);
var transactionEvent = _fixture.AgentLog.TryGetTransactionEvent(expectedTransactionName);
var sqlTraces = _fixture.AgentLog.GetSqlTraces().ToList();
NrAssert.Multiple(
() => Assert.NotNull(transactionSample),
() => Assert.NotNull(transactionEvent)
);
NrAssert.Multiple
(
() => Assertions.MetricsExist(expectedMetrics, metrics),
() => Assertions.MetricsDoNotExist(unexpectedMetrics, metrics),
() => Assertions.TransactionTraceSegmentsExist(expectedTransactionTraceSegments, transactionSample),
() => Assertions.TransactionEventHasAttributes(expectedTransactionEventIntrinsicAttributes, TransactionEventAttributeType.Intrinsic, transactionEvent),
() => Assertions.SqlTraceExists(expectedSqlTraces, sqlTraces)
);
}
}
[NetFrameworkTest]
public class PostgresSqlSimpleQueryAsyncTestsFW462 : PostgresSqlSimpleQueryAsyncTestsBase<ConsoleDynamicMethodFixtureFW462>
{
public PostgresSqlSimpleQueryAsyncTestsFW462(ConsoleDynamicMethodFixtureFW462 fixture, ITestOutputHelper output) : base(fixture, output)
{
}
}
[NetFrameworkTest]
public class PostgresSqlSimpleQueryAsyncTestsFW471 : PostgresSqlSimpleQueryAsyncTestsBase<ConsoleDynamicMethodFixtureFW471>
{
public PostgresSqlSimpleQueryAsyncTestsFW471(ConsoleDynamicMethodFixtureFW471 fixture, ITestOutputHelper output) : base(fixture, output)
{
}
}
[NetFrameworkTest]
public class PostgresSqlSimpleQueryAsyncTestsFW48 : PostgresSqlSimpleQueryAsyncTestsBase<ConsoleDynamicMethodFixtureFW48>
{
public PostgresSqlSimpleQueryAsyncTestsFW48(ConsoleDynamicMethodFixtureFW48 fixture, ITestOutputHelper output) : base(fixture, output)
{
}
}
[NetFrameworkTest]
public class PostgresSqlSimpleQueryAsyncTestsFWLatest : PostgresSqlSimpleQueryAsyncTestsBase<ConsoleDynamicMethodFixtureFWLatest>
{
public PostgresSqlSimpleQueryAsyncTestsFWLatest(ConsoleDynamicMethodFixtureFWLatest fixture, ITestOutputHelper output) : base(fixture, output)
{
}
}
[NetCoreTest]
public class PostgresSqlSimpleQueryAsyncTestsCoreOldest : PostgresSqlSimpleQueryAsyncTestsBase<ConsoleDynamicMethodFixtureCoreOldest>
{
public PostgresSqlSimpleQueryAsyncTestsCoreOldest(ConsoleDynamicMethodFixtureCoreOldest fixture, ITestOutputHelper output) : base(fixture, output)
{
}
}
[NetCoreTest]
public class PostgresSqlSimpleQueryAsyncTestsCoreLatest : PostgresSqlSimpleQueryAsyncTestsBase<ConsoleDynamicMethodFixtureCoreLatest>
{
public PostgresSqlSimpleQueryAsyncTestsCoreLatest(ConsoleDynamicMethodFixtureCoreLatest fixture, ITestOutputHelper output) : base(fixture, output)
{
}
}
}