8000 Merge pull request #89 from bgrainger/skip-tests · mysql-net/MySqlConnector@b83ce6e · GitHub
[go: up one dir, main page]

Skip to content

Commit b83ce6e

Browse files
authored
Merge pull request #89 from bgrainger/skip-tests
Skip tests based on server capabilities.
2 parents cb09a8e + 829daeb commit b83ce6e

File tree

8 files changed

+107
-33
lines changed

8 files changed

+107
-33
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ before_install:
99
- sudo apt-key adv --keyserver apt-mo.trafficmanager.net --recv-keys 417A0893
1010
- sudo apt-get update
1111
- sudo apt-get install -y dotnet-dev-1.0.0-preview2-003121
12-
- docker exec -it mysql mysql -uroot -ptest -e "CREATE USER 'mysqltest'@'%' IDENTIFIED BY 'test;key=\"val'; GRANT ALL ON *.* TO mysqltest; CREATE USER 'no_password'@'172.17.0.1';"
12+
- docker exec -it mysql mysql -uroot -ptest -e "CREATE USER 'mysqltest'@'%' IDENTIFIED BY 'test;key=\"val'; GRANT ALL ON *.* TO mysqltest; CREATE USER 'no_password'@'172.17.0.1'; SET GLOBAL max_allowed_packet=104857600;"
1313

1414
script:
1515
- dotnet restore

appveyor.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ build_script:
1212
dotnet build tests\SideBySide.New --configuration Release
1313
before_test:
1414
- cmd: |-
15-
"C:\Program Files\MySQL\MySQL Server 5.7\bin\mysql.exe" -u root --password=Password12! -e "CREATE USER mysqltest IDENTIFIED BY 'test;key=\"val'; GRANT ALL ON *.* TO mysqltest;"
16-
"C:\Program Files\MySQL\MySQL Server 5.7\bin\mysql.exe" -u root --password=Password12! -e "CREATE USER no_password;"
15+
"C:\Program Files\MySQL\MySQL Server 5.7\bin\mysql.exe" -u root --password=Password12! -e "CREATE USER mysqltest IDENTIFIED BY 'test;key=\"val'; GRANT ALL ON *.* TO mysqltest; CREATE USER no_password;"
16+
"C:\Program Files\MySQL\MySQL Server 5.7\bin\mysql.exe" -u root --password=Password12! -e "SET GLOBAL max_allowed_packet=104857600;"
1717
test_script:
1818
- cmd: |-
1919
dotnet test tests\MySqlConnector.Tests --configuration Release

tests/SideBySide.Baseline/SideBySide.Baseline.csproj

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@
3535
<WarningLevel>4</WarningLevel>
3636
</PropertyGroup>
3737
<ItemGroup>
38-
<Reference Include="Dapper, Version=1.40.0.0, Culture=neutral, processorArchitecture=MSIL">
39-
<HintPath>..\..\packages\Dapper.1.42\lib\net45\Dapper.dll</HintPath>
38+
<Reference Include="Dapper, Version=1.50.2.0, Culture=neutral, processorArchitecture=MSIL">
39+
<HintPath>..\..\packages\Dapper.1.50.2\lib\net451\Dapper.dll</HintPath>
4040
<Private>True</Private>
4141
</Reference>
4242
<Reference Include="MySql.Data, Version=6.9.8.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d, processorArchitecture=MSIL">
@@ -105,6 +105,9 @@
105105
<Compile Include="..\SideBySide.New\QueryTests.cs">
106106
<Link>QueryTests.cs</Link>
107107
</Compile>
108+
<Compile Include="..\SideBySide.New\TestUtilities.cs">
109+
<Link>TestUtilities.cs</Link>
110+
</Compile>
108111
<Compile Include="..\SideBySide.New\Transaction.cs">
109112
<Link>Transaction.cs</Link>
110113
</Compile>

tests/SideBySide.Baseline/packages.config

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<packages>
3-
<package id="Dapper" version="1.42" targetFramework="net46" />
3+
<package id="Dapper" version="1.50.2" targetFramework="net46" />
44
<package id="MySql.Data" version="6.9.8" targetFramework="net46" />
55
<package id="xunit" version="2.1.0" targetFramework="net46" />
66
<package id="xunit.abstractions" version="2.0.0" targetFramework="net46" />

tests/SideBySide.New/DataTypes.cs

Lines changed: 43 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -465,11 +465,16 @@ public void QueryBlob(string column, int padLength)
465465
[Theory]
466466
[InlineData("TinyBlob", 255)]
467467
[InlineData("Blob", 65535)]
468+
[InlineData("MediumBlob", 16777215)]
469+
[InlineData("LongBlob", 67108864)]
468470
public async Task InsertLargeBlobAsync(string column, int size)
469471
{
470-
var data = new byte[size];
471-
Random random = new Random(size);
472-
random.NextBytes(data);
472+
// verify that this amount of data can be sent to MySQL successfully
473+
var maxAllowedPacket = (await m_database.Connection.QueryAsync<int>("select @@max_allowed_packet").ConfigureAwait(false)).Single();
474+
if (maxAllowedPacket < size)
475+
return; // TODO: Use [SkippableFact]
476+
477+
var data = CreateByteArray(size);
473478

474479
long lastInsertId;
475480
using (var cmd = new MySqlCommand(Invariant($"insert into datatypes.blobs(`{column}`) values(?)"), m_database.Connection)
@@ -481,29 +486,25 @@ public async Task InsertLargeBlobAsync(string column, int size)
481486
lastInsertId = cmd.LastInsertedId;
482487
}
483488

484-
foreach (var queryResult in await m_database.Connection.QueryAsync<byte[]>(Invariant($"select `{column}` from datatypes.blobs where rowid = {lastInsertId}")).ConfigureAwait(false))
485-
{
486-
Assert.Equal(data, queryResult);
487-
break;
488-
}
489+
var queryResult = (await m_database.Connection.QueryAsync<byte[]>(Invariant($"select `{column}` from datatypes.blobs where rowid = {lastInsertId}")).ConfigureAwait(false)).Single();
490+
TestUtilities.AssertEqual(data, queryResult);
489491

490492
await m_database.Connection.ExecuteAsync(Invariant($"delete from datatypes.blobs where rowid = {lastInsertId}")).ConfigureAwait(false);
491493
}
492494

493495
[Theory]
494496
[InlineData("TinyBlob", 255)]
495497
[InlineData("Blob", 65535)]
496-
#if false
497-
// MySQL has a default max_allowed_packet size of 4MB; without changing the server configuration, it's impossible
498-
// to send more than 4MB of data.
499498
[InlineData("MediumBlob", 16777215)]
500499
[InlineData("LongBlob", 67108864)]
501-
#endif
502500
public void InsertLargeBlobSync(string column, int size)
503501
{
504-
var data = new byte[size];
505-
Random random = new Random(size);
506-
random.NextBytes(data);
502+
// verify that this amount of data can be sent to MySQL successfully
503+
var maxAllowedPacket = m_database.Connection.Query<int>("select @@max_allowed_packet").Single();
504+
if (maxAllowedPacket < size)
505+
return; // TODO: Use [SkippableFact]
506+
507+
var data = CreateByteArray(size);
507508

508509
long lastInsertId;
509510
using (var cmd = new MySqlCommand(Invariant($"insert into datatypes.blobs(`{column}`) values(?)"), m_database.Connection)
@@ -515,33 +516,49 @@ public void InsertLargeBlobSync(string column, int size)
515516
lastInsertId = cmd.LastInsertedId;
516517
}
517518

518-
foreach (var queryResult in m_database.Connection.Query<byte[]>(Invariant($"select `{column}` from datatypes.blobs where rowid = {lastInsertId}")))
519-
{
520-
Assert.Equal(data, queryResult);
521-
break;
522-
}
519+
var queryResult = m_database.Connection.Query<byte[]>(Invariant($"select `{column}` from datatypes.blobs where rowid = {lastInsertId}")).Single();
520+
TestUtilities.AssertEqual(data, queryResult);
523521

524522
m_database.Connection.Execute(Invariant($"delete from datatypes.blobs where rowid = {lastInsertId}"));
525523
}
526524

525+
private static byte[] CreateByteArray(int size)
526+
{
527+
var data = new byte[size];
528+
Random random = new Random(size);
529+
random.NextBytes(data);
530+
531+
// ensure each byte value is used at least once
532+
for (int i = 0; i < Math.Min(255, size); i++)
533+
data[i] = (byte) i;
534+
535+
return data;
536+
}
537+
527538
[Theory]
528539
[InlineData("Value", new[] { null, "NULL", "BOOLEAN", "ARRAY", "ARRAY", "ARRAY", "INTEGER", "INTEGER", "OBJECT", "OBJECT" })]
529540
public void JsonType(string column, string[] expectedTypes)
530541
{
531-
var types = m_database.Connection.Query<string>(@"select JSON_TYPE(value) from datatypes.json_core order by rowid;").ToList();
532-
Assert.Equal(expectedTypes, types);
542+
if (TestUtilities.SupportsJson(m_database.Connection.ServerVersion))
543+
{
544+
var types = m_database.Connection.Query<string>(@"select JSON_TYPE(value) from datatypes.json_core order by rowid;").ToList();
545+
Assert.Equal(expectedTypes, types);
546+
}
533547
}
534548

