public static void TestCase_TransactionTimeout(bool promote)
{
string testCaseDescription = string.Format(
"TestCase_TransactionTimeout promote={0}",
promote
);
Trace("**** " + testCaseDescription + " ****");
AutoResetEvent pspeCompleted = new AutoResetEvent(false);
NonMSDTCPromoterEnlistment pspe = null;
Assert.Throws<TransactionAbortedException>(() =>
{
CommittableTransaction tx = new CommittableTransaction(TimeSpan.FromSeconds(1));
pspe = (NonMSDTCPromoterEnlistment)CreatePSPEEnlistment(NonMsdtcPromoterTests.PromoterType1,
NonMsdtcPromoterTests.PromotedToken1,
pspeCompleted,
/*nonMSDTC = */ true,
tx,
/*spcResponse=*/ TransactionStatus.Committed,
/*expectRejection=*/ false
);
if (promote)
{
Promote(testCaseDescription, NonMsdtcPromoterTests.PromotedToken1, tx);
}
NoStressTrace(string.Format("There will be a 3 second delay here - {0}", DateTime.Now.ToString()));
Task.Delay(TimeSpan.FromSeconds(3)).Wait();
NoStressTrace(string.Format("Woke up from sleep. Attempting Commit - {0}", DateTime.Now.ToString()));
tx.Commit();
});
Assert.True(pspeCompleted.WaitOne(TimeSpan.FromSeconds(5)));
if (promote)
{
Assert.True(pspe.Promoted);
}
else
{
Assert.False(pspe.Promoted);
}
Assert.True(pspe.Aborted);
TestPassed(true);
}