Skip to content
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

Enable culture analyzer and fix issues #3678

Merged
merged 23 commits into from
Jul 11, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fix culture issues on cross plat engine
  • Loading branch information
Evangelink committed Jun 30, 2022
commit d74922b1dfddebaf60fc885e8ea149122bdb0bf0
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.IO.Pipes;
using System.Linq;
Expand Down Expand Up @@ -124,7 +125,7 @@ private void PipeReaderTask()
.SendMessage((TestMessageLevel)Enum.Parse(typeof(TestMessageLevel), prefix.Substring(prefix.LastIndexOf('.') + 1), false), message);
break;
case AppDomainPipeMessagePrefix.Report:
_progressReporter?.Report(int.Parse(message));
_progressReporter?.Report(int.Parse(message, CultureInfo.CurrentCulture));
break;
default:
EqtTrace.Error($"DataCollectorAttachmentProcessorAppDomain:PipeReaderTask: Unknown message: {message}");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Threading;

Expand Down Expand Up @@ -141,11 +142,11 @@ public void AggregateMetrics(IDictionary<string, object>? metrics)
|| metric.Key.Contains(TelemetryDataConstants.TotalTestsByAdapter)
|| metric.Key.Contains(TelemetryDataConstants.TimeTakenToLoadAdaptersInSec))
{
var newValue = Convert.ToDouble(metric.Value);
var newValue = Convert.ToDouble(metric.Value, CultureInfo.InvariantCulture);

if (_metricsAggregator.TryGetValue(metric.Key, out object? oldValue))
{
double oldDoubleValue = Convert.ToDouble(oldValue);
double oldDoubleValue = Convert.ToDouble(oldValue, CultureInfo.InvariantCulture);
_metricsAggregator[metric.Key] = newValue + oldDoubleValue;
}
else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Globalization;
using System.Linq;

using Microsoft.VisualStudio.TestPlatform.Common.ExtensionFramework.Utilities;
Expand Down Expand Up @@ -194,11 +195,11 @@ public void AggregateRunDataMetrics(IDictionary<string, object>? metrics)
{
if (metric.Key.Contains(TelemetryDataConstants.TimeTakenToRunTestsByAnAdapter) || metric.Key.Contains(TelemetryDataConstants.TimeTakenByAllAdaptersInSec) || (metric.Key.Contains(TelemetryDataConstants.TotalTestsRun) || metric.Key.Contains(TelemetryDataConstants.TotalTestsRanByAdapter)))
{
var newValue = Convert.ToDouble(metric.Value);
var newValue = Convert.ToDouble(metric.Value, CultureInfo.InvariantCulture);

if (_metricsAggregator.TryGetValue(metric.Key, out var oldValue))
{
var oldDoubleValue = Convert.ToDouble(oldValue);
var oldDoubleValue = Convert.ToDouble(oldValue, CultureInfo.InvariantCulture);
_metricsAggregator[metric.Key] = newValue + oldDoubleValue;
}
else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;

using Microsoft.VisualStudio.TestPlatform.Common;
Expand Down Expand Up @@ -323,7 +324,7 @@ private void InitializeExtensions(IEnumerable<string> sources)
var nonExistingExtensions = extensions.Where(extension => !_fileHelper.Exists(extension));
if (nonExistingExtensions.Any())
{
LogMessage(TestMessageLevel.Warning, string.Format(Resources.Resources.NonExistingExtensions, string.Join(",", nonExistingExtensions)));
LogMessage(TestMessageLevel.Warning, string.Format(CultureInfo.CurrentCulture, Resources.Resources.NonExistingExtensions, string.Join(",", nonExistingExtensions)));
}

var sourceList = sources.ToList();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Globalization;
using System.Linq;
using System.Threading;

Expand Down Expand Up @@ -449,7 +450,7 @@ private void InitializeExtensions(IEnumerable<string> sources)
var nonExistingExtensions = extensions.Where(extension => !_fileHelper.Exists(extension));
if (nonExistingExtensions.Any())
{
LogMessage(TestMessageLevel.Warning, string.Format(Resources.Resources.NonExistingExtensions, string.Join(",", nonExistingExtensions)));
LogMessage(TestMessageLevel.Warning, string.Format(CultureInfo.CurrentCulture, Resources.Resources.NonExistingExtensions, string.Join(",", nonExistingExtensions)));
}

var sourceList = sources.ToList();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -229,10 +229,7 @@ public virtual bool SetupChannel(IEnumerable<string> sources, string? runSetting
EqtTrace.Error("ProxyOperationManager: Failed to launch testhost :{0}", ex);

CancellationTokenSource.Token.ThrowTestPlatformExceptionIfCancellationRequested();
throw new TestPlatformException(string.Format(
CultureInfo.CurrentUICulture,
CrossPlatEngineResources.FailedToLaunchTestHost,
ex.ToString()));
throw new TestPlatformException(string.Format(CultureInfo.CurrentCulture, CrossPlatEngineResources.FailedToLaunchTestHost, ex.ToString()));
}

// Warn the user that execution will wait for debugger attach.
Expand All @@ -251,6 +248,7 @@ public virtual bool SetupChannel(IEnumerable<string> sources, string? runSetting

ConsoleOutput.Instance.WriteLine(
string.Format(
CultureInfo.InvariantCulture,
"Process Id: {0}, Name: {1}",
_testHostProcessId,
_processHelper.GetProcessName(_testHostProcessId)),
Expand Down Expand Up @@ -412,8 +410,9 @@ public virtual TestProcessStartInfo UpdateTestProcessStartInfo(TestProcessStartI
: Path.ChangeExtension(
logFile,
string.Format(
CultureInfo.InvariantCulture,
"host.{0}_{1}{2}",
DateTime.Now.ToString("yy-MM-dd_HH-mm-ss_fffff"),
DateTime.Now.ToString("yy-MM-dd_HH-mm-ss_fffff", CultureInfo.InvariantCulture),
new PlatformEnvironment().GetCurrentManagedThreadId(),
Path.GetExtension(logFile))).AddDoubleQuote();
}
Expand Down Expand Up @@ -465,7 +464,7 @@ private void ThrowOnTestHostExited(bool testHostExited)
{
// We might consider passing standard output here in case standard error is not
// available because some errors don't end up in the standard error output.
throw new TestPlatformException(string.Format(CrossPlatEngineResources.TestHostExitedWithError, _testHostProcessStdError));
throw new TestPlatformException(string.Format(CultureInfo.CurrentCulture, CrossPlatEngineResources.TestHostExitedWithError, _testHostProcessStdError));
}
}

Expand All @@ -478,6 +477,7 @@ private void ThrowExceptionOnConnectionFailure(int connTimeout)
if (_testHostLaunched)
{
errorMsg = string.Format(
CultureInfo.CurrentCulture,
CommunicationUtilitiesResources.ConnectionTimeoutErrorMessage,
CoreUtilitiesConstants.VstestConsoleProcessName,
CoreUtilitiesConstants.TesthostProcessName,
Expand All @@ -489,9 +489,9 @@ private void ThrowExceptionOnConnectionFailure(int connTimeout)
if (!StringUtils.IsNullOrWhiteSpace(_testHostProcessStdError))
{
// Testhost failed with error.
errorMsg = string.Format(CrossPlatEngineResources.TestHostExitedWithError, _testHostProcessStdError);
errorMsg = string.Format(CultureInfo.CurrentCulture, CrossPlatEngineResources.TestHostExitedWithError, _testHostProcessStdError);
}

throw new TestPlatformException(string.Format(CultureInfo.CurrentUICulture, errorMsg));
throw new TestPlatformException(errorMsg);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -183,10 +183,7 @@ public void Initialize(string? runSettings)
: logger.FriendlyName;

throw new InvalidLoggerException(
string.Format(
CultureInfo.CurrentUICulture,
CommonResources.LoggerNotFound,
value));
string.Format(CultureInfo.CurrentCulture, CommonResources.LoggerNotFound, value));
}
}

Expand Down Expand Up @@ -413,7 +410,7 @@ internal bool TryGetUriFromFriendlyName(string? friendlyName, out Uri? loggerUri

throw new InvalidLoggerException(
string.Format(
CultureInfo.CurrentUICulture,
CultureInfo.CurrentCulture,
CommonResources.LoggerUriInvalid,
extension.Metadata.ExtensionUri));
}
Expand Down Expand Up @@ -617,7 +614,7 @@ private bool InitializeLogger(object? logger, string? extensionUri, Dictionary<s
_messageLogger.SendMessage(
TestMessageLevel.Error,
string.Format(
CultureInfo.CurrentUICulture,
CultureInfo.CurrentCulture,
CommonResources.LoggerInitializationError,
extensionUri.IsNullOrEmpty() ? "type" : "uri",
extensionUri.IsNullOrEmpty() ? logger.GetType().ToString() : extensionUri,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Reflection;

Expand Down Expand Up @@ -101,8 +102,7 @@ public override int LaunchDataCollector(IDictionary<string, string?>? environmen
EqtTrace.Verbose("DotnetDataCollectionLauncher: Full path of dotnet.exe is {0}", currentProcessFileName);

var cliArgs = string.Join(" ", commandLineArguments);
var argumentsString = string.Format("{0} \"{1}\" {2} ", args, dataCollectorAssemblyPath, cliArgs);

var argumentsString = string.Format(CultureInfo.InvariantCulture, "{0} \"{1}\" {2} ", args, dataCollectorAssemblyPath, cliArgs);
var dataCollectorProcess = _processHelper.LaunchProcess(currentProcessFileName, argumentsString, Directory.GetCurrentDirectory(), environmentVariables, ErrorReceivedCallback, ExitCallBack, null);

DataCollectorProcessId = _processHelper.GetProcessId(dataCollectorProcess);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ public void Initialize()
EqtTrace.Error("ProxyDataCollectionManager.Initialize: failed to connect to datacollector process, processId: {0} port: {1}", _dataCollectionProcessId, _dataCollectionPort);
throw new TestPlatformException(
string.Format(
CultureInfo.CurrentUICulture,
CultureInfo.CurrentCulture,
CommunicationUtilitiesResources.ConnectionTimeoutErrorMessage,
CoreUtilitiesConstants.VstestConsoleProcessName,
CoreUtilitiesConstants.DatacollectorProcessName,
Expand All @@ -271,7 +271,7 @@ private int GetConnectionTimeout(int processId)
{
ConsoleOutput.Instance.WriteLine(CrossPlatEngineResources.DataCollectorDebuggerWarning, OutputLevel.Warning);
ConsoleOutput.Instance.WriteLine(
string.Format("Process Id: {0}, Name: {1}", processId, _processHelper.GetProcessName(processId)),
string.Format(CultureInfo.InvariantCulture, "Process Id: {0}, Name: {1}", processId, _processHelper.GetProcessName(processId)),
OutputLevel.Information);

// Increase connection timeout when debugging is enabled.
Expand Down Expand Up @@ -307,10 +307,10 @@ private IList<string> GetCommandLineArguments(int portNumber)
var commandlineArguments = new List<string>
{
PortOption,
portNumber.ToString(),
portNumber.ToString(CultureInfo.CurrentCulture),

ParentProcessIdOption,
_processHelper.GetCurrentProcessId().ToString()
_processHelper.GetCurrentProcessId().ToString(CultureInfo.CurrentCulture)
};

if (!StringUtils.IsNullOrEmpty(EqtTrace.LogFile))
Expand All @@ -319,7 +319,7 @@ private IList<string> GetCommandLineArguments(int portNumber)
commandlineArguments.Add(GetTimestampedLogFile(EqtTrace.LogFile));

commandlineArguments.Add(TraceLevelOption);
commandlineArguments.Add(((int)EqtTrace.TraceLevel).ToString());
commandlineArguments.Add(((int)EqtTrace.TraceLevel).ToString(CultureInfo.CurrentCulture));
}

return commandlineArguments;
Expand All @@ -330,8 +330,9 @@ private static string GetTimestampedLogFile(string logFile)
return Path.ChangeExtension(
logFile,
string.Format(
CultureInfo.InvariantCulture,
"datacollector.{0}_{1}{2}",
DateTime.Now.ToString("yy-MM-dd_HH-mm-ss_fffff"),
DateTime.Now.ToString("yy-MM-dd_HH-mm-ss_fffff", CultureInfo.CurrentCulture),
new PlatformEnvironment().GetCurrentManagedThreadId(),
Path.GetExtension(logFile))).AddDoubleQuote();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,8 +232,8 @@ private void DiscoverTestsFromSingleDiscoverer(
// Record Total Tests Discovered By each Discoverer.
var totalTestsDiscoveredByCurrentDiscoverer = _discoveryResultCache.TotalDiscoveredTests - currentTotalTests;
_requestData.MetricsCollection.Add(
string.Format("{0}.{1}", TelemetryDataConstants.TotalTestsByAdapter,
discoverer.Metadata.DefaultExecutorUri), totalTestsDiscoveredByCurrentDiscoverer);
$"{TelemetryDataConstants.TotalTestsByAdapter}.{discoverer.Metadata.DefaultExecutorUri}",
totalTestsDiscoveredByCurrentDiscoverer);

totalAdaptersUsed++;

Expand All @@ -249,14 +249,14 @@ private void DiscoverTestsFromSingleDiscoverer(

// Collecting Data Point for Time Taken to Discover Tests by each Adapter
_requestData.MetricsCollection.Add(
string.Format("{0}.{1}", TelemetryDataConstants.TimeTakenToDiscoverTestsByAnAdapter,
discoverer.Metadata.DefaultExecutorUri), totalAdapterRunTime.TotalSeconds);
$"{TelemetryDataConstants.TimeTakenToDiscoverTestsByAnAdapter}.{discoverer.Metadata.DefaultExecutorUri}",
totalAdapterRunTime.TotalSeconds);
totalTimeTakenByAdapters += totalAdapterRunTime.TotalSeconds;
}
catch (Exception e)
{
var message = string.Format(
CultureInfo.CurrentUICulture,
CultureInfo.CurrentCulture,
CrossPlatEngineResources.ExceptionFromLoadTests,
discovererType.Name,
e.Message);
Expand All @@ -277,10 +277,7 @@ private static bool TryToLoadDiscoverer(LazyExtension<ITestDiscoverer, ITestDisc
}
catch (Exception e)
{
var mesage = string.Format(
CultureInfo.CurrentUICulture,
CrossPlatEngineResources.DiscovererInstantiationException,
e.Message);
var mesage = string.Format(CultureInfo.CurrentCulture, CrossPlatEngineResources.DiscovererInstantiationException, e.Message);
logger.SendMessage(TestMessageLevel.Warning, mesage);
EqtTrace.Error("DiscovererEnumerator.LoadTestsFromAnExtension: {0} ", e);

Expand Down Expand Up @@ -316,16 +313,13 @@ private static void LogWarningOnNoTestsDiscovered(IEnumerable<string> sources, s

logger.SendMessage(
TestMessageLevel.Warning,
string.Format(CrossPlatEngineResources.NoTestsAvailableForGivenTestCaseFilter, testCaseFilterToShow, sourcesString));
string.Format(CultureInfo.CurrentCulture, CrossPlatEngineResources.NoTestsAvailableForGivenTestCaseFilter, testCaseFilterToShow, sourcesString));
}
else
{
logger.SendMessage(
TestMessageLevel.Warning,
string.Format(
CultureInfo.CurrentUICulture,
CrossPlatEngineResources.TestRunFailed_NoDiscovererFound_NoTestsAreAvailableInTheSources,
sourcesString));
string.Format(CultureInfo.CurrentCulture, CrossPlatEngineResources.TestRunFailed_NoDiscovererFound_NoTestsAreAvailableInTheSources, sourcesString));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.Threading;

using Microsoft.VisualStudio.TestPlatform.CommunicationUtilities.EventHandlers;
Expand Down Expand Up @@ -348,7 +349,7 @@ public void OnMessageReceived(object? sender, MessageReceivedEventArgs messageRe
// Can only do this after InitializeCommunication because TestHost cannot "Send Log" unless communications are initialized
if (!StringUtils.IsNullOrEmpty(EqtTrace.LogFile))
{
SendLog(TestMessageLevel.Informational, string.Format(CrossPlatResources.TesthostDiagLogOutputFile, EqtTrace.LogFile));
SendLog(TestMessageLevel.Informational, string.Format(CultureInfo.CurrentCulture, CrossPlatResources.TesthostDiagLogOutputFile, EqtTrace.LogFile));
}
else if (!StringUtils.IsNullOrEmpty(EqtTrace.ErrorOnInitialization))
{
Expand Down
Loading