Skip to content

Commit

Permalink
ensure proper disposal of transports from di factory (#44)
Browse files Browse the repository at this point in the history
* Rework servertransport to have proper interface and factory

* fmt

* rename class

* exclude factory from tests
  • Loading branch information
adamhathcock authored Jul 18, 2024
1 parent 5891163 commit 5c7a96b
Show file tree
Hide file tree
Showing 15 changed files with 81 additions and 12 deletions.
1 change: 1 addition & 0 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,6 @@
<GlobalPackageReference Include="PolySharp" Version="1.14.1" />
<GlobalPackageReference Include="Microsoft.SourceLink.GitHub" Version="8.0.0" />
<GlobalPackageReference Include="GitVersion.MsBuild" Version="5.12.0" />
<GlobalPackageReference Include="Speckle.InterfaceGenerator" Version="0.9.5" />
</ItemGroup>
</Project>
6 changes: 6 additions & 0 deletions build/packages.lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@
"resolved": "12.0.0",
"contentHash": "ptxlWtxC8vM6Y6e3h9ZTxBBkOWnWrm/Sa1HT+2i1xcXY3Hx2hmKDZP5RShPf8Xr9D+ivlrXNy57ktzyH8kyt+Q=="
},
"Speckle.InterfaceGenerator": {
"type": "Direct",
"requested": "[0.9.5, )",
"resolved": "0.9.5",
"contentHash": "oU/L7pN1R7q8KkbrpQ3WJnHirPHqn+9DEA7asOcUiggV5dzVg1A/VYs7GOSusD24njxXh03tE3a2oTLOjt3cVg=="
},
"Microsoft.Build.Tasks.Git": {
"type": "Transitive",
"resolved": "8.0.0",
Expand Down
10 changes: 10 additions & 0 deletions src/Speckle.Core/Transports/IServerTransport.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace Speckle.Core.Transports;

public interface IServerTransport : IDisposable, ITransport, IBlobCapableTransport, ICloneable
{
int TotalSentBytes { get; }
Credentials.Account Account { get; }
string BaseUri { get; }
string StreamId { get; }
int TimeoutSeconds { get; set; }
}
13 changes: 13 additions & 0 deletions src/Speckle.Core/Transports/ServerTransportFactory.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using System.Diagnostics.CodeAnalysis;
using Speckle.Core.Credentials;
using Speckle.InterfaceGenerator;

namespace Speckle.Core.Transports;

[GenerateAutoInterface]
[ExcludeFromCodeCoverage] //factories don't need coverage
public class ServerTransportFactory : IServerTransportFactory
{
public IServerTransport Create(Account account, string streamId, int timeoutSeconds, string? blobStorageFolder) =>
new ServerTransport(account, streamId, timeoutSeconds, blobStorageFolder);
}
12 changes: 1 addition & 11 deletions src/Speckle.Core/Transports/ServerV2.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Speckle.Core.Credentials;
using Speckle.Core.Helpers;
using Speckle.Core.Logging;
Expand All @@ -14,12 +8,8 @@

namespace Speckle.Core.Transports;

public sealed class ServerTransport : IDisposable, ICloneable, ITransport, IBlobCapableTransport
public sealed class ServerTransport : IServerTransport
{
// POC: autofac uses this to construct a factory in place if this delegate and this can then be injected and parameters passed
// this should, and I think can, come out of this class, because I think autofac does magic based on the return type
public delegate ITransport Factory(Account account, string streamId, int timeoutSeconds, string? blobStorageFolder);

private readonly object _elapsedLock = new();

private Exception? _exception;
Expand Down
6 changes: 6 additions & 0 deletions src/Speckle.Core/packages.lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,12 @@
"resolved": "4.0.1",
"contentHash": "MzEQ1Im0zTja+tEsdRIk/WlPiKqb22NmTOJcR1ZKm/mz46pezyyID3/wRz6vJUELMpSLnG7LhsxBL+nxbr7V0w=="
},
"Speckle.InterfaceGenerator": {
"type": "Direct",
"requested": "[0.9.5, )",
"resolved": "0.9.5",
"contentHash": "oU/L7pN1R7q8KkbrpQ3WJnHirPHqn+9DEA7asOcUiggV5dzVg1A/VYs7GOSusD24njxXh03tE3a2oTLOjt3cVg=="
},
"Speckle.Newtonsoft.Json": {
"type": "Direct",
"requested": "[13.0.2, )",
Expand Down
2 changes: 1 addition & 1 deletion src/Speckle.Objects/Speckle.Objects.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<Product>Speckle.Objects</Product>
<Description>Objects is the default object model for Speckle</Description>
<PackageTags>$(PackageTags), objects</PackageTags>
<PolySharpExcludeGeneratedTypes>System.Runtime.CompilerServices.IsExternalInit;System.Runtime.CompilerServices.RequiresLocationAttribute</PolySharpExcludeGeneratedTypes>
<PolySharpExcludeGeneratedTypes>System.Runtime.CompilerServices.RequiresLocationAttribute</PolySharpExcludeGeneratedTypes>
<Configurations>Debug;Release;Local</Configurations>
</PropertyGroup>

Expand Down
6 changes: 6 additions & 0 deletions src/Speckle.Objects/packages.lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@
"resolved": "1.14.1",
"contentHash": "mOOmFYwad3MIOL14VCjj02LljyF1GNw1wP0YVlxtcPvqdxjGGMNdNJJxHptlry3MOd8b40Flm8RPOM8JOlN2sQ=="
},
"Speckle.InterfaceGenerator": {
"type": "Direct",
"requested": "[0.9.5, )",
"resolved": "0.9.5",
"contentHash": "oU/L7pN1R7q8KkbrpQ3WJnHirPHqn+9DEA7asOcUiggV5dzVg1A/VYs7GOSusD24njxXh03tE3a2oTLOjt3cVg=="
},
"GraphQL.Client.Abstractions": {
"type": "Transitive",
"resolved": "6.0.0",
Expand Down
6 changes: 6 additions & 0 deletions src/Speckle.Transports.Disk/packages.lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@
"resolved": "1.14.1",
"contentHash": "mOOmFYwad3MIOL14VCjj02LljyF1GNw1wP0YVlxtcPvqdxjGGMNdNJJxHptlry3MOd8b40Flm8RPOM8JOlN2sQ=="
},
"Speckle.InterfaceGenerator": {
"type": "Direct",
"requested": "[0.9.5, )",
"resolved": "0.9.5",
"contentHash": "oU/L7pN1R7q8KkbrpQ3WJnHirPHqn+9DEA7asOcUiggV5dzVg1A/VYs7GOSusD24njxXh03tE3a2oTLOjt3cVg=="
},
"GraphQL.Client.Abstractions": {
"type": "Transitive",
"resolved": "6.0.0",
Expand Down
6 changes: 6 additions & 0 deletions src/Speckle.Transports.MongoDB/packages.lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@
"resolved": "1.14.1",
"contentHash": "mOOmFYwad3MIOL14VCjj02LljyF1GNw1wP0YVlxtcPvqdxjGGMNdNJJxHptlry3MOd8b40Flm8RPOM8JOlN2sQ=="
},
"Speckle.InterfaceGenerator": {
"type": "Direct",
"requested": "[0.9.5, )",
"resolved": "0.9.5",
"contentHash": "oU/L7pN1R7q8KkbrpQ3WJnHirPHqn+9DEA7asOcUiggV5dzVg1A/VYs7GOSusD24njxXh03tE3a2oTLOjt3cVg=="
},
"AWSSDK.Core": {
"type": "Transitive",
"resolved": "3.7.100.14",
Expand Down
6 changes: 6 additions & 0 deletions tests/Speckle.Core.Serialization.Tests/packages.lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,12 @@
"EmptyFiles": "4.4.0"
}
},
"Speckle.InterfaceGenerator": {
"type": "Direct",
"requested": "[0.9.5, )",
"resolved": "0.9.5",
"contentHash": "oU/L7pN1R7q8KkbrpQ3WJnHirPHqn+9DEA7asOcUiggV5dzVg1A/VYs7GOSusD24njxXh03tE3a2oTLOjt3cVg=="
},
"DiffEngine": {
"type": "Transitive",
"resolved": "11.3.0",
Expand Down
6 changes: 6 additions & 0 deletions tests/Speckle.Core.Tests.Integration/packages.lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,12 @@
"EmptyFiles": "4.4.0"
}
},
"Speckle.InterfaceGenerator": {
"type": "Direct",
"requested": "[0.9.5, )",
"resolved": "0.9.5",
"contentHash": "oU/L7pN1R7q8KkbrpQ3WJnHirPHqn+9DEA7asOcUiggV5dzVg1A/VYs7GOSusD24njxXh03tE3a2oTLOjt3cVg=="
},
"DiffEngine": {
"type": "Transitive",
"resolved": "11.3.0",
Expand Down
6 changes: 6 additions & 0 deletions tests/Speckle.Core.Tests.Unit/packages.lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,12 @@
"resolved": "1.14.1",
"contentHash": "mOOmFYwad3MIOL14VCjj02LljyF1GNw1wP0YVlxtcPvqdxjGGMNdNJJxHptlry3MOd8b40Flm8RPOM8JOlN2sQ=="
},
"Speckle.InterfaceGenerator": {
"type": "Direct",
"requested": "[0.9.5, )",
"resolved": "0.9.5",
"contentHash": "oU/L7pN1R7q8KkbrpQ3WJnHirPHqn+9DEA7asOcUiggV5dzVg1A/VYs7GOSusD24njxXh03tE3a2oTLOjt3cVg=="
},
"GraphQL.Client.Abstractions": {
"type": "Transitive",
"resolved": "6.0.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<IsTestProject>true</IsTestProject>
<PolySharpExcludeGeneratedTypes>System.Runtime.CompilerServices.IsExternalInit</PolySharpExcludeGeneratedTypes>
</PropertyGroup>

<ItemGroup>
Expand Down
6 changes: 6 additions & 0 deletions tests/Speckle.Objects.Tests.Unit/packages.lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,12 @@
"resolved": "1.14.1",
"contentHash": "mOOmFYwad3MIOL14VCjj02LljyF1GNw1wP0YVlxtcPvqdxjGGMNdNJJxHptlry3MOd8b40Flm8RPOM8JOlN2sQ=="
},
"Speckle.InterfaceGenerator": {
"type": "Direct",
"requested": "[0.9.5, )",
"resolved": "0.9.5",
"contentHash": "oU/L7pN1R7q8KkbrpQ3WJnHirPHqn+9DEA7asOcUiggV5dzVg1A/VYs7GOSusD24njxXh03tE3a2oTLOjt3cVg=="
},
"GraphQL.Client.Abstractions": {
"type": "Transitive",
"resolved": "6.0.0",
Expand Down

0 comments on commit 5c7a96b

Please sign in to comment.