-
Notifications
You must be signed in to change notification settings - Fork 70
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Round sub-milliseconds up to the next milliseconds on transaction tim…
…eout (#720) * Round sub-milliseconds up to the next milliseconds on transaction timeout. * Minor tidying * Fixup * Fix failing tests * Added non-integer milliseconds to tests * blacklist test that is failing in .NET * xml docs * Fix mutating default Tx Config --------- Co-authored-by: grant lodge <[email protected]>
- Loading branch information
1 parent
1a5e46d
commit fecc2f0
Showing
7 changed files
with
124 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
Neo4j.Driver/Neo4j.Driver.Tests/Internal/Util/TransactionTimeoutTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
// Copyright (c) "Neo4j" | ||
// Neo4j Sweden AB [http://neo4j.com] | ||
// | ||
// This file is part of Neo4j. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"). | ||
// You may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
using System; | ||
using FluentAssertions; | ||
using Moq; | ||
using Moq.AutoMock; | ||
using Xunit; | ||
|
||
namespace Neo4j.Driver.Internal.Util | ||
{ | ||
public class TransactionTimeoutTests | ||
{ | ||
[Theory] | ||
[InlineData(0, 0, 0)] | ||
[InlineData(0, 1, 1)] | ||
[InlineData(0.1, 0, 1)] | ||
[InlineData(1, 0, 1)] | ||
[InlineData(1, 1, 2)] | ||
[InlineData(1.23, 0, 2)] | ||
[InlineData(598, 1, 599)] | ||
[InlineData(598.2, 0, 599)] | ||
[InlineData(2000, 96, 2001)] | ||
[InlineData(2000.8, 0, 2001)] | ||
public void ShouldRoundSubmillisecondTimeoutsToMilliseconds( | ||
double milliseconds, | ||
int ticks, | ||
int expectedMilliseconds) | ||
{ | ||
var inputMilliseconds = TimeSpan.FromMilliseconds(milliseconds); | ||
var inputTicks = TimeSpan.FromTicks(ticks); | ||
var totalInput = inputMilliseconds + inputTicks; | ||
var expectedTimeout = TimeSpan.FromMilliseconds(expectedMilliseconds); | ||
|
||
var autoMocker = new AutoMocker(MockBehavior.Strict); | ||
if (expectedTimeout != inputMilliseconds) | ||
{ | ||
// only logs if it changes the timeout | ||
autoMocker.GetMock<ILogger>() | ||
.Setup( | ||
x => x.Info( | ||
It.Is<string>(s => s.Contains("rounded up")), | ||
It.IsAny<object[]>())) | ||
.Verifiable(); | ||
} | ||
|
||
var sut = | ||
new TransactionConfigBuilder(autoMocker.GetMock<ILogger>().Object, TransactionConfig.Default) | ||
.WithTimeout(totalInput); | ||
|
||
var result = sut.Build().Timeout; | ||
|
||
result.Should().Be(expectedTimeout); | ||
(result?.Ticks % TimeSpan.TicksPerMillisecond).Should().Be(0); | ||
autoMocker.VerifyAll(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters