Skip to content

Commit

Permalink
Merge pull request #88 from launchdarkly/eb/sc-154188/drop-old-platforms
Browse files Browse the repository at this point in the history
drop .NET Framework 4.5.2/4.6.1 and don't test in EOL platforms
  • Loading branch information
eli-darkly authored Aug 18, 2022
2 parents b90604c + 219307d commit 9694804
Show file tree
Hide file tree
Showing 13 changed files with 137 additions and 124 deletions.
53 changes: 32 additions & 21 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,20 @@ workflows:
version: 2
test:
jobs:
- test-netcore:
name: .NET Core 2.1
docker-image: mcr.microsoft.com/dotnet/core/sdk:2.1-focal
test-target-framework: netcoreapp2.1
- test-netcore:
- test_linux:
name: .NET Core 3.1
docker-image: mcr.microsoft.com/dotnet/core/sdk:3.1-focal
test-target-framework: netcoreapp3.1
- test-netcore:
name: .NET 5.0
docker-image: mcr.microsoft.com/dotnet/sdk:5.0-focal
test-target-framework: net5.0
- test-windows-netframework:
name: .NET Framework 4.5.2
test-target-framework: net452
- test-windows-netframework:
name: .NET Framework 4.6.1
test-target-framework: net461
- test_linux:
name: .NET 6.0
docker-image: mcr.microsoft.com/dotnet/sdk:6.0-focal
test-target-framework: net6.0
- test_windows:
name: .NET Framework 4.6.2
test-target-framework: net462

jobs:
test-netcore:
test_linux:
parameters:
docker-image:
type: string
Expand All @@ -43,10 +36,19 @@ jobs:
name: install packages
command: apt-get -q update && apt-get install -qy awscli
- checkout
- run: dotnet build src/LaunchDarkly.EventSource -f netstandard2.0
- run: dotnet test test/LaunchDarkly.EventSource.Tests/LaunchDarkly.EventSource.Tests.csproj
- run:
name: build
command: dotnet build src/LaunchDarkly.EventSource -f netstandard2.0
- run:
name: run tests
command: |
dotnet test \
-l "junit;LogFilePath=/tmp/circle-reports/unit-tests-commonsdk.xml" \
test/LaunchDarkly.EventSource.Tests/LaunchDarkly.EventSource.Tests.csproj
- store_test_results:
path: /tmp/circle-reports

test-windows-netframework:
test_windows:
parameters:
test-target-framework:
type: string
Expand All @@ -57,5 +59,14 @@ jobs:
TESTFRAMEWORK: <<parameters.test-target-framework>>
steps:
- checkout
- run: dotnet build src/LaunchDarkly.EventSource
- run: dotnet test test/LaunchDarkly.EventSource.Tests/LaunchDarkly.EventSource.Tests.csproj
- run:
name: build
command: dotnet build src/LaunchDarkly.EventSource
- run:
name: run tests
command: |
dotnet test \
-l "junit;LogFilePath=/tmp/circle-reports/unit-tests-commonsdk.xml" \
test/LaunchDarkly.EventSource.Tests/LaunchDarkly.EventSource.Tests.csproj
- store_test_results:
path: /tmp/circle-reports
8 changes: 5 additions & 3 deletions .ldrelease/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,18 @@ publications:

branches:
- name: main
description: 4.x - for .NET SDK 6.0+ and Xamarin SDK 2.0+
description: 5.x - for server-side .NET SDK 7.0+ and client-side .NET SDK 3.0+
- name: 4.x
description: for .NET SDK 6.0+ and Xamarin SDK 2.0+
- name: 3.x
description: for earlier .NET and Xamarin SDKs

jobs:
- template:
name: dotnet-linux
name: dotnet6-linux
env:
LD_RELEASE_DOCS_TARGET_FRAMEWORK: netstandard2.0
LD_RELEASE_TEST_TARGET_FRAMEWORK: net5.0
LD_RELEASE_TEST_TARGET_FRAMEWORK: net6.0

