-
Notifications
You must be signed in to change notification settings - Fork 322
Test | Split TvpTest part1 #3956
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
Open
mdaigle
wants to merge
6
commits into
main
Choose a base branch
from
dev/mdaigle/split-tvp-part1
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+4,356
−3,521
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
2a566e2
Split baseline files.
mdaigle 1ac20af
Fix split test compilation.
mdaigle 82efb97
Remove original TestMain and combined output files.
mdaigle 22ad3b0
Fix compilation. Add flaky category.
mdaigle 20ef414
Add tests to single collection to force them to run serially.
mdaigle a6e8500
Set culture.
mdaigle File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
146 changes: 146 additions & 0 deletions
146
src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/ParameterTest/DateTimeVariantTests.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,146 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
| // See the LICENSE file in the project root for more information. | ||
|
|
||
| using System; | ||
| using System.Globalization; | ||
| using System.IO; | ||
| using System.Text; | ||
| using System.Threading; | ||
| using Xunit; | ||
|
|
||
| namespace Microsoft.Data.SqlClient.ManualTesting.Tests | ||
| { | ||
| /// <summary> | ||
| /// Tests for DateTime variant parameters with different date/time types. | ||
| /// These tests run independently with their own baseline comparison. | ||
| /// </summary> | ||
| [Collection("ParameterBaselineTests")] | ||
| public class DateTimeVariantTests | ||
| { | ||
| private readonly string _connStr; | ||
|
|
||
| public DateTimeVariantTests() | ||
| { | ||
| _connStr = DataTestUtility.TCPConnectionString; | ||
| } | ||
|
|
||
| [Trait("Category", "flaky")] | ||
| [ConditionalFact(typeof(DataTestUtility), nameof(DataTestUtility.AreConnStringsSetup), nameof(DataTestUtility.IsNotAzureSynapse))] | ||
| public void DateTimeVariantParameterTest() | ||
| { | ||
| Assert.True(RunTestAndCompareWithBaseline()); | ||
| } | ||
|
|
||
| private bool RunTestAndCompareWithBaseline() | ||
| { | ||
| CultureInfo previousCulture = Thread.CurrentThread.CurrentCulture; | ||
| Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US"); | ||
| try | ||
| { | ||
| string outputPath = "DateTimeVariant.out"; | ||
| string baselinePath; | ||
| #if DEBUG | ||
| if (DataTestUtility.IsNotAzureServer() || DataTestUtility.IsManagedInstance) | ||
| { | ||
| baselinePath = "DateTimeVariant_DebugMode.bsl"; | ||
| } | ||
| else | ||
| { | ||
| baselinePath = "DateTimeVariant_DebugMode_Azure.bsl"; | ||
| } | ||
| #else | ||
| if (DataTestUtility.IsNotAzureServer() || DataTestUtility.IsManagedInstance) | ||
| { | ||
| baselinePath = "DateTimeVariant_ReleaseMode.bsl"; | ||
| } | ||
| else | ||
| { | ||
| baselinePath = "DateTimeVariant_ReleaseMode_Azure.bsl"; | ||
| } | ||
mdaigle marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| #endif | ||
|
|
||
| var fstream = new FileStream(outputPath, FileMode.Create, FileAccess.Write, FileShare.Read); | ||
| var swriter = new StreamWriter(fstream, Encoding.UTF8); | ||
| var twriter = new TvpTest.CarriageReturnLineFeedReplacer(swriter); | ||
| Console.SetOut(twriter); | ||
|
|
||
| // Run Test | ||
| DateTimeVariantTest.TestAllDateTimeWithDataTypeAndVariant(_connStr); | ||
|
|
||
| Console.Out.Flush(); | ||
| Console.Out.Dispose(); | ||
|
|
||
| // Recover the standard output stream | ||
| StreamWriter standardOutput = new(Console.OpenStandardOutput()); | ||
| standardOutput.AutoFlush = true; | ||
| Console.SetOut(standardOutput); | ||
|
|
||
| // Compare output file | ||
| var comparisonResult = FindDiffFromBaseline(baselinePath, outputPath); | ||
|
|
||
| if (string.IsNullOrEmpty(comparisonResult)) | ||
| { | ||
| return true; | ||
| } | ||
|
|
||
| Console.WriteLine("DateTimeVariantParameterTest Failed!"); | ||
| Console.WriteLine("Please compare baseline: {0} with output: {1}", Path.GetFullPath(baselinePath), Path.GetFullPath(outputPath)); | ||
| Console.WriteLine("Comparison Results:"); | ||
| Console.WriteLine(comparisonResult); | ||
| return false; | ||
mdaigle marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
| finally | ||
| { | ||
| Thread.CurrentThread.CurrentCulture = previousCulture; | ||
| } | ||
| } | ||
|
|
||
| private static string FindDiffFromBaseline(string baselinePath, string outputPath) | ||
| { | ||
| var expectedLines = File.ReadAllLines(baselinePath); | ||
| var outputLines = File.ReadAllLines(outputPath); | ||
|
|
||
| var comparisonSb = new StringBuilder(); | ||
|
|
||
| var expectedLength = expectedLines.Length; | ||
| var outputLength = outputLines.Length; | ||
| var findDiffLength = Math.Min(expectedLength, outputLength); | ||
|
|
||
| for (var lineNo = 0; lineNo < findDiffLength; lineNo++) | ||
| { | ||
| if (!expectedLines[lineNo].Equals(outputLines[lineNo])) | ||
| { | ||
| comparisonSb.AppendFormat("** DIFF at line {0} \n", lineNo); | ||
| comparisonSb.AppendFormat("A : {0} \n", outputLines[lineNo]); | ||
| comparisonSb.AppendFormat("E : {0} \n", expectedLines[lineNo]); | ||
| } | ||
| } | ||
|
|
||
| var startIndex = findDiffLength - 1; | ||
| if (startIndex < 0) | ||
| { | ||
| startIndex = 0; | ||
| } | ||
|
|
||
| if (findDiffLength < expectedLength) | ||
| { | ||
| comparisonSb.AppendFormat("** MISSING \n"); | ||
| for (var lineNo = startIndex; lineNo < expectedLength; lineNo++) | ||
| { | ||
| comparisonSb.AppendFormat("{0} : {1}", lineNo, expectedLines[lineNo]); | ||
| } | ||
| } | ||
| if (findDiffLength < outputLength) | ||
| { | ||
| comparisonSb.AppendFormat("** EXTRA \n"); | ||
| for (var lineNo = startIndex; lineNo < outputLength; lineNo++) | ||
| { | ||
| comparisonSb.AppendFormat("{0} : {1}", lineNo, outputLines[lineNo]); | ||
| } | ||
| } | ||
|
|
||
| return comparisonSb.ToString(); | ||
| } | ||
| } | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The original monolithic
TvpTest.TestMainforcedThread.CurrentThread.CurrentCulturetoen-USto keep date/time string output stable for baseline comparisons. After splitting, this test no longer sets culture, so baselines can become machine-locale dependent. Set the culture (and ideally restore the previous culture in atry/finally) before running the test logic.