Skip to content

Conversation

@Rick-van-Dam
Copy link
Contributor

Proposed change

Check before running the dispose code if the object has already been disposed previously. If so skip the code.

Also added a simple unit test to check if its possible to dispose twice without exception.

Type of change

  • Dependency upgrade
  • Bugfix (non-breaking change which fixes an issue)
  • New feature (which adds functionality to an existing integration)
  • Breaking change (fix/feature causing existing functionality to break)
  • Code quality improvements to existing code or addition of tests

Additional information

Checklist

  • The code change is tested and works locally.
  • Local tests pass. Your PR cannot be merged unless tests pass
  • There is no commented out code in this PR.
  • I have followed the [development checklist][dev-checklist]
  • The code compiles without warnings (code quality chek)
  • Tests have been added to verify that the new code works.

/// Implements a IDisposable to cancel timers
/// </summary>
public sealed class DisposableTimer : IDisposable
{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this class should have been internal actually

@codecov-commenter
Copy link

Codecov Report

Base: 78.06% // Head: 78.00% // Decreases project coverage by -0.06% ⚠️

Coverage data is based on head (86de16b) compared to base (c12c0c9).
Patch coverage: 100.00% of modified lines in pull request are covered.

Additional details and impacted files
@@            Coverage Diff             @@
##              dev     #799      +/-   ##
==========================================
- Coverage   78.06%   78.00%   -0.07%     
==========================================
  Files         152      152              
  Lines        3999     4005       +6     
  Branches      402      404       +2     
==========================================
+ Hits         3122     3124       +2     
- Misses        717      721       +4     
  Partials      160      160              
Flag Coverage Δ
unittests 78.00% <100.00%> (-0.07%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
...aemon.Extensions.Scheduling/DisposableScheduler.cs 88.63% <100.00%> (+0.83%) ⬆️
...NetDaemon.Extensions.Scheduling/DisposableTimer.cs 100.00% <100.00%> (ø)
...mon.HassClient/Internal/HomeAssistantConnection.cs 88.79% <0.00%> (-3.45%) ⬇️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.


public class DisposableTimerTest
{
[Fact]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion:
Because this is really a helper class that should be internal it does not seem to deserve its own test class. You could move this test to SchedulerExtensionTest.SchedulePeriodicStopsAfterDisposeOfSubscriber() and dispose the result of disposable.RunEvery there twice

@FrankBakkerNl FrankBakkerNl merged commit 1cf015d into net-daemon:dev Dec 9, 2022
helto4real pushed a commit to Ikcelaks/netdaemon that referenced this pull request Dec 17, 2022
* Check if already disposed and skip if so

* Add unit test to check dispose functionality
Ikcelaks pushed a commit to Ikcelaks/netdaemon that referenced this pull request Dec 23, 2022
* Check if already disposed and skip if so

* Add unit test to check dispose functionality
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Calling dispose twice on DisposableTimer raises a exception

3 participants