1
0

Small async fixes for AsyncQueue and over-/underflow for IPAddress

This commit is contained in:
2022-08-17 23:38:51 +02:00
parent 18c9bb7cee
commit c4870ad799
5 changed files with 105 additions and 14 deletions

View File

@@ -18,6 +18,9 @@
{
bytes[bytePos] = 0;
bytePos--;
if (bytePos < 0)
return new IPAddress(bytes);
}
bytes[bytePos]++;
@@ -37,6 +40,9 @@
{
bytes[bytePos] = byte.MaxValue;
bytePos--;
if (bytePos < 0)
return new IPAddress(bytes);
}
bytes[bytePos]--;

View File

@@ -220,7 +220,7 @@ namespace System.Collections.Generic
internalDequeueTcs = ResetToken(ref dequeueTcs);
}
await WaitAsync(internalDequeueTcs, cancellationToken);
await WaitAsync(internalDequeueTcs, cancellationToken).ConfigureAwait(false);
}
}
@@ -251,7 +251,7 @@ namespace System.Collections.Generic
internalDequeueTcs = ResetToken(ref dequeueTcs);
}
await WaitAsync(internalDequeueTcs, cancellationToken);
await WaitAsync(internalDequeueTcs, cancellationToken).ConfigureAwait(false);
}
}
@@ -273,7 +273,7 @@ namespace System.Collections.Generic
internalDequeueTcs = ResetToken(ref dequeueTcs);
}
await WaitAsync(internalDequeueTcs, cancellationToken);
await WaitAsync(internalDequeueTcs, cancellationToken).ConfigureAwait(false);
}
}
@@ -293,7 +293,7 @@ namespace System.Collections.Generic
internalAvailableTcs = ResetToken(ref availableTcs);
}
await WaitAsync(internalAvailableTcs, cancellationToken);
await WaitAsync(internalAvailableTcs, cancellationToken).ConfigureAwait(false);
}
#endregion Async implementation

View File

@@ -1,26 +1,37 @@
# Changelog
All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [Unreleased](https://git.am-wd.de/AM.WD/common/compare/v1.9.0...main) - 0000-00-00
_nothing changed yet_
### Fixed
- Over-/Underflow behaviour for IPAddress de-/increment
- Await behaviour for AsyncQueue (not required to marshal back to the original captured context)
## [v1.9.0](https://git.am-wd.de/AM.WD/common/compare/v1.8.1...v1.9.0) - 2022-08-14
### Added
- `AsyncQueue<T>` to `AMWD.Common.Utilities` with namespace `System.Collections.Generic`
## [v1.8.1](https://git.am-wd.de/AM.WD/common/compare/v1.8.0...v1.8.1) - 2022-08-07
### Fixed
- UnitTests
- BasicAuthentication modules now all use the cancellation token
## [v1.8.0](https://git.am-wd.de/AM.WD/common/compare/v1.7.0...v1.8.0) - 2022-08-07
### Added
- Converters for `Newtonsoft.Json`
- `ByteArrayHexConverter` to get an byte array as hex string instead of Base64
- `IPAddressConverter` to make `System.Net.IPAdress`es (and list forms) serializable
@@ -34,65 +45,86 @@ _nothing changed yet_
- `IPNetworkListFormatter` to serialize lists of `Microsoft.AspNetCore.HttpOverrides.IPNetwork`
### Changed
- `IBasicAuthenticationValidator` has the possibillity to cancel the operation
## [v1.7.0](https://git.am-wd.de/AM.WD/common/compare/v1.6.1...v1.7.0) - 2022-07-24
### Added
- UnitTests for `AspNetCore` as far as testable without massive work
- `IPAddress.Increment` and `IPAddress.Decrement` extensions
- `NetworkHelper.ParseNetwork` and `NetworkHelper.TryParseNetwork` to parse a CIDR (e.g. 192.168.178.0/24) network
- `IPNetwork.ExpandNetwork` to create a list with all contained `IPAddress`es
### Changed
- `BasicAuthenticationAttribute` now respects the `IBasicAuthenticationValidator.Realm` when the own `Realm` property is not set
- CI scripts
- Updated all package references to latest builds (as on 2022-07-23)
### Removed
- `IBasicAuthenticationValidator.Realm` is now a read-only property (removed public set)
## [v1.6.1](https://git.am-wd.de/AM.WD/common/compare/v1.6.0...v1.6.1) - 2022-06-23
### Added
- `BasicAuthenticationAttribute` sets the `HttpContext.User` property when successfully validated
### Changed
- Moved `BasicAuthenticationAttribute` from `ActionFilter` to `IAsyncAuthorizationFilter`
### Fixed
- `TimeSpan.ToShortString()` is now capable of negative values
## [v1.6.0](https://git.am-wd.de/AM.WD/common/compare/v1.5.3...v1.6.0) - 2022-06-22
### Changed
- All attributes now reside in `Microsoft.AspNetCore.Mvc.Filters` namespace
### Fixed
- Fixed `BasicAuthenticationAttribute`
## [v1.5.3](https://git.am-wd.de/AM.WD/common/compare/v1.5.2...v1.5.3) - 2022-06-22
### Changed
- `BasicAuthenticationAttribute` is now in namespace `AMWD.Common.AspNetCore.Attributes`
### Fixed
- Fixed problem with `ForbidResult` without having an authentication schema defined
Now only HTTP Status 403 (Forbid) is returned
## [v1.5.2](https://git.am-wd.de/AM.WD/common/compare/v1.5.1...v1.5.2) - 2022-06-20
### Removed
- Removed support for .NET 5.0 due to EOL (2022-05-10, see [.NET and .NET Core release lifecycle](https://dotnet.microsoft.com/en-us/platform/support/policy/dotnet-core#lifecycle))
## [v1.5.1](https://git.am-wd.de/AM.WD/common/compare/v1.5.0...v1.5.1) - 2022-06-20
### Changed
- Changed from `Assembly.GetExecutingAssmebly().Location` to `AppContext.BaseDirectory` due to single-file applications
## [v1.5.0](https://git.am-wd.de/AM.WD/common/compare/v1.4.3...v1.5.0) - 2022-06-15
### Added
- `TcpClientMoq` to test communication via a `TcpClient`
- EntityFramework Core Converters for new `DateOnly` and `TimeOnly` datatypes when using SQL Server on .NET 6.0 (Bug on Microsoft's EntityFramework)
- `HttpContext.IsLocalRequest()` to determine whether the request was from local or remote
@@ -100,120 +132,155 @@ _nothing changed yet_
## [v1.4.3](https://git.am-wd.de/AM.WD/common/compare/v1.4.2...v1.4.3) - 2022-05-12
### Fixed
- Fixed detection of SQLServer for EFCore extensions
## [v1.4.2](https://git.am-wd.de/AM.WD/common/compare/v1.4.1...v1.4.2) - 2022-05-06
### Added
- New extension for `StringBuilder` `AppendLine(value: string, newLine: string)` to add a line with a explicit defined new line character
## [v1.4.1](https://git.am-wd.de/AM.WD/common/compare/v1.4.0...v1.4.1) - 2022-03-23
### Added
- `IntegrityHashTagHelper` can be used with `asp-integrity="true|false"` and `asp-integrity-strength="256|384|512"`
- `WaitAvailableAsync` can be used to wait for a database connection to be available
### Changed
- `ApplyMigrationsAsync` uses `WaitAvailableAsync` internally
### Fixed
- `InMemory` database provider does not fail on "migration" (none possible)
## [v1.4.0](https://git.am-wd.de/AM.WD/common/compare/v1.3.0...v1.4.0) - 2022-02-11
### Added
- New NuGet package `AMWD.Common.Moq` with `HttpRequestHandlerMoq` class
- Supporting `InMemory` Database as provider
### Changed
- Enhanced Stopwatch/Timer delta due to unsharp resolution using timers
- `IBasicAuthenticationValidator` now also provides the realm as property (resolving a string on DI is bad style)
## [v1.3.0](https://git.am-wd.de/AM.WD/common/compare/v1.2.0...v1.3.0) - 2021-12-21
### Added
- `BasicAuthenticationHandler` to use instead of other handlers (instead of e.g. CookieAuthentication)
- `BasicAuthenticationAttribute` to restrict single actions
### Changed
- Simplified package references on AspNetCore
- Changed NuGet package `DnsClient` to `DNS`
## [v1.2.0](https://git.am-wd.de/AM.WD/common/compare/v1.1.0...v1.2.0) - 2021-12-19
### Added
- CHANGELOG
- `HtmlHelper.IsDarkColor` to classify a color as dark or light one (by luminance)
- `ReadLine` and `ReadLineAsync` as `StreamExtensions`
### Changed
- Unit-Tests enhanced
- Unit-Tests excluded from code coverage calcualtion
- Updated NuGet package `NetRevisionTask`
## [v1.1.0](https://git.am-wd.de/AM.WD/common/compare/v1.0.2...v1.1.0) - 2021-11-22
### Added
- `AddSingletonHostedService<TService, TImplementation>` using an interface and an implementation type
- Unit-Tests for `AMWD.Common` (ca. 60% Branch-Coverage, target: above 90%)
- `IsValidEmailAddress` check whether a string is a valid email address, optionally with DNS check (MX record)
- AES and 3DES De-/Encrypt enhanced for string to string (plain/base64)
### Changed
- CI Build-Process splitted into: build, test, deploy
- `GetAlignedInterval` splitted into `GetAlignedIntervalUtc` and `GetAlignedIntervalLocal` to respect daylight saving times
- `HexToBytes` checks for valid characters by using RegEx
### Fixed
- `Sha256` as string extension
## [v1.0.2](https://git.am-wd.de/AM.WD/common/compare/v1.0.1...v1.0.2) - 2021-11-09
### Added
- .NET 6.0 (LTS) compatibility
- Versioning in README
### Changed
- CI Build modified
- C# Update from 9.0 to 10.0
### Fixed
- Comments updated / enhanced
## [v1.0.1](https://git.am-wd.de/AM.WD/common/compare/v1.0.0...v1.0.1) - 2021-10-25
### Added
- `ParseDecimal` added to prevent problems with comma/dot as decimal separator
### Changed
- NuGet packages reside on `artifacts/`
### Fixed
- MySQL library is now working correctly via reflection
## [v1.0.0](https://git.am-wd.de/AM.WD/common/compare/v0.0.2...v1.0.0) - 2021-10-24
### Added
- Lizenz
- Readme
### Changed
- `CustomFloatingPointModelBinder*` renamed to `InvariantFloatingPointModelBinder*`
- `ResolveHost` returns a list of resolved ip addresses
- `ResolveInterface` returns a list of resolved ip addresses
### Removed
- `IPAddress fallback` parameter removed from `ResolveHost`
- `IPAddress fallback` parameter removed from `ResolveInterface`
- `ResolveInterface` does not use DNS to resolve the input (kind a weired behaviour)
## [v0.0.2](https://git.am-wd.de/AM.WD/common/compare/v0.0.1...v0.0.2) - 2021-10-23
### Added
- NuGet packages have an icon
### Changed
- Additional information for NuGet packages

View File

@@ -1,9 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;
using System.Net;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace UnitTests.Common.Extensions
@@ -38,6 +33,19 @@ namespace UnitTests.Common.Extensions
Assert.AreEqual("193.0.0.0", incremented.ToString());
}
[TestMethod]
public void ShouldIncrementOverflow()
{
// arrange
var ipAddress = IPAddress.Parse("255.255.255.255");
// act
var incremented = ipAddress.Increment();
// assert
Assert.AreEqual("0.0.0.0", incremented.ToString());
}
[TestMethod]
public void ShouldDecrementLastByte()
{
@@ -63,5 +71,18 @@ namespace UnitTests.Common.Extensions
// assert
Assert.AreEqual("191.255.255.255", decremented.ToString());
}
[TestMethod]
public void ShouldDecrementUnderflow()
{
// arrange
var ipAddress = IPAddress.Parse("0.0.0.0");
// act
var decremented = ipAddress.Decrement();
// assert
Assert.AreEqual("255.255.255.255", decremented.ToString());
}
}
}

View File

@@ -3,7 +3,6 @@ using System.Collections.Generic;
using System.Reflection;
using System.Threading.Tasks;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Moq;
namespace UnitTests.Common.Utilities
{
@@ -333,8 +332,6 @@ namespace UnitTests.Common.Utilities
Assert.Fail();
}
private AsyncQueue<TestElement> GetQueue()
{
var asyncQueue = new AsyncQueue<TestElement>();