-
Notifications
You must be signed in to change notification settings - Fork 934
Fix NH-3023 test #1501
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix NH-3023 test #1501
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,14 +3,16 @@ | |
using System.Threading; | ||
using System.Transactions; | ||
using log4net; | ||
using NHibernate.Util; | ||
using NUnit.Framework; | ||
|
||
namespace NHibernate.Test.NHSpecificTest.NH3023 | ||
{ | ||
public partial class DeadlockHelper | ||
{ | ||
private static readonly ILog _log = LogManager.GetLogger(typeof(DeadlockHelper)); | ||
|
||
public void ForceDeadlockOnConnection(SqlConnection connection) | ||
public void ForceDeadlockOnConnection(SqlConnection connection, string connectionString) | ||
{ | ||
using (var victimLock = new SemaphoreSlim(0)) | ||
using (var winnerLock = new SemaphoreSlim(0)) | ||
|
@@ -27,7 +29,7 @@ public void ForceDeadlockOnConnection(SqlConnection connection) | |
{ | ||
using (var scope = new TransactionScope(TransactionScopeOption.RequiresNew)) | ||
{ | ||
using (var cxn = new SqlConnection(connection.ConnectionString + ";Pooling=No")) | ||
using (var cxn = new SqlConnection(connectionString + ";Pooling=No")) | ||
{ | ||
cxn.Open(); | ||
DeadlockParticipant(cxn, false, winnerLock, victimLock); | ||
|
@@ -38,6 +40,7 @@ public void ForceDeadlockOnConnection(SqlConnection connection) | |
catch (Exception ex) | ||
{ | ||
winnerEx = ex; | ||
winnerLock.Release(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In case of early failure of the winner thread, the "loser thread" was stuck for 2 minutes. Better release him. |
||
} | ||
}); | ||
|
||
|
@@ -57,6 +60,8 @@ public void ForceDeadlockOnConnection(SqlConnection connection) | |
if (winnerEx != null) | ||
_log.Warn("Winner thread failed", winnerEx); | ||
} | ||
// If getting here, expected victim has not fail. If expected winner has failed instead, fail the test. | ||
Assert.That(winnerEx, Is.Null); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In case of winner thread failure while loser thread does not fail, the test was "succeeding". Prevent this. |
||
|
||
// | ||
// Should never get here | ||
|
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
connection.ConnectionString
is purged from password, when there is one. This causes the winner thread to fail in such case.