Commit 86c0fa81 authored by Marc Gravell's avatar Marc Gravell

swap int.TryParse => Format.TryParse just in case #883 is locale-related

parent d6653d3b
...@@ -245,7 +245,7 @@ internal static EndPoint TryParseEndPoint(string addressWithPort) ...@@ -245,7 +245,7 @@ internal static EndPoint TryParseEndPoint(string addressWithPort)
int? port = 0; int? port = 0;
if (portPart != null) if (portPart != null)
{ {
if (int.TryParse(portPart, out var portVal)) if (Format.TryParseInt32(portPart, out var portVal))
{ {
port = portVal; port = portVal;
} }
......
...@@ -1916,7 +1916,7 @@ protected override bool SetResultCore(PhysicalConnection connection, Message mes ...@@ -1916,7 +1916,7 @@ protected override bool SetResultCore(PhysicalConnection connection, Message mes
{ {
return true; return true;
} }
else if (arr.Length == 2 && int.TryParse(arr[1], out var port)) else if (arr.Length == 2 && Format.TryParseInt32(arr[1], out var port))
{ {
SetResult(message, Format.ParseEndPoint(arr[0], port)); SetResult(message, Format.ParseEndPoint(arr[0], port));
return true; return true;
......
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics; using System.Diagnostics;
using System.Globalization;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Net; using System.Net;
...@@ -331,33 +332,49 @@ private void Check(string name, object x, object y) ...@@ -331,33 +332,49 @@ private void Check(string name, object x, object y)
[Fact] [Fact]
public void Issue883_Exhaustive() public void Issue883_Exhaustive()
{ {
var a = ConnectionMultiplexer.PrepareConfig("myDNS:883,password=mypassword,connectRetry=3,connectTimeout=5000,syncTimeout=5000,defaultDatabase=0,ssl=true,abortConnect=false"); var old = CultureInfo.CurrentCulture;
var b = ConnectionMultiplexer.PrepareConfig(new ConfigurationOptions try
{ {
EndPoints = { { "myDNS", 883 } }, var all = CultureInfo.GetCultures(CultureTypes.AllCultures);
Password = "mypassword", Writer.WriteLine($"Checking {all.Length} cultures...");
ConnectRetry = 3, foreach (var ci in all)
ConnectTimeout = 5000, {
SyncTimeout = 5000, Writer.WriteLine("Tessting: " + ci.Name);
DefaultDatabase = 0, CultureInfo.CurrentCulture = ci;
Ssl = true,
AbortOnConnectFail = false, var a = ConnectionMultiplexer.PrepareConfig("myDNS:883,password=mypassword,connectRetry=3,connectTimeout=5000,syncTimeout=5000,defaultDatabase=0,ssl=true,abortConnect=false");
}); var b = ConnectionMultiplexer.PrepareConfig(new ConfigurationOptions
Writer.WriteLine($"computed: {b.ToString(true)}"); {
EndPoints = { { "myDNS", 883 } },
Writer.WriteLine("Checking endpoints..."); Password = "mypassword",
var c = a.EndPoints.Cast<DnsEndPoint>().Single(); ConnectRetry = 3,
var d = b.EndPoints.Cast<DnsEndPoint>().Single(); ConnectTimeout = 5000,
Check(nameof(c.Host), c.Host, d.Host); SyncTimeout = 5000,
Check(nameof(c.Port), c.Port, d.Port); DefaultDatabase = 0,
Check(nameof(c.AddressFamily), c.AddressFamily, d.AddressFamily); Ssl = true,
AbortOnConnectFail = false,
var fields = typeof(ConfigurationOptions).GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); });
Writer.WriteLine($"Comparing {fields.Length} fields..."); Writer.WriteLine($"computed: {b.ToString(true)}");
Array.Sort(fields, (x, y) => string.Compare(x.Name, y.Name));
foreach (var field in fields) Writer.WriteLine("Checking endpoints...");
var c = a.EndPoints.Cast<DnsEndPoint>().Single();
var d = b.EndPoints.Cast<DnsEndPoint>().Single();
Check(nameof(c.Host), c.Host, d.Host);
Check(nameof(c.Port), c.Port, d.Port);
Check(nameof(c.AddressFamily), c.AddressFamily, d.AddressFamily);
var fields = typeof(ConfigurationOptions).GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
Writer.WriteLine($"Comparing {fields.Length} fields...");
Array.Sort(fields, (x, y) => string.Compare(x.Name, y.Name));
foreach (var field in fields)
{
Check(field.Name, field.GetValue(a), field.GetValue(b));
}
}
}
finally
{ {
Check(field.Name, field.GetValue(a), field.GetValue(b)); CultureInfo.CurrentCulture = old;
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment