Skip to content

Commit

Permalink
Update xunit to 2.5.3.
Browse files Browse the repository at this point in the history
Update AdoNet.Specification.Tests to 2.2.0 Beta 2 to match. Fix xunit analyzer errors.
  • Loading branch information
bgrainger committed Oct 20, 2023
1 parent 021c039 commit 755f1a7
Show file tree
Hide file tree
Showing 11 changed files with 104 additions and 95 deletions.
5 changes: 5 additions & 0 deletions global.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"sdk": {
"version": "7.0.402"
}
}
8 changes: 4 additions & 4 deletions tests/Conformance.Tests/Conformance.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="AdoNet.Specification.Tests" Version="2.0.0-beta.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.7.0" />
<PackageReference Include="xunit" Version="2.4.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
<PackageReference Include="AdoNet.Specification.Tests" Version="2.0.0-beta.2" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.7.2" />
<PackageReference Include="xunit" Version="2.5.3" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.3">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
Expand Down
14 changes: 8 additions & 6 deletions tests/IntegrationTests/CancelTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ public void CancelCommand()
TestUtilities.AssertExecuteScalarReturnsOneOrIsCanceled(cmd);
Assert.InRange(stopwatch.ElapsedMilliseconds, 250, 2500);

#pragma warning disable xUnit1031 // Do not use blocking task operations in test method
task.Wait(); // shouldn't throw
#pragma warning restore xUnit1031 // Do not use blocking task operations in test method
}

#if !MYSQL_DATA
Expand Down Expand Up @@ -246,21 +248,21 @@ public async Task CancelCompletedCommand()
create table cancel_completed_command (
id bigint unsigned,
value varchar(45)
);").ConfigureAwait(false);
);").ConfigureAwait(true);

using (var cmd = m_database.Connection.CreateCommand())
{
cmd.CommandText = @"insert into cancel_completed_command (id, value) values (1, null);";

using (await cmd.ExecuteReaderAsync().ConfigureAwait(false))
using (await cmd.ExecuteReaderAsync().ConfigureAwait(true))
cmd.Cancel();
}

using (var cmd = m_database.Connection.CreateCommand())
{
cmd.CommandText = @"update cancel_completed_command SET value = ""value"" where id = 1;";

await cmd.ExecuteNonQueryAsync().ConfigureAwait(false);
await cmd.ExecuteNonQueryAsync().ConfigureAwait(true);
}

using (var cmd = m_database.Connection.CreateCommand())
Expand Down Expand Up @@ -631,21 +633,21 @@ public async Task CancelCompletedBatch()
create table cancel_completed_command (
id bigint unsigned,
value varchar(45)
);").ConfigureAwait(false);
);").ConfigureAwait(true);

using (var batch = m_database.Connection.CreateBatch())
{
batch.BatchCommands.Add(new MySqlBatchCommand(@"insert into cancel_completed_command (id, value) values (1, null);"));

using (await batch.ExecuteReaderAsync().ConfigureAwait(false))
using (await batch.ExecuteReaderAsync().ConfigureAwait(true))
batch.Cancel();
}

using (var batch = m_database.Connection.CreateBatch())
{
batch.BatchCommands.Add(new MySqlBatchCommand(@"update cancel_completed_command SET value = ""value"" where id = 1;"));

await batch.ExecuteNonQueryAsync().ConfigureAwait(false);
await batch.ExecuteNonQueryAsync().ConfigureAwait(true);
}

using (var cmd = m_database.Connection.CreateCommand())
Expand Down
22 changes: 11 additions & 11 deletions tests/IntegrationTests/ConnectionPool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public async Task ExhaustConnectionPool()
for (int i = 0; i < csb.MaximumPoolSize; i++)
{
var connection = new MySqlConnection(csb.ConnectionString);
await connection.OpenAsync().ConfigureAwait(false);
await connection.OpenAsync().ConfigureAwait(true);
connections.Add(connection);
}

Expand All @@ -71,12 +71,12 @@ public async Task ExhaustConnectionPool()
using (var extraConnection = new MySqlConnection(csb.ConnectionString))
{
var stopwatch = Stopwatch.StartNew();
await extraConnection.OpenAsync().ConfigureAwait(false);
await extraConnection.OpenAsync().ConfigureAwait(true);
stopwatch.Stop();
Assert.InRange(stopwatch.ElapsedMilliseconds, 4500, 7500);
}

closeTask.Wait();
await closeTask.ConfigureAwait(true);

foreach (var connection in connections)
connection.Dispose();
Expand All @@ -96,7 +96,7 @@ public async Task ExhaustConnectionPoolWithTimeout()
for (int i = 0; i < csb.MaximumPoolSize; i++)
{
var connection = new MySqlConnection(csb.ConnectionString);
await connection.OpenAsync().ConfigureAwait(false);
await connection.OpenAsync().ConfigureAwait(true);
connections.Add(connection);
}

Expand Down Expand Up @@ -184,22 +184,22 @@ public async Task CharacterSet()
#endif

// verify that connection charset is the same when retrieving a connection from the pool
await CheckCharacterSetAsync(csb.ConnectionString).ConfigureAwait(false);
await CheckCharacterSetAsync(csb.ConnectionString).ConfigureAwait(false);
await CheckCharacterSetAsync(csb.ConnectionString).ConfigureAwait(false);
await CheckCharacterSetAsync(csb.ConnectionString).ConfigureAwait(true);
await CheckCharacterSetAsync(csb.ConnectionString).ConfigureAwait(true);
await CheckCharacterSetAsync(csb.ConnectionString).ConfigureAwait(true);
}

private async Task CheckCharacterSetAsync(string connectionString)
{
using var connection = new MySqlConnection(connectionString);
await connection.OpenAsync().ConfigureAwait(false);
await connection.OpenAsync().ConfigureAwait(true);
using var cmd = connection.CreateCommand();
cmd.CommandText = @"select @@character_set_client, @@character_set_connection";
using var reader = await cmd.ExecuteReaderAsync().ConfigureAwait(false);
Assert.True(await reader.ReadAsync().ConfigureAwait(false));
using var reader = await cmd.ExecuteReaderAsync().ConfigureAwait(true);
Assert.True(await reader.ReadAsync().ConfigureAwait(true));
Assert.Equal("utf8mb4", reader.GetString(0));
Assert.Equal("utf8mb4", reader.GetString(1));
Assert.False(await reader.ReadAsync().ConfigureAwait(false));
Assert.False(await reader.ReadAsync().ConfigureAwait(true));
}

[Fact]
Expand Down
50 changes: 25 additions & 25 deletions tests/IntegrationTests/DataTypes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public DataTypes(DataTypesFixture database)
[InlineData("UInt64", new[] { 1, 0, 0, 0, 0 }, new[] { false, false, false, true, true })]
public async Task GetBoolean(string column, int[] flags, bool[] values)
{
await DoGetValue(column, (r, n) => r.GetBoolean(n), (r, s) => r.GetBoolean(s), flags, values).ConfigureAwait(false);
await DoGetValue(column, (r, n) => r.GetBoolean(n), (r, s) => r.GetBoolean(s), flags, values).ConfigureAwait(true);
}

[Theory]
Expand All @@ -62,7 +62,7 @@ public async Task GetBoolean(string column, int[] flags, bool[] values)
[InlineData("UInt64", new[] { 1, 0, 0, 2, 2 }, new short[] { 0, 0, 0, 0, 0 })]
public async Task GetInt16(string column, int[] flags, short[] values)
{
await DoGetValue(column, (r, n) => r.GetInt16(n), (r, s) => r.GetInt16(s), flags, values).ConfigureAwait(false);
await DoGetValue(column, (r, n) => r.GetInt16(n), (r, s) => r.GetInt16(s), flags, values).ConfigureAwait(true);
}

[Theory]
Expand All @@ -78,7 +78,7 @@ public async Task GetInt16(string column, int[] flags, short[] values)
[InlineData("UInt64", new[] { 1, 0, 0, 2, 2 }, new[] { 0, 0, 0, 0, 0 })]
public async Task GetInt32(string column, int[] flags, int[] values)
{
await DoGetValue(column, (r, n) => r.GetInt32(n), (r, s) => r.GetInt32(s), flags, values).ConfigureAwait(false);
await DoGetValue(column, (r, n) => r.GetInt32(n), (r, s) => r.GetInt32(s), flags, values).ConfigureAwait(true);
}

