Skip to content

Commit 26149ed

Browse files
committed
Test MariaDB 10.3. Fixes #504
Instead of adding a new ServerFeatures flag controlling whether 'SELECT 1;' is expected to return Int32 or Int64, permit either and perform a conversion where necessary. (There are other tests that will ensure data types are transmitted/parsed correctly.) Signed-off-by: Bradley Grainger <[email protected]>
1 parent 6d6c23f commit 26149ed

File tree

6 files changed

+41
-20
lines changed

6 files changed

+41
-20
lines changed

.travis.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ env:
1818
- IMAGE=mariadb:10.2
1919
NAME=mariadb
2020
OMIT_FEATURES=Json,Sha256Password,CachingSha2Password,RoundDateTime,UuidToBin
21+
- IMAGE=mariadb:10.3
22+
NAME=mariadb
23+
OMIT_FEATURES=Json,Sha256Password,CachingSha2Password,RoundDateTime,UuidToBin
2124

2225
before_install:
2326
- .ci/docker-run.sh $IMAGE $NAME 3307 $OMIT_FEATURES

tests/SideBySide/CancelTests.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,7 @@ public void NoCancel()
2828
using (var cmd = new MySqlCommand("SELECT SLEEP(0.25)", m_database.Connection))
2929
{
3030
var stopwatch = Stopwatch.StartNew();
31-
var result = (long) cmd.ExecuteScalar();
32-
Assert.Equal(0L, result);
31+
Assert.Equal(0L, Convert.ToInt64(cmd.ExecuteScalar()));
3332
Assert.InRange(stopwatch.ElapsedMilliseconds, 100, 1000);
3433
}
3534
}
@@ -46,8 +45,7 @@ public void CancelCommand()
4645
});
4746

4847
var stopwatch = Stopwatch.StartNew();
49-
var result = (long) cmd.ExecuteScalar();
50-
Assert.Equal(1L, result);
48+
TestUtilities.AssertIsOne(cmd.ExecuteScalar());
5149
Assert.InRange(stopwatch.ElapsedMilliseconds, 250, 2500);
5250

5351
task.Wait(); // shouldn't throw

tests/SideBySide/CommandTests.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ public void CommandTransactionMustBeSet()
114114
Assert.Throws<InvalidOperationException>(() => command.ExecuteScalar());
115115

116116
command.Transaction = transaction;
117-
Assert.Equal(1L, command.ExecuteScalar());
117+
TestUtilities.AssertIsOne(command.ExecuteScalar());
118118
}
119119
}
120120
}
@@ -129,7 +129,7 @@ public void IgnoreCommandTransactionIgnoresNull()
129129
using (var command = connection.CreateCommand())
130130
{
131131
command.CommandText = "SELECT 1;";
132-
Assert.Equal(1L, command.ExecuteScalar());
132+
TestUtilities.AssertIsOne(command.ExecuteScalar());
133133
}
134134
}
135135
}
@@ -149,7 +149,7 @@ public void IgnoreCommandTransactionIgnoresDisposedTransaction()
149149
{
150150
command.CommandText = "SELECT 1;";
151151
command.Transaction = transaction;
152-
Assert.Equal(1L, command.ExecuteScalar());
152+
TestUtilities.AssertIsOne(command.ExecuteScalar());
153153
}
154154
}
155155
}
@@ -167,7 +167,7 @@ public void IgnoreCommandTransactionIgnoresDifferentTransaction()
167167
{
168168
command2.Transaction = transaction1;
169169
command2.CommandText = "SELECT 1;";
170-
Assert.Equal(1L, command2.ExecuteScalar());
170+
TestUtilities.AssertIsOne(command2.ExecuteScalar());
171171
}
172172
}
173173
}

tests/SideBySide/DataAdapterTests.cs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public void UseDataAdapter()
4949
Assert.Single(ds.Tables);
5050
Assert.Single(ds.Tables[0].Rows);
5151
Assert.Single(ds.Tables[0].Rows[0].ItemArray);
52-
Assert.Equal(1L, ds.Tables[0].Rows[0][0]);
52+
TestUtilities.AssertIsOne(ds.Tables[0].Rows[0][0]);
5353
}
5454
}
5555

@@ -61,7 +61,7 @@ public void UseDataAdapterMySqlConnectionConstructor()
6161
using (var ds = new DataSet())
6262
{
6363
da.Fill(ds);
64-
Assert.Equal(1L, ds.Tables[0].Rows[0][0]);
64+
TestUtilities.AssertIsOne(ds.Tables[0].Rows[0][0]);
6565
}
6666
}
6767

@@ -72,8 +72,7 @@ public void UseDataAdapterStringMySqlConnectionConstructor()
7272
using (var ds = new DataSet())
7373
{
7474
da.Fill(ds);
75-
Assert.Equal(1L, ds.Tables[0].Rows[0][0]);
76-
Assert.Equal(1L, ds.Tables[0].Rows[0][0]);
75+
TestUtilities.AssertIsOne(ds.Tables[0].Rows[0][0]);
7776
}
7877
}
7978

@@ -84,7 +83,7 @@ public void UseDataAdapterStringStringConstructor()
8483
using (var ds = new DataSet())
8584
{
8685
da.Fill(ds);
87-
Assert.Equal(1L, ds.Tables[0].Rows[0][0]);
86+
TestUtilities.AssertIsOne(ds.Tables[0].Rows[0][0]);
8887
}
8988
}
9089

tests/SideBySide/QueryTests.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -502,14 +502,14 @@ id bigint(20) not null primary key
502502
public void ExecuteScalarReturnsFirstValue()
503503
{
504504
var result = m_database.Connection.ExecuteScalar("select 1; select 2;");
505-
Assert.Equal(1L, result);
505+
TestUtilities.AssertIsOne(result);
506506
}
507507

508508
[Fact]
509509
public async Task ExecuteScalarAsyncReturnsFirstValue()
510510
{
511511
var result = await m_database.Connection.ExecuteScalarAsync("select 1; select 2;");
512-
Assert.Equal(1L, result);
512+
TestUtilities.AssertIsOne(result);
513513
}
514514

515515
[Fact]
@@ -649,8 +649,8 @@ public void UseReaderWithoutDisposing()
649649
[InlineData("null", typeof(object))]
650650
#endif
651651
[InlineData("cast(null as char)", typeof(string))]
652-
[InlineData("1", typeof(long))]
653-
[InlineData("cast(1 as unsigned)", typeof(ulong))]
652+
[InlineData("1000000000000", typeof(long))]
653+
[InlineData("cast(1000000000000 as unsigned)", typeof(ulong))]
654654
[InlineData("1.0", typeof(decimal))]
655655
[InlineData("'text'", typeof(string))]
656656
[InlineData("cast('text' as char(4))", typeof(string))]
@@ -679,8 +679,8 @@ public void GetFieldType(string value, Type expectedType)
679679
[InlineData("null", "NULL")]
680680
#endif
681681
[InlineData("cast(null as char)", "VARCHAR")]
682-
[InlineData("1", "BIGINT")]
683-
[InlineData("cast(1 as unsigned)", "BIGINT")]
682+
[InlineData("1000000000000", "BIGINT")]
683+
[InlineData("cast(1000000000000 as unsigned)", "BIGINT")]
684684
[InlineData("1.0", "DECIMAL")]
685685
[InlineData("'text'", "VARCHAR")]
686686
[InlineData("cast('2000-01-02' as date)", "DATE")]
@@ -890,7 +890,7 @@ public void ReturnDerivedTypes()
890890
using (MySqlDataReader reader = command.ExecuteReader())
891891
{
892892
Assert.True(reader.Read());
893-
Assert.Equal(3L, reader.GetValue(0));
893+
Assert.Equal(3L, Convert.ToInt64(reader.GetValue(0)));
894894
Assert.False(reader.Read());
895895
}
896896

tests/SideBySide/TestUtilities.cs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,27 @@ public static void AssertEqual(byte[] expected, byte[] actual)
2222
}
2323
}
2424

25+
/// <summary>
26+
/// Verifies that <paramref name="value"/> is an integer (<see cref="Int32"/> or <see cref="Int64"/>) with the value <code>1</code>.
27+
/// </summary>
28+
public static void AssertIsOne(object value)
29+
{
30+
switch (value)
31+
{
32+
case int intValue:
33+
Assert.Equal(1, intValue);
34+
break;
35+
36+
case long longValue:
37+
Assert.Equal(1L, longValue);
38+
break;
39+
40+
default:
41+
Assert.Equal(1L, value);
42+
break;
43+
}
44+
}
45+
2546
/// <summary>
2647
/// Asserts that <paramref name="stopwatch"/> is in the range [minimumMilliseconds, minimumMilliseconds + lengthMilliseconds].
2748
/// </summary>

0 commit comments

Comments
 (0)