Skip to content

Commit

Permalink
Add test for MySql.Data bug 109390.
Browse files Browse the repository at this point in the history
  • Loading branch information
bgrainger committed Dec 23, 2022
1 parent 331902a commit 6e842cc
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 0 deletions.
1 change: 1 addition & 0 deletions docs/content/tutorials/migrating-from-connector-net.md
Original file line number Diff line number Diff line change
Expand Up @@ -297,4 +297,5 @@ The following bugs in Connector/NET are fixed by switching to MySqlConnector. (~
* [#108970](https://bugs.mysql.com/bug.php?id=108970): `MySqlConnectionStringBuilder.ContainsKey` method gives wrong result
* [#109141](https://bugs.mysql.com/bug.php?id=109141): Insert of data into a table results in `System.ArgumentException`
* [#109331](https://bugs.mysql.com/bug.php?id=109331): MySQL Connector/NET is incompatible with MariaDB 10.10 and later
* [#109390](https://bugs.mysql.com/bug.php?id=109390): Transaction lock held after connection timeout exception
* [#109476](https://bugs.mysql.com/bug.php?id=109476): `TransactionScope.Dispose` throws "Connection must be valid and open to rollback"
64 changes: 64 additions & 0 deletions tests/IntegrationTests/Transaction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,70 @@ public async Task DisposeAsync()
}
#endif

[SkippableFact(MySqlData = "https://bugs.mysql.com/bug.php?id=109390")]
public void TransactionHoldsLocks()
{
using (var connection = new MySqlConnection(AppConfig.ConnectionString))
{
connection.Open();
using var command = connection.CreateCommand();
command.CommandText = """
drop table if exists transaction_locks;
create table transaction_locks(id int not null primary key, val int);
insert into transaction_locks(id, val) values(1, 1);
""";
command.ExecuteNonQuery();
}

using var barrier = new Barrier(2);
using var barrier2 = new Barrier(2);

var task1 = Task.Run(() =>
{
using (var connection = new MySqlConnection(AppConfig.ConnectionString))
{
connection.Open();
using var transaction = connection.BeginTransaction();
using var command = connection.CreateCommand();
command.CommandText = "select * from transaction_locks where id = 1 for update";
command.Transaction = transaction;
command.ExecuteNonQuery();
barrier.SignalAndWait();
barrier2.SignalAndWait();
}
});
var task2 = Task.Run(() =>
{
barrier.SignalAndWait();
using (var connection = new MySqlConnection(AppConfig.ConnectionString))
{
connection.Open();
using var transaction = connection.BeginTransaction();
using var command = connection.CreateCommand();
command.CommandText = "update transaction_locks set val = val + 1 where id = 1";
command.CommandTimeout = 3;
command.Transaction = transaction;
Assert.Throws<MySqlException>(() => command.ExecuteNonQuery());
}
barrier2.SignalAndWait();
using (var connection = new MySqlConnection(AppConfig.ConnectionString))
{
connection.Open();
using var transaction = connection.BeginTransaction();
using var command = connection.CreateCommand();
command.CommandText = "update transaction_locks set val = val + 1 where id = 1";
command.CommandTimeout = 3;
command.Transaction = transaction;
command.ExecuteNonQuery();
transaction.Commit();
}
});

task1.GetAwaiter().GetResult();
Assert.Equal(0, Task.WaitAny(task2, Task.Delay(TimeSpan.FromSeconds(10))));
task2.GetAwaiter().GetResult();
}

readonly TransactionFixture m_database;
readonly MySqlConnection m_connection;
}

0 comments on commit 6e842cc

Please sign in to comment.