Skip to content

Commit 6f208ff

Browse files
committed
CA1001: Types that own disposable fields should be disposable
1 parent c88e39f commit 6f208ff

File tree

10 files changed

+39
-3
lines changed

10 files changed

+39
-3
lines changed

.editorconfig

+3
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,9 @@ dotnet_diagnostic.RS0041.severity = none # not default, decreased severity becau
216216
# CA1824: Mark assemblies with NeutralResourcesLanguageAttribute
217217
dotnet_diagnostic.CA1824.severity = warning # not default, increased severity to ensure it is applied
218218

219+
# CA1001: Types that own disposable fields should be disposable
220+
dotnet_diagnostic.CA1001.severity = warning # not default, increased severity to ensure it is applied
221+
219222
# CA1304: Specify CultureInfo
220223
dotnet_diagnostic.CA1304.severity = warning # not default, increased severity to ensure it is applied
221224

TestPlatform.sln

+3
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ EndProject
88
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.TestPlatform.CoreUtilities", "src\Microsoft.TestPlatform.CoreUtilities\Microsoft.TestPlatform.CoreUtilities.csproj", "{50C00046-0DA3-4B5C-9F6F-7BE1145E156A}"
99
EndProject
1010
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{B27FAFDF-2DBA-4AB0-BA85-FD5F21D359D6}"
11+
ProjectSection(SolutionItems) = preProject
12+
test\.editorconfig = test\.editorconfig
13+
EndProjectSection
1114
EndProject
1215
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.TestPlatform.CoreUtilities.UnitTests", "test\Microsoft.TestPlatform.CoreUtilities.UnitTests\Microsoft.TestPlatform.CoreUtilities.UnitTests.csproj", "{01409D95-A5F1-4EBE-94B1-909D5D2D0DC3}"
1316
EndProject

src/Microsoft.TestPlatform.Common/DataCollection/DataCollectionAttachmentManager.cs

+14-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ namespace Microsoft.VisualStudio.TestPlatform.Common.DataCollector;
3434
/// we don't know how the user will implement the datacollector and they could send file out of events(wrong usage, no more expected sequential access AddAttachment->GetAttachments),
3535
/// so we prefer protect every collection. This not means that outcome will be "always correct"(file attached in a correct way) but at least we avoid exceptions.
3636
/// </summary>
37-
internal class DataCollectionAttachmentManager : IDataCollectionAttachmentManager
37+
internal class DataCollectionAttachmentManager : IDataCollectionAttachmentManager, IDisposable
3838
{
3939
private readonly object _attachmentTaskLock = new();
4040

@@ -356,4 +356,17 @@ private void LogError(string errorMessage, Uri collectorUri, string collectorFri
356356
_messageSink?.SendMessage(args);
357357
}
358358

359+
public void Dispose()
360+
{
361+
Dispose(disposing: true);
362+
GC.SuppressFinalize(this);
363+
}
364+
365+
protected virtual void Dispose(bool disposing)
366+
{
367+
if (disposing)
368+
{
369+
_cancellationTokenSource.Dispose();
370+
}
371+
}
359372
}

src/Microsoft.TestPlatform.Common/ExtensionFramework/TestPluginCache.cs

+1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ namespace Microsoft.VisualStudio.TestPlatform.Common.ExtensionFramework;
2525
/// The test plugin cache.
2626
/// </summary>
2727
/// <remarks>Making this a singleton to offer better unit testing.</remarks>
28+
[SuppressMessage("Design", "CA1001:Types that own disposable fields should be disposable", Justification = "Would cause a breaking change if users are inheriting this class and implement IDisposable")]
2829
public class TestPluginCache
2930
{
3031
private readonly Dictionary<string, Assembly?> _resolvedAssemblies = new();

src/Microsoft.TestPlatform.CommunicationUtilities/SocketClient.cs

+2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
33

44
using System;
5+
using System.Diagnostics.CodeAnalysis;
56
using System.IO;
67
using System.Net.Sockets;
78
using System.Threading;
@@ -16,6 +17,7 @@ namespace Microsoft.VisualStudio.TestPlatform.CommunicationUtilities;
1617
/// <summary>
1718
/// Communication client implementation over sockets.
1819
/// </summary>
20+
[SuppressMessage("Design", "CA1001:Types that own disposable fields should be disposable", Justification = "Would cause a breaking change if users are inheriting this class and implement IDisposable")]
1921
public class SocketClient : ICommunicationEndPoint
2022
{
2123
private readonly CancellationTokenSource _cancellation;

src/Microsoft.TestPlatform.CommunicationUtilities/SocketCommunicationManager.cs

+2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
using System;
55
using System.Diagnostics;
6+
using System.Diagnostics.CodeAnalysis;
67
using System.IO;
78
using System.Net;
89
using System.Net.Sockets;
@@ -19,6 +20,7 @@ namespace Microsoft.VisualStudio.TestPlatform.CommunicationUtilities;
1920
/// <summary>
2021
/// Facilitates communication using sockets
2122
/// </summary>
23+
[SuppressMessage("Design", "CA1001:Types that own disposable fields should be disposable", Justification = "Would cause a breaking change if users are inheriting this class and implement IDisposable")]
2224
public class SocketCommunicationManager : ICommunicationManager
2325
{
2426
/// <summary>

src/Microsoft.TestPlatform.CommunicationUtilities/SocketServer.cs

+2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
33

44
using System;
5+
using System.Diagnostics.CodeAnalysis;
56
using System.IO;
67
using System.Net.Sockets;
78
using System.Threading;
@@ -16,6 +17,7 @@ namespace Microsoft.VisualStudio.TestPlatform.CommunicationUtilities;
1617
/// <summary>
1718
/// Communication server implementation over sockets.
1819
/// </summary>
20+
[SuppressMessage("Design", "CA1001:Types that own disposable fields should be disposable", Justification = "Would cause a breaking change if users are inheriting this class and implement IDisposable")]
1921
public class SocketServer : ICommunicationEndPoint
2022
{
2123
private readonly CancellationTokenSource _cancellation;

src/Microsoft.TestPlatform.CrossPlatEngine/AttachmentsProcessing/DataCollectorAttachmentProcessorWrapper.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ namespace Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.TestRunAttachments
2727
/// It tries to load the extension and it receives calls from the DataCollectorAttachmentProcessorAppDomain that
2828
/// acts as a proxy for the main AppDomain(the runner one).
2929
/// </summary>
30-
internal class DataCollectorAttachmentProcessorRemoteWrapper : MarshalByRefObject
30+
internal sealed class DataCollectorAttachmentProcessorRemoteWrapper : MarshalByRefObject, IDisposable
3131
{
3232
private readonly AnonymousPipeServerStream _pipeServerStream = new(PipeDirection.Out, HandleInheritability.None);
3333
private readonly object _pipeClientLock = new();

src/vstest.console/Internal/ProgressIndicator.cs

+8-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
33

4+
using System;
45
using System.Globalization;
56

67
using Microsoft.VisualStudio.TestPlatform.Utilities;
@@ -12,7 +13,7 @@ namespace Microsoft.VisualStudio.TestPlatform.CommandLine.Internal;
1213
/// <summary>
1314
/// Indicates the test run progress
1415
/// </summary>
15-
internal class ProgressIndicator : IProgressIndicator
16+
internal sealed class ProgressIndicator : IProgressIndicator, IDisposable
1617
{
1718
private readonly object _syncObject = new();
1819
private int _dotCounter;
@@ -115,4 +116,10 @@ private void Timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
115116
}
116117
}
117118
}
119+
120+
public void Dispose()
121+
{
122+
_timer?.Dispose();
123+
_timer = null;
124+
}
118125
}

test/.editorconfig

+3
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ dotnet_diagnostic.IDE0060.severity = warning
1515
# CA1018: Mark attributes with AttributeUsageAttribute
1616
dotnet_diagnostic.CA1018.severity = warning
1717

18+
# CA1001: Types that own disposable fields should be disposable
19+
dotnet_diagnostic.CA1001.severity = silent # Disabled on tests as it does not matter
20+
1821
#### C# Coding Conventions ####
1922

2023
#### .NET Formatting Rules ####

0 commit comments

Comments
 (0)