|
| 1 | +// Copyright 2020 New Relic, Inc. All rights reserved. |
| 2 | +// SPDX-License-Identifier: Apache-2.0 |
| 3 | + |
| 4 | +using System; |
| 5 | +using System.Collections.Generic; |
| 6 | +using System.Linq; |
| 7 | +using System.Text; |
| 8 | +using System.Threading.Tasks; |
| 9 | +using Microsoft.VisualStudio.TestPlatform.Utilities; |
| 10 | +using NewRelic.Agent.IntegrationTestHelpers; |
| 11 | +using NewRelic.Agent.IntegrationTestHelpers.RemoteServiceFixtures; |
| 12 | +using Xunit; |
| 13 | +using Xunit.Abstractions; |
| 14 | + |
| 15 | +namespace NewRelic.Agent.UnboundedIntegrationTests.MsSql |
| 16 | +{ |
| 17 | + public class MsSqlFailedExplainPlanTests : NewRelicIntegrationTest<ConsoleDynamicMethodFixtureCoreLatest> |
| 18 | + { |
| 19 | + private readonly ConsoleDynamicMethodFixtureCoreLatest _fixture; |
| 20 | + |
| 21 | + public MsSqlFailedExplainPlanTests(ConsoleDynamicMethodFixtureCoreLatest fixture, ITestOutputHelper outputHelper) : base(fixture) |
| 22 | + { |
| 23 | + var exerciserName = "MicrosoftDataSqlClientExerciser"; |
| 24 | + |
| 25 | + _fixture = fixture; |
| 26 | + _fixture.TestLogger = outputHelper; |
| 27 | + |
| 28 | + var procedureName = Utilities.GenerateProcedureName(); |
| 29 | + |
| 30 | + _fixture.AddCommand($"{exerciserName} MsSqlCreateStoredProcWithTempTable {procedureName}"); |
| 31 | + _fixture.AddCommand($"{exerciserName} MsSqlStoredProcWithTempTable {procedureName}"); |
| 32 | + _fixture.AddCommand($"{exerciserName} MsSqlStoredProcWithTempTable {procedureName}"); |
| 33 | + _fixture.AddCommand($"{exerciserName} MsSqlDropStoredProcWithTempTable {procedureName}"); |
| 34 | + |
| 35 | + _fixture.AddActions |
| 36 | + ( |
| 37 | + setupConfiguration: () => |
| 38 | + { |
| 39 | + var configPath = fixture.DestinationNewRelicConfigFilePath; |
| 40 | + var configModifier = new NewRelicConfigModifier(configPath); |
| 41 | + configModifier.ConfigureFasterMetricsHarvestCycle(15); |
| 42 | + configModifier.ConfigureFasterTransactionTracesHarvestCycle(15); |
| 43 | + configModifier.ConfigureFasterSqlTracesHarvestCycle(15); |
| 44 | + |
| 45 | + configModifier.ForceTransactionTraces(); |
| 46 | + configModifier.SetLogLevel("finest"); //This has to stay at finest to ensure parameter check security |
| 47 | + |
| 48 | + CommonUtils.ModifyOrCreateXmlAttributeInNewRelicConfig(configPath, new[] { "configuration", "transactionTracer" }, "explainEnabled", "true"); |
| 49 | + CommonUtils.ModifyOrCreateXmlAttributeInNewRelicConfig(configPath, new[] { "configuration", "transactionTracer" }, "recordSql", "raw"); |
| 50 | + CommonUtils.ModifyOrCreateXmlAttributeInNewRelicConfig(configPath, new[] { "configuration", "transactionTracer" }, "explainThreshold", "1"); |
| 51 | + CommonUtils.ModifyOrCreateXmlAttributeInNewRelicConfig(configPath, new[] { "configuration", "datastoreTracer", "queryParameters" }, "enabled", "true"); |
| 52 | + }, |
| 53 | + exerciseApplication: () => |
| 54 | + { |
| 55 | + _fixture.AgentLog.WaitForLogLine(AgentLogBase.ExplainPlainFailureLogLineRegex, TimeSpan.FromMinutes(1)); |
| 56 | + } |
| 57 | + ); |
| 58 | + |
| 59 | + _fixture.Initialize(); |
| 60 | + |
| 61 | + } |
| 62 | + |
| 63 | + [Fact] |
| 64 | + public void Test() |
| 65 | + { |
| 66 | + // verify that the log contains one explain plan failure log line - second call to the stored proc doesn't try to generate an explain plan |
| 67 | + Assert.Single(_fixture.AgentLog.TryGetLogLines(AgentLogBase.ExplainPlainFailureLogLineRegex)); |
| 68 | + } |
| 69 | + } |
| 70 | +} |
0 commit comments