535549
[Theory]
536550
[InlineData("value", new[] { null, "null", "true", "[]", "[0]", "[1]", "0", "1", "{}", "{\"a\": \"b\"}" })]
537551
public void QueryJson(string column, string[] expected)
538552
{
539-
string dataTypeName = "JSON";
553+
if (TestUtilities.SupportsJson(m_database.Connection.ServerVersion))
554+
{
555+
string dataTypeName = "JSON";
540556
#if BASELINE
541-
// mysql-connector-net returns "VARCHAR" for "JSON"
542-
dataTypeName = "VARCHAR";
557+
// mysql-connector-net returns "VARCHAR" for "JSON"
558+
dataTypeName = "VARCHAR";
543559
#endif
544-
DoQuery("json_core", column, dataTypeName, expected, reader => reader.GetString(0), omitWhereTest: true);
560+
DoQuery("json_core", column, dataTypeName, expected, reader => reader.GetString(0), omitWhereTest: true);
561+
}
545562
}
546563

547564
private static byte[] GetBytes(DbDataReader reader)

tests/SideBySide.New/DataTypesFixture.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,11 @@ insert into datatypes.guids (char38, char38bin, `text`, `blob`)
160160
'33221100-5544-7766-8899-aabbccddeeff', X'00112233445566778899AABBCCDDEEFF'),
161161
('{33221100-5544-7766-8899-aabbccddeeff}', '{33221100-5544-7766-8899-aabbccddeeff}',
162162
'{33221100-5544-7766-8899-aabbccddeeff}', X'00112233445566778899AABBCCDDEEFF');
163+
");
163164

165+
if (TestUtilities.SupportsJson(Connection.ServerVersion))
166+
{
167+
Connection.Execute(@"
164168
create table datatypes.json_core (
165169
rowid integer not null primary key auto_increment,
166170
value json null
@@ -179,6 +183,7 @@ insert into datatypes.json_core (value)
179183
('{}'),
180184
('{""a"": ""b""}');
181185
");
186+
}
182187
}
183188

184189
protected override void Dispose(bool disposing)

tests/SideBySide.New/TestUtilities.cs

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
using System;
2+
using System.Globalization;
3+
using Xunit;
4+
5+
namespace SideBySide
6+
{
7+
public class TestUtilities
8+
{
9+
/// <summary>
10+
/// Asserts that two byte arrays are equal. This method is much faster than xUnit's <code>Assert.Equal</code>.
11+
/// </summary>
12+
/// <param name="expected">The expected byte array.</param>
13+
/// <param name="actual">The actual byte array.</param>
14+
public static void AssertEqual(byte[] expected, byte[] actual)
15+
{
16+
Assert.Equal(expected.Length, actual.Length);
17+
for (var i = 0; i < expected.Length; i++)
18+
{
19+
if (expected[i] != actual[i])
20+
Assert.Equal(expected[i], actual[i]);
21+
}
22+
}
23+
24+
public static Version ParseServerVersion(string serverVersion)
25+
{
26+
// copied from MySql.Data.MySqlClient.ServerVersion
27+
28+
var last = 0;
29+
var index = serverVersion.IndexOf('.', last);
30+
var major = int.Parse(serverVersion.Substring(last, index - last), CultureInfo.InvariantCulture);
31+
last = index + 1;
32+
33+
index = serverVersion.IndexOf('.', last);
34+
var minor = int.Parse(serverVersion.Substring(last, index - last), CultureInfo.InvariantCulture);
35+
last = index + 1;
36+
37+
do
38+
{
39+
index++;
40+
} while (index < serverVersion.Length && serverVersion[index] >= '0' && serverVersion[index] <= '9');
41+
var build = int.Parse(serverVersion.Substring(last, index - last), CultureInfo.InvariantCulture);
42+
43+
return new Version(major, minor, build);
44+
}
45+
46+
public static bool SupportsJson(string serverVersion) =>
47+
ParseServerVersion(serverVersion).CompareTo(new Version(5, 7)) >= 0;
48+
}
49+
}

tests/SideBySide.New/project.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"MySqlConnector": {
88
"target": "project"
99
},
10-
"Dapper": "1.50.0-*",
10+
"Dapper": "1.50.2",
1111
"xunit": "2.2.0-beta2-build3300",
1212
"dotnet-test-xunit": "2.2.0-preview2-build1029"
1313
},

0 commit comments

Comments
 (0)
0