Skip to content

Commit 1e592aa

Browse files
authored
Merge pull request #537 from Particular/fix-flaky-test-3.4
Fix flaky test 3.4
2 parents da62710 + 1961663 commit 1e592aa

File tree

3 files changed

+53
-3
lines changed

3 files changed

+53
-3
lines changed

src/NServiceBus.TransactionalSession.AcceptanceTests/When_using_outbox_and_audit_enabled.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ public async Task Should_not_audit_the_control_message(bool commitHappensAfterCo
2323
var options = new CustomTestingPersistenceOpenSessionOptions
2424
{
2525
TransactionCommitTaskCompletionSource = ctx.TransactionCommitTaskCompletionSource,
26-
CommitDelayIncrement = TimeSpan.FromSeconds(500)
26+
CommitDelayIncrement = TimeSpan.FromSeconds(500),
27+
MaximumCommitDuration = TimeSpan.FromSeconds(2)
2728
};
2829

2930
if (!commitHappensAfterControlMessage)
@@ -48,6 +49,7 @@ public async Task Should_not_audit_the_control_message(bool commitHappensAfterCo
4849
class Context : TransactionalSessionTestContext
4950
{
5051
public bool SampleMessageAudited { get; set; }
52+
public bool CompleteTestMessageAudited { get; set; }
5153
public bool ControlMessageWasAudited { get; set; }
5254
public bool TestComplete { get; set; }
5355

@@ -117,6 +119,11 @@ public override Task Invoke(ITransportReceiveContext context, Func<Task> next)
117119
}
118120

119121
if (messageType.Contains(nameof(CompleteTestMessage)))
122+
{
123+
testContext.CompleteTestMessageAudited = true;
124+
}
125+
126+
if (testContext.SampleMessageAudited && testContext.CompleteTestMessageAudited)
120127
{
121128
testContext.TestComplete = true;
122129
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
namespace NServiceBus.TransactionalSession.Tests;
2+
3+
using System;
4+
using NUnit.Framework;
5+
6+
public class OpenSessionOptionsTests
7+
{
8+
[Test]
9+
public void Should_not_throw_exception_when_commit_delay_increment_is_greater_than_zero() =>
10+
Assert.DoesNotThrow(() =>
11+
{
12+
var options = new CustomTestingPersistenceOpenSessionOptions
13+
{
14+
CommitDelayIncrement = TimeSpan.FromTicks(1),
15+
MaximumCommitDuration = TimeSpan.FromSeconds(8)
16+
};
17+
});
18+
19+
[Test]
20+
[TestCase(-1)]
21+
[TestCase(0)]
22+
public void Should_throw_exception_when_commit_delay_increment_is_less_than_or_equal_to_zero(int commitDelayIncrement) =>
23+
Assert.Throws<ArgumentOutOfRangeException>(() =>
24+
{
25+
var options = new CustomTestingPersistenceOpenSessionOptions
26+
{
27+
CommitDelayIncrement = TimeSpan.FromSeconds(commitDelayIncrement),
28+
MaximumCommitDuration = TimeSpan.FromSeconds(8)
29+
};
30+
});
31+
32+
class CustomTestingPersistenceOpenSessionOptions : OpenSessionOptions;
33+
}
34+

src/NServiceBus.TransactionalSession/OpenSessionOptions.cs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,17 @@ public abstract class OpenSessionOptions
3737
/// <summary>
3838
/// The time increment used to delay the commit of the transactional session when the outbox record is not yet in the storage.
3939
/// </summary>
40-
/// <remarks>Defaults to <code>TimeSpan.FromSeconds(2)</code></remarks>
41-
public TimeSpan CommitDelayIncrement { get; set; } = TimeSpan.FromSeconds(2);
40+
/// <remarks>Defaults to <code>TimeSpan.FromSeconds(2)</code>. Value must be greater than <code>TimeSpan.Zero</code>.</remarks>
41+
public TimeSpan CommitDelayIncrement
42+
{
43+
get => commitDelayIncrement;
44+
set
45+
{
46+
ArgumentOutOfRangeException.ThrowIfLessThanOrEqual(value, TimeSpan.Zero, nameof(CommitDelayIncrement));
47+
commitDelayIncrement = value;
48+
}
49+
}
4250

4351
Dictionary<string, string>? metadata;
52+
TimeSpan commitDelayIncrement = TimeSpan.FromSeconds(2);
4453
}

0 commit comments

Comments
 (0)