documentation:
gitHubPages: true
Expand Down
4 changes: 2 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@ To run all unit tests, for all targets:
dotnet test test/LaunchDarkly.EventSource.Tests
```

Or, to run tests only for the .NET Standard 2.0 target (using the .NET Core 2.1 runtime):
Or, to run tests only for the .NET Standard 2.0 target (using the .NET Core 3.1 runtime):

```
dotnet test test/LaunchDarkly.EventSource.Tests -f netcoreapp2.1
dotnet test test/LaunchDarkly.EventSource.Tests -f netcoreapp3.1
```

Note that the unit tests can only be run in Debug configuration. There is an `InternalsVisibleTo` directive that allows the test code to access internal members of the library, and assembly strong-naming in the Release configuration interferes with this.
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,8 @@ The `LaunchDarkly.EventSource` package allows .NET developers to consume Server-

This version of the library is built for the following targets:

* .NET Framework 4.5.2: runs on .NET Framework 4.5.x and above.
* .NET Core 2.1: runs on .NET Core 2.x and 3.x, or .NET 5. This target provides an adapter to the standard .NET Core logging framework, `Logs.CoreLogging`, which is not available in .NET Framework.
* .NET Standard 2.0: runs on .NET Core 2.x and 3.x or .NET 5, or within a library that is targeted to .NET Standard 2.x.
* .NET Framework 4.6.2: runs on .NET Framework 4.6.2 and above.
* .NET Standard 2.0: runs on .NET Core 3.x or .NET 6.0+, or within a library that is targeted to .NET Standard 2.x.

The .NET build tools should automatically load the most appropriate build of the library for whatever platform your application or library is targeted to.

Expand Down
8 changes: 0 additions & 8 deletions src/LaunchDarkly.EventSource/Configuration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,6 @@ public sealed class Configuration
[Obsolete("Use ResponseStartTimeout")]
public TimeSpan ConnectionTimeout => ResponseStartTimeout;

/// <summary>
/// The character encoding to use when reading the stream if the server did not specify
/// an encoding in a <c>Content-Type</c> header.
/// </summary>
/// <seealso cref="ConfigurationBuilder.DefaultEncoding(Encoding)"/>
public Encoding DefaultEncoding { get; }

/// <summary>
/// The HttpClient that will be used as the HTTP client, or null for a new HttpClient.
/// </summary>
Expand Down Expand Up @@ -183,7 +176,6 @@ internal Configuration(ConfigurationBuilder builder)
(builder._logAdapter is null ? null : builder._logAdapter.Logger(Configuration.DefaultLoggerName));

BackoffResetThreshold = builder._backoffResetThreshold;
DefaultEncoding = builder._defaultEncoding ?? Encoding.UTF8;
HttpClient = builder._httpClient;
HttpMessageHandler = (builder._httpClient != null) ? null : builder._httpMessageHandler;
InitialRetryDelay = builder._initialRetryDelay;
Expand Down
31 changes: 6 additions & 25 deletions src/LaunchDarkly.EventSource/ConfigurationBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ public class ConfigurationBuilder
#region Private Fields

internal readonly Uri _uri;
internal Encoding _defaultEncoding = Encoding.UTF8;
internal TimeSpan _initialRetryDelay = Configuration.DefaultInitialRetryDelay;
internal TimeSpan _backoffResetThreshold = Configuration.DefaultBackoffResetThreshold;
internal string _lastEventId;
Expand Down Expand Up @@ -89,21 +88,6 @@ public ConfigurationBuilder HttpRequestModifier(Action<HttpRequestMessage> httpR
return this;
}

/// <summary>
/// Sets the character encoding to use when reading the stream if the server did not specify
/// an encoding in a <c>Content-Type</c> header.
/// </summary>
/// <param name="defaultEncoding">A <c>System.Text.Encoding</c>; if null, the default
/// is <see cref="Encoding.UTF8"/></param>
/// <returns>the builder</returns>
/// <seealso cref="MessageEvent"/>
/// <seealso cref="PreferDataAsUtf8Bytes"/>
public ConfigurationBuilder DefaultEncoding(Encoding defaultEncoding)
{
_defaultEncoding = defaultEncoding ?? Encoding.UTF8;
return this;
}

/// <summary>
/// Sets the initial amount of time to wait before attempting to reconnect to the EventSource API.
/// </summary>
Expand Down Expand Up @@ -320,17 +304,14 @@ public ConfigurationBuilder Logger(Logger logger)
/// preferable to store and process event data as UTF-8 byte arrays rather than
/// strings. By default, <c>EventSource</c> will use the <c>string</c> type when
/// processing the event stream; if you then use <see cref="MessageEvent.DataUtf8Bytes"/>
/// to get the data, it will be converted to a byte array as needed. It will also
/// always use the <c>string</c> type internally if the stream's encoding is not
/// UTF-8. However, if the stream's encoding is UTF-8 <c>and</c> you have set
/// <c>PreferDataAsUtf8Bytes</c> to <see langword="true"/>, the event data will
/// be stored internally as a UTF-8 byte array so that if you read
/// to get the data, it will be converted to a byte array as needed. However, if
/// you set <c>PreferDataAsUtf8Bytes</c> to <see langword="true"/>, the event data
/// will be stored internally as a UTF-8 byte array so that if you read
/// <see cref="MessageEvent.DataUtf8Bytes"/>, you will get the same array with no
/// extra copying or conversion. Therefore, for greatest efficiency you should set
/// this to <see langword="true"/> if you intend to process the data as UTF-8 and
/// if you expect that the server will provide it in that encoding. If the server
/// turns out not to use that encoding, everything will still work the same except
/// that there will be more overhead from string conversion.
/// this to <see langword="true"/> if you intend to process the data as UTF-8. Note
/// that Server-Sent Event streams always use UTF-8 encoding, as required by the
/// SSE specification.
/// </remarks>
/// <param name="preferDataAsUtf8Bytes">true if you intend to request the event
/// data as UTF-8 bytes</param>
Expand Down
17 changes: 11 additions & 6 deletions src/LaunchDarkly.EventSource/EventSourceService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,20 +100,25 @@ CancellationToken cancellationToken
_logger.Debug("Response status: {0}", (int)response.StatusCode);
ValidateResponse(response);

OnConnectionOpened();

using (var stream = await response.Content.ReadAsStreamAsync().ConfigureAwait(false))
{
var encoding = DetectEncoding(response);
if (encoding == Encoding.UTF8 && _configuration.PreferDataAsUtf8Bytes)
if (encoding != Encoding.UTF8)
{
throw new EventSourceServiceCancelledException(
string.Format(Resources.ErrorWrongEncoding, encoding.HeaderName));
}
OnConnectionOpened();

if (_configuration.PreferDataAsUtf8Bytes)
{
_logger.Debug("Reading UTF-8 stream without string conversion");
await ProcessResponseFromUtf8StreamAsync(processResponseLineUTF8, stream, cancellationToken);
}
else
{
_logger.Debug("Reading stream with {0} encoding and string conversion", encoding.EncodingName);
using (var reader = new StreamReader(stream, encoding))
_logger.Debug("Reading stream with string conversion");
using (var reader = new StreamReader(stream, Encoding.UTF8))
{
await ProcessResponseFromReaderAsync(processResponseLineString, reader, cancellationToken);
}
Expand All @@ -135,7 +140,7 @@ private Encoding DetectEncoding(HttpResponseMessage response)
}
catch (ArgumentException) { }
}
return _configuration.DefaultEncoding ?? Encoding.UTF8;
return Encoding.UTF8;
}

protected virtual async Task ProcessResponseFromReaderAsync(
Expand Down
4 changes: 2 additions & 2 deletions src/LaunchDarkly.EventSource/LaunchDarkly.EventSource.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<Version>4.2.0</Version>
<TargetFrameworks>netstandard2.0;net452</TargetFrameworks>
<TargetFrameworks>netstandard2.0;net462</TargetFrameworks>
<PackageLicenseExpression>Apache-2.0</PackageLicenseExpression>
<AssemblyName>LaunchDarkly.EventSource</AssemblyName>
<DebugType>portable</DebugType>
Expand All @@ -21,7 +21,7 @@
<PackageReference Include="LaunchDarkly.Logging" Version="[1.0.1,2.0.0)" />
</ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'net452' ">
<ItemGroup Condition=" '$(TargetFramework)' == 'net462' ">
<Reference Include="System" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Net.Http" />
Expand Down
25 changes: 5 additions & 20 deletions src/LaunchDarkly.EventSource/MessageEvent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,27 +19,12 @@ namespace LaunchDarkly.EventSource
/// <para>
/// Since strings in .NET use two-byte UTF-16 characters, if you have a large block of
/// UTF-8 data it is considerably more efficient to process it in its original form
/// rather than converting it to or from a string. <c>MessageEvent</c> converts
/// transparently between these types depending on the original character encoding of
/// the stream; the <see cref="Configuration"/> properties <see cref="Configuration.DefaultEncoding"/>
/// and <see cref="Configuration.PreferDataAsUtf8Bytes"/>; and whether the caller reads
/// from the property <see cref="MessageEvent.Data"/> or <see cref="MessageEvent.DataUtf8Bytes"/>.
/// If you intend to process the data as UTF-8 bytes, and if you expect that the server
/// will provide UTF-8, you should set
/// rather than converting it to or from a string. <see cref="EventSource"/> stores
/// data as strings by default, but you set <see cref="ConfigurationBuilder.PreferDataAsUtf8Bytes(bool)"/>
/// it can store the raw UTF-8 data instead. In either case, <c>MessageEvent</c> will
/// convert types transparently so that you can read either <see cref="MessageEvent.Data"/>
/// or <see cref="MessageEvent.DataUtf8Bytes"/>.
/// </para>
/// <list type="bullet">
/// <item> If the stream encoding is UTF-8, and you read the event data with the
/// <see cref="MessageEvent.DataUtf8Bytes"/> property, the event data is stored as a
/// UTF-8 byte array when it is first read from the stream and it returns the same
/// array, without any further copying and without creating a <c>string</c>. </item>
/// <item> If the stream encoding is UTF-8, but you read the event data with the
/// <see cref="MessageEvent.Data"/> property, the event data is originally read from
/// the stream as a UTF-8 byte array but is then converted to a <c>string</c>. </item>
/// <item> If the stream encoding is not UTF-8, the event data is originally read from
/// the stream as a <c>string</c>. <see cref="MessageEvent.Data"/> will return the
/// same <c>string</c>; <see cref="MessageEvent.DataUtf8Bytes"/> will create a new
/// UTF-8 byte array from it.</item>
/// </list>
/// </remarks>
public struct MessageEvent
{
Expand Down
Loading

0 comments on commit 9694804

Please sign in to comment.