[Theory]
Expand All @@ -94,7 +94,7 @@ public async Task GetInt32(string column, int[] flags, int[] values)
[InlineData("UInt64", new[] { 1, 0, 0, 2, 0 }, new[] { 0L, 0, 0, 0, 1234567890123456789 })]
public async Task GetInt64(string column, int[] flags, long[] values)
{
await DoGetValue(column, (r, n) => r.GetInt64(n), (r, s) => r.GetInt64(s), flags, values).ConfigureAwait(false);
await DoGetValue(column, (r, n) => r.GetInt64(n), (r, s) => r.GetInt64(s), flags, values).ConfigureAwait(true);
}

[Theory]
Expand All @@ -110,7 +110,7 @@ public async Task GetInt64(string column, int[] flags, long[] values)
[InlineData("UInt64", new[] { 1, 0, 0, 2, 2 }, new ushort[] { 0, 0, 0, 0, 0 })]
public async Task GetUInt16(string column, int[] flags, ushort[] values)
{
await DoGetValue(column, (r, n) => r.GetUInt16(n), (r, s) => r.GetUInt16(s), flags, values).ConfigureAwait(false);
await DoGetValue(column, (r, n) => r.GetUInt16(n), (r, s) => r.GetUInt16(s), flags, values).ConfigureAwait(true);
}

[Theory]
Expand All @@ -126,7 +126,7 @@ public async Task GetUInt16(string column, int[] flags, ushort[] values)
[InlineData("UInt64", new[] { 1, 0, 0, 2, 2 }, new uint[] { 0, 0, 0, 0, 0 })]
public async Task GetUInt32(string column, int[] flags, uint[] values)
{
await DoGetValue(column, (r, n) => r.GetUInt32(n), (r, s) => r.GetUInt32(s), flags, values).ConfigureAwait(false);
await DoGetValue(column, (r, n) => r.GetUInt32(n), (r, s) => r.GetUInt32(s), flags, values).ConfigureAwait(true);
}

[Theory]
Expand All @@ -142,17 +142,17 @@ public async Task GetUInt32(string column, int[] flags, uint[] values)
[InlineData("UInt64", new[] { 1, 0, 0, 0, 0 }, new ulong[] { 0, 0, 0, 18446744073709551615, 1234567890123456789 })]
public async Task GetUInt64(string column, int[] flags, ulong[] values)
{
await DoGetValue(column, (r, n) => r.GetUInt64(n), (r, s) => r.GetUInt64(s), flags, values).ConfigureAwait(false);
await DoGetValue(column, (r, n) => r.GetUInt64(n), (r, s) => r.GetUInt64(s), flags, values).ConfigureAwait(true);
}

