-
-
Notifications
You must be signed in to change notification settings - Fork 70
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Make the disposing of application context thread safe * Fix the example app using get calendar events * Make the handling of cancellation more roboust to avoid the source to be disposed before all tasks been completed * added tests * Fixed the throw instead * Ignore and tracelog the operation cancelled exception in background task * revert throwifcanceled #1 * revert throwif cancelled #2 * Add the Flush feature on BackgroundTaskTracker * Fix the scheduler to be more robust and not call actions on disposed schedulers * Fix the code comment using interlocked instead * Fix warning and missing setting the disposed flag * add test * Added context tests * Added even more tests * add tests * fix test * remove the last of throwifcancelled * Add one more test * renaming * Fix comments and from discussion * removed timing using TaskSource * using interlocked on more places * removed the disposable timer * fix last interlocked case * forgott the test * revert back to volatile bools * Added more checks for disposed and throws if so * added test for multople dispose * fix from comment
- Loading branch information
1 parent
089f848
commit 4a3cbb5
Showing
21 changed files
with
453 additions
and
121 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
18 changes: 18 additions & 0 deletions
18
src/AppModel/NetDaemon.AppModel.Tests/Context/ApplicationContextTests.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,18 @@ | ||
using NetDaemon.AppModel.Internal; | ||
using NetDaemon.AppModel.Internal.AppFactories; | ||
|
||
namespace NetDaemon.AppModel.Tests.Context; | ||
|
||
public class ApplicationContextTests | ||
{ | ||
[Fact] | ||
public async Task TestApplicationContextIsDisposedMultipleTimesNotThrowsException() | ||
{ | ||
var serviceProvider = new ServiceCollection().BuildServiceProvider(); | ||
var appFactory = Mock.Of<IAppFactory>(); | ||
var applicationContext = new ApplicationContext(serviceProvider, appFactory); | ||
|
||
await applicationContext.DisposeAsync(); | ||
await applicationContext.DisposeAsync(); | ||
} | ||
} |
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
65 changes: 65 additions & 0 deletions
65
...Client/NetDaemon.HassClient.Tests/HomeAssistantClientTest/HomeAssistantConnectionTests.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,65 @@ | ||
namespace NetDaemon.HassClient.Tests.HomeAssistantClientTest; | ||
|
||
public record FakeCommand : CommandMessage {} | ||
|
||
public class HomeAssistantConnectionTests | ||
{ | ||
private static IHomeAssistantConnection GetDefaultHomeAssistantConnection() | ||
{ | ||
var pipeline = new TransportPipelineMock(); | ||
pipeline.Setup(n => n.WebSocketState).Returns(WebSocketState.Open); | ||
var apiManagerMock = new Mock<IHomeAssistantApiManager>(); | ||
var loggerMock = new Mock<ILogger<IHomeAssistantConnection>>(); | ||
return new HomeAssistantConnection(loggerMock.Object, pipeline.Object, apiManagerMock.Object); | ||
} | ||
|
||
[Fact] | ||
public async Task UsingDisposedConnectionWhenSendCommandShouldThrowException() | ||
{ | ||
var homeAssistantConnection = GetDefaultHomeAssistantConnection(); | ||
await homeAssistantConnection!.DisposeAsync(); | ||
|
||
Func<Task> act = async () => | ||
{ | ||
await homeAssistantConnection!.SendCommandAsync(new FakeCommand(), CancellationToken.None); | ||
}; | ||
|
||
await act.Should().ThrowAsync<ObjectDisposedException>(); | ||
} | ||
|
||
[Fact] | ||
public async Task UsingDisposedConnectionWhenGetApiCommandShouldThrowException() | ||
{ | ||
var homeAssistantConnection = GetDefaultHomeAssistantConnection(); | ||
await homeAssistantConnection!.DisposeAsync(); | ||
|
||
Func<Task> act = async () => | ||
{ | ||
await homeAssistantConnection!.GetApiCallAsync<string>("test", CancellationToken.None); | ||
}; | ||
|
||
await act.Should().ThrowAsync<ObjectDisposedException>(); | ||
} | ||
|
||
[Fact] | ||
public async Task UsingDisposedConnectionWhenPostApiShouldThrowException() | ||
{ | ||
var homeAssistantConnection = GetDefaultHomeAssistantConnection(); | ||
await homeAssistantConnection!.DisposeAsync(); | ||
|
||
Func<Task> act = async () => | ||
{ | ||
await homeAssistantConnection!.PostApiCallAsync<string>("test", CancellationToken.None, null); | ||
}; | ||
|
||
await act.Should().ThrowAsync<ObjectDisposedException>(); | ||
} | ||
|
||
[Fact] | ||
public async Task HomeAssistantConnectionDisposedMultipleTimesShouldNotThrow() | ||
{ | ||
var homeAssistantConnection = GetDefaultHomeAssistantConnection(); | ||
await homeAssistantConnection!.DisposeAsync(); | ||
await homeAssistantConnection!.DisposeAsync(); | ||
} | ||
} |
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
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
16 changes: 0 additions & 16 deletions
16
src/Extensions/NetDaemon.Extensions.Scheduling.Tests/Scheduling/DisposableTimerTest.cs
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.