-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Conversation
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.
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(); |
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.
Since we are updating these lines anyways, let's go with our usual coding standard of not using abbreviations.
cts
=> cancellationTokenSource
Same elsewhere.
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.
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); |
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.
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.
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.
|
||
mockOperation.Verify(m => m.Execute(binding, cancellationToken), Times.Once); | ||
mockOperation.Verify(m => m.Execute(binding, default), Times.Once); |
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.
Same concern around the use of default
as with the previous file.
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.
LGTM
No description provided.