-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* editorconfig and codeformatting * rewrite * docs * throttle-event-args * another check to not reconnect while disconnecting/closing * naming * docs * changelog * reusable TaskHelper * docs * docs * downgrade from version 7 to version 5 of Microsoft.Extensions.Logging.Abstractions * downgrade from net7.0 to net5.0 * fix from integration-test * upgrade to net6 * reduced some overheaad, as mentioned/suggested by Bukk94 * ChangeLog * whispers are obsolete * ChangeLog * ChangeLog: Consideration/Proposal * fixing reconnectionpolicy-issue * fixing reconnectionpolicy-issue * ThrottlingPeriod * get MessageType-values outside while-loop the values wont change at runtime * logging * ToString() * moved and added tests * tests * usings * naming * diagnostic messages * suppress diagnostic messages * OnData has never been used * docs * todo removed, cause it got unnecessary * checked * naming * use build variable * remove * remove * remove * formatting * visibility * removed OnReconnectedEventArgs OnConnectedEventArgs is used, cause what happens is indicated by the EventHandler that is called * update version from 1.0.6 to 1.1.0 * push up ThrottlerService to TwitchClient and update version to 2.2.0 PubSub has its own PING/PONG-Timers PubSub only subscribes to Events PubSub only receives push-messages from twitch * WaitOneDuration * return-value for throttlerservice re-introduced... * changelog * assertion * remove whisper stuff * started changelog * rename method SendIRC to SpecificClientSend changed visibility from internal to protected comments updated * Send can be and is called by several methods so send has to be synchronized/locked * changelog * missed the important thing - sry * removed: event EventHandler<OnStateChangedEventArgs> OnStateChanged * removed comments locking is done in ABaseClient.Send() * give MonitorTaskAction a chance to catch cancellation * Addressed PR comments, renamed properties based on guidelines * Formatted code, updated logic for ConnectionWatchDog * Code formatting for unit tests * Added github workflow and improvements from Syzuna * Updated SSL port for TCP Client, added logging abstractions * Properly updated properties, improved naming, removed duplicate close on streams * Remove lingering option from TCP Client * Fixed code path for net6 and higher * Reworked NoReconnection policy, further code improvements * Removed broken test --------- Co-authored-by: CMR <[email protected]>
- Loading branch information
Showing
39 changed files
with
1,663 additions
and
1,360 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
name: Test TwitchLib.Communication Linux | ||
|
||
on: | ||
[push] | ||
|
||
jobs: | ||
tests: | ||
|
||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
dotnet-version: [ '6.0.x' ] | ||
|
||
steps: | ||
- uses: actions/checkout@v3 | ||
- name: Setup .NET | ||
uses: actions/setup-dotnet@v2 | ||
with: | ||
dotnet-version: ${{ matrix.dotnet-version }} | ||
- name: Restore dependencies | ||
run: dotnet restore | ||
- name: Build TwitchLib.Communication | ||
run: dotnet build --no-restore --configuration Release | ||
- name: Test | ||
run: dotnet test --no-restore --verbosity normal |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
name: Test TwitchLib.Communication Windows | ||
|
||
on: | ||
[push] | ||
|
||
jobs: | ||
tests: | ||
|
||
runs-on: windows-latest | ||
strategy: | ||
matrix: | ||
dotnet-version: [ '6.0.x' ] | ||
|
||
steps: | ||
- uses: actions/checkout@v3 | ||
- name: Setup .NET | ||
uses: actions/setup-dotnet@v2 | ||
with: | ||
dotnet-version: ${{ matrix.dotnet-version }} | ||
- name: Restore dependencies | ||
run: dotnet restore | ||
- name: Build TwitchLib.Communication | ||
run: dotnet build --no-restore --configuration Release | ||
- name: Test | ||
run: dotnet test --no-restore --verbosity normal |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -233,4 +233,7 @@ $RECYCLE.BIN/ | |
*.msp | ||
|
||
# Windows shortcuts | ||
*.lnk | ||
*.lnk | ||
|
||
# Rider files | ||
.idea/* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
# Changelog | ||
|
||
## Version 2.0.0 | ||
### Addresses | ||
##### Issues | ||
- https://github.com/TwitchLib/TwitchLib/issues/1093 | ||
- https://github.com/TwitchLib/TwitchLib.Client/issues/206 | ||
- https://github.com/TwitchLib/TwitchLib/issues/1104 | ||
- https://github.com/TwitchLib/TwitchLib.Communication/issues/13 | ||
- https://github.com/TwitchLib/TwitchLib.Communication/issues/7 | ||
|
||
##### Pull Requests | ||
- none | ||
|
||
--- | ||
|
||
### Changes | ||
|
||
--- | ||
|
||
#### IClient | ||
##### Changed | ||
- now extends `IDisposable` | ||
- `event EventHandler<OnReconnectedEventArgs> OnReconnected;` | ||
- to `event EventHandler<OnConnectedEventArgs> OnReconnected;` | ||
- now the `event`handlers argument is `OnConnectedEventArgs` instead of `OnReconnectedEventArgs` | ||
- the specific `event`handler itself, determines wether the args are in context of connect or reconnect | ||
- `IClient.Send(string message)` is now synchronized because | ||
- `ThrottlerService` got removed | ||
- https://learn.microsoft.com/en-us/dotnet/api/system.net.sockets.networkstream?view=netstandard-2.0#remarks | ||
##### Added | ||
- none | ||
##### Removed | ||
- see also: https://discuss.dev.twitch.tv/t/deprecation-of-chat-commands-through-irc/40486 | ||
- `bool SendWhisper(string message);` | ||
- `void WhisperThrottled(OnWhisperThrottledEventArgs eventArgs);` | ||
- `event EventHandler<OnDataEventArgs> OnData;` | ||
- as far as i got it right, | ||
- binary data is not received | ||
- it has never ever been used/raised | ||
- `event EventHandler<OnMessageThrottledEventArgs> OnMessageThrottled;` | ||
- because `ThrottlerService` is now part of `TwitchLib.Client` | ||
- `event EventHandler<OnStateChangedEventArgs> OnStateChanged;` | ||
- neither used by `TwitchLib.Client` nor by `TwitchLib.PubSub` | ||
--- | ||
|
||
#### ClientOptions | ||
##### Changed | ||
- `value`s for properties can only be passed by `ctor` | ||
- `ctor` also takes an argument for `ReconnectionPolicy` | ||
- by leaving it `null`, a `default` `ReconnectionPolicy` is created, that attempts to reconnect every 3_000 milliseconds for ten times | ||
- `DisconnectWait` became an unsigned integer (`uint`), to ensure only positive values are used for it | ||
##### Removed | ||
- see also: https://discuss.dev.twitch.tv/t/deprecation-of-chat-commands-through-irc/40486 | ||
- `TimeSpan WhisperThrottlingPeriod { get; set; }` | ||
- `int WhispersAllowedInPeriod { get; set; }` | ||
- `int WhisperQueueCapacity { get; set; }` | ||
##### <span id="ClientOptions.Moved">Moved</span> | ||
- the following properties went to `TwitchLib.Client.Models.SendOptions` | ||
- `int SendQueueCapacity { get; set; }` | ||
- `TimeSpan SendCacheItemTimeout { get; set; }` | ||
- `ushort SendDelay { get; set; }` | ||
- `TimeSpan ThrottlingPeriod { get; set; }` | ||
- `int MessagesAllowedInPeriod { get; set; }` | ||
|
||
--- | ||
|
||
#### ConnectionWatchDog | ||
- now the `ConnectionWatchDog` enforces reconnect according to the `ReconnectionPolicy` | ||
- `ConnectionWatchDog` does not send `PING :tmi.twitch.tv`-messages anymore | ||
- `TwitchLib.Client` receives `PING :tmi.twitch.tv`-messages and has to reply with `PONG :tmi.twitch.tv` | ||
- https://dev.twitch.tv/docs/irc/#keepalive-messages | ||
- `TwitchLib.Client` does so | ||
- it handles received PING-messages | ||
- `TwitchLib.PubSub` has to send `PING :tmi.twitch.tv` within at least every five minutes | ||
- https://dev.twitch.tv/docs/pubsub/#connection-management | ||
- `TwitchLib.PubSub` does so | ||
- it has its own PING- and PONG-Timer | ||
|
||
--- | ||
|
||
#### Throttling/ThrottlerService | ||
- `TwitchLib.Communication.IClient` doesnt throttle messages anymore | ||
- `TwitchLib.PubSub` does not need it | ||
- only `TwitchLib.Client` needs it | ||
- so, throttling went to `TwitchLib.Client.Services.ThrottlerService` in combination with `TwitchLib.Client.Services.Throttler` | ||
- everything related to throttling got removed | ||
- `TwitchLib.Communication.Events.OnMessageThrottledEventArgs` | ||
- `TwitchLib.Communication.Interfaces.IClientOptions` | ||
- see also [ClientOptions.Moved](#ClientOptions.Moved) | ||
- `int SendQueueCapacity { get; set; }` | ||
- `TimeSpan SendCacheItemTimeout { get; set; }` | ||
- `ushort SendDelay { get; set; }` | ||
- `TimeSpan ThrottlingPeriod { get; set; }` | ||
- `int MessagesAllowedInPeriod { get; set; }` | ||
|
||
--- | ||
|
||
#### OnStateChangedEventArgs | ||
- removed | ||
- neither used by `TwitchLib.Client` nor by `TwitchLib.PubSub` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
185 changes: 185 additions & 0 deletions
185
src/TwitchLib.Communication.Tests/Clients/ClientTestsBase.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,185 @@ | ||
using System; | ||
using System.Reflection; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using Microsoft.Extensions.Logging; | ||
using TwitchLib.Communication.Events; | ||
using TwitchLib.Communication.Interfaces; | ||
using TwitchLib.Communication.Models; | ||
using TwitchLib.Communication.Tests.Helpers; | ||
using Xunit; | ||
|
||
namespace TwitchLib.Communication.Tests.Clients | ||
{ | ||
/// <summary> | ||
/// bundles <see cref="IClient"/>-Tests in one container | ||
/// </summary> | ||
/// <typeparam name="T"> | ||
/// <list type="bullet"> | ||
/// <see cref="Clients.TcpClient"/> | ||
/// </list> | ||
/// <list type="bullet"> | ||
/// <see cref="Clients.WebSocketClient"/> | ||
/// </list> | ||
/// </typeparam> | ||
public abstract class ClientTestsBase<T> where T : IClient | ||
{ | ||
private static uint WaitAfterDispose => 3; | ||
private static TimeSpan WaitOneDuration => TimeSpan.FromSeconds(5); | ||
private static IClientOptions Options; | ||
|
||
public ClientTestsBase(IClientOptions options = null) | ||
{ | ||
Options = options; | ||
} | ||
|
||
[Fact] | ||
public void Client_Raises_OnConnected_EventArgs() | ||
{ | ||
// create one logger per test-method! - cause one file per test-method is generated | ||
ILogger<T> logger = TestLogHelper.GetLogger<T>(); | ||
T? client = GetClient(logger, Options); | ||
Assert.NotNull(client); | ||
try | ||
{ | ||
ManualResetEvent pauseConnected = new ManualResetEvent(false); | ||
|
||
Assert.Raises<OnConnectedEventArgs>( | ||
h => client.OnConnected += h, | ||
h => client.OnConnected -= h, | ||
() => | ||
{ | ||
client.OnConnected += (sender, e) => pauseConnected.Set(); | ||
client.Open(); | ||
Assert.True(pauseConnected.WaitOne(WaitOneDuration)); | ||
}); | ||
} | ||
catch (Exception e) | ||
{ | ||
logger.LogError(e.ToString()); | ||
Assert.Fail(e.ToString()); | ||
} | ||
finally | ||
{ | ||
Cleanup(client); | ||
} | ||
} | ||
|
||
[Fact] | ||
public void Client_Raises_OnDisconnected_EventArgs() | ||
{ | ||
// create one logger per test-method! - cause one file per test-method is generated | ||
ILogger<T> logger = TestLogHelper.GetLogger<T>(); | ||
T? client = GetClient(logger, Options); | ||
Assert.NotNull(client); | ||
try | ||
{ | ||
ManualResetEvent pauseDisconnected = new ManualResetEvent(false); | ||
|
||
Assert.Raises<OnDisconnectedEventArgs>( | ||
h => client.OnDisconnected += h, | ||
h => client.OnDisconnected -= h, | ||
() => | ||
{ | ||
client.OnConnected += (sender, e) => | ||
{ | ||
Task.Delay(WaitOneDuration).GetAwaiter().GetResult(); | ||
client.Close(); | ||
}; | ||
client.OnDisconnected += (sender, e) => pauseDisconnected.Set(); | ||
client.Open(); | ||
Assert.True(pauseDisconnected.WaitOne(WaitOneDuration)); | ||
}); | ||
} | ||
catch (Exception e) | ||
{ | ||
logger.LogError(e.ToString()); | ||
Assert.Fail(e.ToString()); | ||
} | ||
finally | ||
{ | ||
Cleanup(client); | ||
} | ||
} | ||
|
||
[Fact] | ||
public void Client_Raises_OnReconnected_EventArgs() | ||
{ | ||
// create one logger per test-method! - cause one file per test-method is generated | ||
ILogger<T> logger = TestLogHelper.GetLogger<T>(); | ||
T? client = GetClient(logger, Options); | ||
Assert.NotNull(client); | ||
try | ||
{ | ||
ManualResetEvent pauseReconnected = new ManualResetEvent(false); | ||
|
||
Assert.Raises<OnConnectedEventArgs>( | ||
h => client.OnReconnected += h, | ||
h => client.OnReconnected -= h, | ||
() => | ||
{ | ||
client.OnConnected += (s, e) => client.Reconnect(); | ||
|
||
client.OnReconnected += (s, e) => pauseReconnected.Set(); | ||
client.Open(); | ||
|
||
Assert.True(pauseReconnected.WaitOne(WaitOneDuration)); | ||
}); | ||
} | ||
catch (Exception e) | ||
{ | ||
logger.LogError(e.ToString()); | ||
Assert.Fail(e.ToString()); | ||
} | ||
finally | ||
{ | ||
Cleanup(client); | ||
} | ||
} | ||
|
||
[Fact] | ||
public void Dispose_Client_Before_Connecting_IsOK() | ||
{ | ||
// create one logger per test-method! - cause one file per test-method is generated | ||
ILogger<T> logger = TestLogHelper.GetLogger<T>(); | ||
IClient? client = null; | ||
try | ||
{ | ||
client = GetClient(logger, Options); | ||
Assert.NotNull(client); | ||
client.Dispose(); | ||
} | ||
catch (Exception e) | ||
{ | ||
logger.LogError(e.ToString()); | ||
Assert.Fail(e.ToString()); | ||
} | ||
finally | ||
{ | ||
Cleanup((T?)client); | ||
} | ||
} | ||
|
||
private static void Cleanup(T? client) | ||
{ | ||
client?.Dispose(); | ||
Task.Delay(TimeSpan.FromSeconds(WaitAfterDispose)).GetAwaiter().GetResult(); | ||
} | ||
|
||
private static TClient? GetClient<TClient>(ILogger<TClient> logger, IClientOptions? options = null) | ||
{ | ||
Type[] constructorParameterTypes = new Type[] | ||
{ | ||
typeof(IClientOptions), | ||
typeof(ILogger<TClient>) | ||
}; | ||
ConstructorInfo? constructor = typeof(TClient).GetConstructor(constructorParameterTypes); | ||
object[] constructorParameters = new object[] | ||
{ | ||
options ?? new ClientOptions(), | ||
logger | ||
}; | ||
return (TClient?)constructor?.Invoke(constructorParameters); | ||
} | ||
} | ||
} |
Oops, something went wrong.