-
Notifications
You must be signed in to change notification settings - Fork 1.3k
CSHARP-5695: CSOT: Unified test spec runner #1758
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
Conversation
|
||
var stream = new NetworkStream(socket, true); | ||
|
||
if (_settings.ReadTimeout.HasValue) |
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.
Read and Write timeout now is being applied by BinaryConnection.
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.
I had to move this out, because socketTimeout is deprecated by CSOT timeout if it was provided. So we have to apply both in the same level, otherwise it could be a confusion which timeout should be enforced. Even if we applied socket_timeout here briefly and remove on BinaryConnection, we could run into socket timeout when SSL stream authentication.
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.
Initial review
src/MongoDB.Driver/Core/WireProtocol/CommandUsingCommandMessageWireProtocol.cs
Show resolved
Hide resolved
var waitQueueTimeout = _pool.Settings.WaitQueueTimeout; | ||
if (operationContext.RemainingTimeout != Timeout.InfiniteTimeSpan) | ||
{ | ||
waitQueueTimeout = operationContext.RemainingTimeout < _pool.Settings.WaitQueueTimeout ? operationContext.RemainingTimeout : _pool.Settings.WaitQueueTimeout; |
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.
Don't we need Max(TimeSpan) extension method yet :) ?
And then MaxIgnoreInfinite
...
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.
Code was rewritten a little to be more readable.
@@ -223,7 +244,8 @@ public async Task<IConnectionHandle> AcquireConnectionAsync(OperationContext ope | |||
|
|||
using (var connectionCreator = new ConnectionCreator(_pool)) | |||
{ | |||
pooledConnection = await connectionCreator.CreateOpenedOrReuseAsync(operationContext).ConfigureAwait(false); | |||
waitQueueTimeout = _pool.CalculateRemainingTimeout(waitQueueTimeout, stopwatch); | |||
pooledConnection = await connectionCreator.CreateOpenedOrReuseAsync(operationContext, waitQueueTimeout - stopwatch.Elapsed).ConfigureAwait(false); |
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.
Is this correct?
waitQueueTimeout := waitQueueTimeout - elapsed
// Remaining
And then another waitQueueTimeout - stopwatch.Elapsed (==waitQueueTimeout - elapsed * 2)
in
CreateOpenedOrReuseAsync(operationContext, waitQueueTimeout - stopwatch.Elapsed)
?
If this is a bug, no tests to catch this?
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.
Good catch! Thank you! I've spotted the problem in sync code path, but forget to do the same fix into async code-path.
Fixed.
src/MongoDB.Driver/Core/WireProtocol/CommandUsingCommandMessageWireProtocol.cs
Show resolved
Hide resolved
while (count > 0) | ||
{ | ||
var timeout = hasOperationTimeout ? operationContext.RemainingTimeout : streamTimeout; | ||
var timeout = operationContext.Timeout == null ? socketTimeout : operationContext.RemainingTimeout; |
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.
.RemainingTimeoutOrDefaut(defaultTimeout)
?
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.
Done.
@@ -223,7 +244,8 @@ public async Task<IConnectionHandle> AcquireConnectionAsync(OperationContext ope | |||
|
|||
using (var connectionCreator = new ConnectionCreator(_pool)) | |||
{ | |||
pooledConnection = await connectionCreator.CreateOpenedOrReuseAsync(operationContext).ConfigureAwait(false); | |||
waitQueueTimeout = _pool.CalculateRemainingTimeout(waitQueueTimeout, stopwatch); | |||
pooledConnection = await connectionCreator.CreateOpenedOrReuseAsync(operationContext, waitQueueTimeout).ConfigureAwait(false); |
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.
So no failing tests for this previous issue?
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.
cc @sanych-sun
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.
Non of existing tests were failing.
SkipNotSupportedTestCases("timeoutMS applies to whole operation, not individual attempts"); // blocked by DRIVERS-3247 | ||
SkipNotSupportedTestCases("WaitQueueTimeoutError does not clear the pool"); // TODO: CSOT: TimeoutMS is not implemented yet for runCommand | ||
SkipNotSupportedTestCases("write concern error MaxTimeMSExpired is transformed"); // TODO: CSOT: investigate error transformation, implementing the requirement might be breaking change | ||
SkipNotSupportedTestCases("operation succeeds after one socket timeout - listDatabases on client"); // TODO: listDatabases is not retryable in CSharp Driver, NEED TICKET!!! |
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.
TODO :)
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.
Ticket created :)
@@ -317,17 +317,17 @@ void ICoreSessionInternal.CommitTransaction(CommitTransactionOptions options, Ca | |||
|
|||
try | |||
{ | |||
var firstAttempt = CreateCommitTransactionOperation(IsFirstCommitAttemptRetry()); | |||
var firstAttempt = CreateCommitTransactionOperation(operationContext,IsFirstCommitAttemptRetry()); |
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.
missing space after comma
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.
Fixed.
{ | ||
// unpin server if needed, then ignore exception and retry | ||
TransactionHelper.UnpinServerIfNeededOnRetryableCommitException(_currentTransaction, exception); | ||
} | ||
|
||
var secondAttempt = CreateCommitTransactionOperation(isCommitRetry: true); | ||
var secondAttempt = CreateCommitTransactionOperation(operationContext,isCommitRetry: true); |
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.
missing space after comma
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.
Fixed.
@@ -33,7 +34,7 @@ public void Compress(Stream input, Stream output) | |||
{ | |||
var uncompressedSize = (int)(input.Length - input.Position); | |||
var uncompressedBytes = new byte[uncompressedSize]; // does not include uncompressed message headers | |||
input.ReadBytes(OperationContext.NoTimeout, uncompressedBytes, offset: 0, count: uncompressedSize); | |||
input.ReadBytes(OperationContext.NoTimeout, uncompressedBytes, offset: 0, count: uncompressedSize, Timeout.InfiniteTimeSpan); |
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.
Could you use a named argument for the socketTimeout here? so its clear at a glance what that Timeout value at the end is for.
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.
Done.
break; | ||
case "readConcern": | ||
options = options ?? new TransactionOptions(); | ||
options = options.With(readConcern: ReadConcern.FromBsonDocument(argument.Value.AsBsonDocument)); | ||
readConcern =ReadConcern.FromBsonDocument(argument.Value.AsBsonDocument); |
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.
missing space after =
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.
Fixed.
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.
Few minor comments
@@ -223,7 +244,8 @@ public async Task<IConnectionHandle> AcquireConnectionAsync(OperationContext ope | |||
|
|||
using (var connectionCreator = new ConnectionCreator(_pool)) | |||
{ | |||
pooledConnection = await connectionCreator.CreateOpenedOrReuseAsync(operationContext).ConfigureAwait(false); | |||
waitQueueTimeout = _pool.CalculateRemainingTimeout(waitQueueTimeout, stopwatch); | |||
pooledConnection = await connectionCreator.CreateOpenedOrReuseAsync(operationContext, waitQueueTimeout).ConfigureAwait(false); |
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.
cc @sanych-sun
public static bool IsRootContextTimeoutConfigured(this OperationContext operationContext) => | ||
operationContext.RootContext.Timeout.HasValue; | ||
|
||
public static TimeSpan RemainingTimeoutOrDefault(this OperationContext operationContext, TimeSpan defaultValue) => |
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.
Worth adding a test.
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.
OperationContextExtensionsTests test class was created.
@@ -322,6 +321,7 @@ private HelloResult GetHelloResult( | |||
|
|||
private void Heartbeat(CancellationToken cancellationToken) | |||
{ | |||
using var operationContext = new OperationContext(null, cancellationToken); |
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.
I would rather not have this unless there is a timeout that encompasses the entire heartbeat cycle (I doubt we have that). InitializeConnection
and GetHelloResult
could use their own independent OperationContext instances.
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.
As it was discussed offline: we will keep the code as is for now.
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.
LGTM + nit comment
using MongoDB.Driver.Core.Misc; | ||
using Xunit; | ||
|
||
namespace MongoDB.Driver.Tests |
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.
File scoped namespace?
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.
LGTM
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.
LGTM
No description provided.