Skip to content
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

CSHARP-3678: Convert transactions spec tests to unified test format #1586

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

sanych-sun
Copy link
Member

@sanych-sun sanych-sun commented Jan 6, 2025

This PR will close the following Jira tickets:

  1. CSHARP-3678: Convert transactions spec tests to unified test format - PARTIAL! There were changes to transactions-convenient-api specs, which is not syncing in this PR, will do as a separate PR to reduce it's size.
  2. CSHARP-4966: Revise runOnRequirements for transaction tests incompatible with load balancers

NOTICE: Some spec tests contains changes done locally, that has to be processed to spec repository at first. I'm discussing the changes with spec owners and will create PR to spec repo shortly.

@sanych-sun sanych-sun requested a review from a team as a code owner January 6, 2025 20:40
@sanych-sun sanych-sun requested review from JamesKovacs and removed request for a team January 6, 2025 20:40
SpinWait.SpinUntil(() => _server.Description.State == ServerState.Connected, 1000);
if (!SpinWait.SpinUntil(() => _server.Description.State == ServerState.Connected, 1000))
{
throw new InvalidOperationException("Server is not connected.");
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's better to throw here, to avoid getting cryptic exception ("pool is in paused state").

throw new SkipException("Skipped because CSharp Driver has an issue with handling read timeout for sync code-path.");
}

if (CoreTestConfiguration.Cluster.Description.Type == ClusterType.Sharded &&
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have to skip these tests for MongoDB sharded cluster 4.2, as they are not compatible with it. Confirmed with Java team, they have to skip them as well: https://github.com/mongodb/mongo-java-driver/blob/08880c810b76f8c8d165f6ce66c83060c7bc93c5/driver-sync/src/test/functional/com/mongodb/client/unified/UnifiedTestModifications.java#L244

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a comment stating that these tests are not compatible with MongoDB 4.2. Otherwise it is not clear why we only run them for 4.4+.

{
if (testCase.Name.Contains("add RetryableWriteError and UnknownTransactionCommitResult labels to connection errors"))
{
throw new SkipException("Skipped because CSharp Driver has an issue with handling read timeout for sync code-path.");
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is test that is failing in sync path because authors of the test trying to emulate network error, by setting fail point that blocks connection for longer then read timeout - so driver should abort the connection and get network error. That test works as expected for ASYNC path because we manually apply read timeout, but not for SYNC path. It worth to investigate and do the same for sync path as well, but as discussed with Boris - we probably will postpone it and will do in scope of CSOT implementation.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reasonable. I would file a CSHARP ticket and note its number here so that we don't lose it.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@@ -1,24 +0,0 @@
/* Copyright 2020-present MongoDB Inc.
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This interface was used to have a special case for failpoint operations to store them in a specialized collection for later disposal. This PR introducing a new method in EntityMap that let register any IDisposable for disposal after test execution.

var creator = new UnifiedEntityMapCreator(eventFormatters, loggingSettings);
return new UnifiedEntityMap(creator, async);
}
=> new(eventFormatters, loggingSettings, async);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We use to have EntityMap kind of immutable (we created a new EntityMap for each CreateEntity operation, and in case of nested create entities operations - we merge them together), but in this PR I've run into a situation when CreateEntity operation inside of test references entities created by another CreateEntity operation. So it should have access to entity map created earlier... I've decided to let CreateEntity operation instead of creating and merging to simply modify single entity map.

{
var cluster = _client.GetClusterInternal();
var session = NoCoreSession.NewHandle();

failPoint = FailPoint.Configure(cluster, session, _failPointCommand, _async);
var failPoint = FailPoint.Configure(cluster, session, _failPointCommand, _async);
_entityMap.RegisterForDispose(failPoint);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We register created failpoint for disposal together with entityMap, instead of returning it and letting test runner dispose them.

{
var pinnedServer = _session?.WrappedCoreSession?.CurrentTransaction?.PinnedServer;
var pinnedServer = _session?.WrappedCoreSession?.CurrentTransaction?.PinnedServer.EndPoint;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We cannot use the same cluster as provided session, because in several test cases we setup failPoint for hello command, which will turn cluster to be disconnected so disposal of the failPoint will throw (connection pool is paused state error). So have to use another client to configure failPoints.

if (pinnedServer == null)
{
throw new InvalidOperationException("UnifiedTargetedFailPointOperation requires a pinned server.");
}

var client = DriverTestConfiguration.CreateMongoClient(useMultipleShardRouters: true);
_entityMap.RegisterForDispose(client);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have to register for disposal both: created client and failPoint itself.

@@ -161,13 +159,6 @@ public void Dispose()
{
_logger.LogDebug("Disposing");

if (_failPoints != null)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Disposed together with entityMap.

Copy link
Contributor

@JamesKovacs JamesKovacs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Minor comments for your consideration but nothing blocking.

{
if (testCase.Name.Contains("add RetryableWriteError and UnknownTransactionCommitResult labels to connection errors"))
{
throw new SkipException("Skipped because CSharp Driver has an issue with handling read timeout for sync code-path.");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reasonable. I would file a CSHARP ticket and note its number here so that we don't lose it.

throw new SkipException("Skipped because CSharp Driver has an issue with handling read timeout for sync code-path.");
}

if (CoreTestConfiguration.Cluster.Description.Type == ClusterType.Sharded &&
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a comment stating that these tests are not compatible with MongoDB 4.2. Otherwise it is not clear why we only run them for 4.4+.

{
var result = _session == null
? _collection.Count(_filter, _options, cancellationToken)
: _collection.Count(_session, _filter, _options, cancellationToken);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMongoCollection<T>.Count is obsolete. We should be using IMongoCollection<T>.CountDocuments instead.

{
var result = _session == null
? await _collection.CountAsync(_filter, _options, cancellationToken)
: await _collection.CountAsync(_session, _filter, _options, cancellationToken);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above except CountDocumentsAsync.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants