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-4245: Dispose CancellationTokenSource in tests #846

Merged
merged 2 commits into from
Jul 13, 2022

Conversation

BorisDog
Copy link
Contributor

No description provided.

@BorisDog BorisDog requested a review from JamesKovacs July 11, 2022 16:58
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.

Very nice use of using var syntax. My one concern is around the use of default in certain mocking scenarios. See my comment below for more details. Plus a minor point about using cancellationTokenSource rather than cts (even though cts was in the original).

@@ -93,7 +93,7 @@ public void ResolveSrvRecords_should_throw_when_cancellation_is_already_requeste
{
var subject = CreateSubject();
var service = "_mongodb._tcp.test5.test.build.10gen.cc";
var cts = new CancellationTokenSource();
using var cts = new CancellationTokenSource();
Copy link
Contributor

Choose a reason for hiding this comment

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

Since we are updating these lines anyways, let's go with our usual coding standard of not using abbreviations.

cts => cancellationTokenSource

Same elsewhere.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

var task1 = Task.FromResult<object>(null);
mockStream.Setup(s => s.CopyToAsync(mockDestination.Object, bufferSize, cancellationToken)).Returns(task1);
mockStream.Setup(s => s.CopyToAsync(mockDestination.Object, bufferSize, default)).Returns(task1);
Copy link
Contributor

Choose a reason for hiding this comment

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

Isn't this changing the meaning of the test? Previously we were asserting that the passed-in CancellationTokenSource was passed correctly. But since CancellationTokenSource is a class default(CancellationTokenSource is simply null. Thus we cannot tell if the CancellationTokenSource is being correctly passed through or if we are simply explicitly passing null through the call chain.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed.


mockOperation.Verify(m => m.Execute(binding, cancellationToken), Times.Once);
mockOperation.Verify(m => m.Execute(binding, default), Times.Once);
Copy link
Contributor

Choose a reason for hiding this comment

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

Same concern around the use of default as with the previous file.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed.

@BorisDog BorisDog requested a review from JamesKovacs July 12, 2022 23:43
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

@BorisDog BorisDog merged commit 50db4b7 into mongodb:master Jul 13, 2022
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