private async Task DoGetValue<T>(string column, Func<MySqlDataReader, int, T> getInt, Func<MySqlDataReader, string, T> getIntByName, int[] flags, T[] values)
{
using var cmd = Connection.CreateCommand();
cmd.CommandText = $"select {column} from datatypes_integers order by rowid";
using var reader = (MySqlDataReader) await cmd.ExecuteReaderAsync().ConfigureAwait(false);
using var reader = (MySqlDataReader) await cmd.ExecuteReaderAsync().ConfigureAwait(true);
for (int i = 0; i < flags.Length; i++)
{
Assert.True(await reader.ReadAsync().ConfigureAwait(false));
Assert.True(await reader.ReadAsync().ConfigureAwait(true));
switch (flags[i])
{
case 0: // normal
Expand All @@ -161,7 +161,7 @@ private async Task DoGetValue<T>(string column, Func<MySqlDataReader, int, T> ge
break;

case 1: // null
Assert.True(await reader.IsDBNullAsync(0).ConfigureAwait(false));
Assert.True(await reader.IsDBNullAsync(0).ConfigureAwait(true));
break;

case 2: // overflow
Expand All @@ -170,8 +170,8 @@ private async Task DoGetValue<T>(string column, Func<MySqlDataReader, int, T> ge
break;
}
}
Assert.False(await reader.ReadAsync().ConfigureAwait(false));
Assert.False(await reader.NextResultAsync().ConfigureAwait(false));
Assert.False(await reader.ReadAsync().ConfigureAwait(true));
Assert.False(await reader.NextResultAsync().ConfigureAwait(true));
}

[Theory]
Expand Down Expand Up @@ -442,17 +442,17 @@ public async Task QueryWithGuidParameter(bool oldGuids)
var csb = CreateConnectionStringBuilder();
csb.OldGuids = oldGuids;
using var connection = new MySqlConnection(csb.ConnectionString);
await connection.OpenAsync().ConfigureAwait(false);
await connection.OpenAsync().ConfigureAwait(true);
try
{
Assert.Equal(oldGuids ? 0L : 1L, (await connection.QueryAsync<long>(@"select count(*) from datatypes_strings where guid = @guid", new { guid = new Guid("fd24a0e8-c3f2-4821-a456-35da2dc4bb8f") }).ConfigureAwait(false)).SingleOrDefault());
Assert.Equal(oldGuids ? 0L : 1L, (await connection.QueryAsync<long>(@"select count(*) from datatypes_strings where guidbin = @guid", new { guid = new Guid("fd24a0e8-c3f2-4821-a456-35da2dc4bb8f") }).ConfigureAwait(false)).SingleOrDefault());
Assert.Equal(oldGuids ? 0L : 1L, (await connection.QueryAsync<long>(@"select count(*) from datatypes_strings where guid = @guid", new { guid = new Guid("fd24a0e8-c3f2-4821-a456-35da2dc4bb8f") }).ConfigureAwait(true)).SingleOrDefault());
Assert.Equal(oldGuids ? 0L : 1L, (await connection.QueryAsync<long>(@"select count(*) from datatypes_strings where guidbin = @guid", new { guid = new Guid("fd24a0e8-c3f2-4821-a456-35da2dc4bb8f") }).ConfigureAwait(true)).SingleOrDefault());
}
catch (MySqlException ex) when (oldGuids && ex.Number is 1300 or 3854) // InvalidCharacterString, CannotConvertString
{
// new error in MySQL 8.0.24, MariaDB 10.5
}
Assert.Equal(oldGuids ? 1L : 0L, (await connection.QueryAsync<long>(@"select count(*) from datatypes_blobs where guidbin = @guid", new { guid = new Guid(0x33221100, 0x5544, 0x7766, 0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF) }).ConfigureAwait(false)).SingleOrDefault());
Assert.Equal(oldGuids ? 1L : 0L, (await connection.QueryAsync<long>(@"select count(*) from datatypes_blobs where guidbin = @guid", new { guid = new Guid(0x33221100, 0x5544, 0x7766, 0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF) }).ConfigureAwait(true)).SingleOrDefault());
}

[Theory]
Expand All @@ -464,14 +464,14 @@ public async Task GetGuid(string column, Type fieldType)
{
using var cmd = Connection.CreateCommand();
cmd.CommandText = $"select `{column}` from datatypes_guids order by rowid";
using var reader = await cmd.ExecuteReaderAsync().ConfigureAwait(false);
using var reader = await cmd.ExecuteReaderAsync().ConfigureAwait(true);
Assert.Equal(fieldType, reader.GetFieldType(0));

Assert.True(await reader.ReadAsync().ConfigureAwait(false));
Assert.True(await reader.ReadAsync().ConfigureAwait(true));
Assert.True(reader.IsDBNull(0));
Assert.Throws<GetGuidWhenNullException>(() => reader.GetGuid(0));

Assert.True(await reader.ReadAsync().ConfigureAwait(false));
Assert.True(await reader.ReadAsync().ConfigureAwait(true));
Assert.False(reader.IsDBNull(0));
Assert.NotNull(reader.GetValue(0));
Assert.IsType(fieldType, reader.GetValue(0));
Expand All @@ -484,17 +484,17 @@ public async Task GetGuid(string column, Type fieldType)
#endif
Assert.Throws(exceptionType, () => reader.GetGuid(0));

Assert.True(await reader.ReadAsync().ConfigureAwait(false));
Assert.True(await reader.ReadAsync().ConfigureAwait(true));
Assert.NotNull(reader.GetValue(0));
Assert.IsType(fieldType, reader.GetValue(0));
Assert.Equal(new Guid("33221100-5544-7766-8899-aabbccddeeff"), reader.GetGuid(0));

Assert.True(await reader.ReadAsync().ConfigureAwait(false));
Assert.True(await reader.ReadAsync().ConfigureAwait(true));
Assert.NotNull(reader.GetValue(0));
Assert.IsType(fieldType, reader.GetValue(0));
Assert.Equal(new Guid("33221100-5544-7766-8899-aabbccddeeff"), reader.GetGuid(0));

Assert.False(await reader.ReadAsync().ConfigureAwait(false));
Assert.False(await reader.ReadAsync().ConfigureAwait(true));
}

#if !MYSQL_DATA
Expand Down Expand Up @@ -842,7 +842,7 @@ public async Task InsertLargeBlobAsync(string column, int size)
try
{
cmd.Parameters.AddWithValue("@data", data);
await cmd.ExecuteNonQueryAsync().ConfigureAwait(false);
await cmd.ExecuteNonQueryAsync().ConfigureAwait(true);
lastInsertId = cmd.LastInsertedId;
Assert.True(isSupported);
}
Expand All @@ -857,10 +857,10 @@ public async Task InsertLargeBlobAsync(string column, int size)

if (isSupported)
{
var queryResult = (await connection.QueryAsync<byte[]>($"select `{column}` from datatypes_blob_insert where rowid = {lastInsertId}").ConfigureAwait(false)).Single();
var queryResult = (await connection.QueryAsync<byte[]>($"select `{column}` from datatypes_blob_insert where rowid = {lastInsertId}").ConfigureAwait(true)).Single();
TestUtilities.AssertEqual(data, queryResult);

await connection.ExecuteAsync($"delete from datatypes_blob_insert where rowid = {lastInsertId}").ConfigureAwait(false);
await connection.ExecuteAsync($"delete from datatypes_blob_insert where rowid = {lastInsertId}").ConfigureAwait(true);
}
}

Expand Down
6 changes: 3 additions & 3 deletions tests/IntegrationTests/IntegrationTests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@

<ItemGroup>
<!--testing packages-->
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.7.0" />
<PackageReference Include="xunit" Version="2.5.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.0">
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.7.2" />
<PackageReference Include="xunit" Version="2.5.3" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.3">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
Expand Down
16 changes: 8 additions & 8 deletions tests/IntegrationTests/QueryTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -469,8 +469,8 @@ public async Task DoubleDispose()
{
using var cmd = m_database.Connection.CreateCommand();
cmd.CommandText = @"select 1;";
using var reader = await cmd.ExecuteReaderAsync().ConfigureAwait(false);
Assert.True(await reader.ReadAsync().ConfigureAwait(false));
using var reader = await cmd.ExecuteReaderAsync().ConfigureAwait(true);
Assert.True(await reader.ReadAsync().ConfigureAwait(true));
reader.Dispose();
reader.Dispose();
}
Expand All @@ -481,15 +481,15 @@ public async Task MultipleStatementsWithInvalidSql()
using var cmd = m_database.Connection.CreateCommand();
cmd.CommandText = @"select 1; select 1 from mysql.abc; select 2;";

using var reader = await cmd.ExecuteReaderAsync().ConfigureAwait(false);
Assert.True(await reader.ReadAsync().ConfigureAwait(false));
using var reader = await cmd.ExecuteReaderAsync().ConfigureAwait(true);
Assert.True(await reader.ReadAsync().ConfigureAwait(true));
Assert.Equal(1, reader.GetInt32(0));
Assert.False(await reader.ReadAsync().ConfigureAwait(false));
Assert.False(await reader.ReadAsync().ConfigureAwait(true));

await Assert.ThrowsAsync<MySqlException>(() => reader.NextResultAsync());
Assert.False(await reader.ReadAsync().ConfigureAwait(false));
Assert.False(await reader.ReadAsync().ConfigureAwait(true));

Assert.False(await reader.NextResultAsync().ConfigureAwait(false));
Assert.False(await reader.NextResultAsync().ConfigureAwait(true));
}

[Fact]
Expand Down Expand Up @@ -521,7 +521,7 @@ public async Task GetEnumerator()
using (var cmd = m_database.Connection.CreateCommand())
{
cmd.CommandText = @"select value from query_enumerator order by value asc;";
using var reader = await cmd.ExecuteReaderAsync().ConfigureAwait(false);
using var reader = await cmd.ExecuteReaderAsync().ConfigureAwait(true);
Assert.Equal(new[] { "four", "one", "three", "two" }, reader.Cast<IDataRecord>().Select(x => x.GetString(0)));
}
}
Expand Down
Loading

0 comments on commit 755f1a7

Please sign in to comment.