Skip to content

Commit

Permalink
Lifetime.Eternal.KeepAlive should throw an assertion
Browse files Browse the repository at this point in the history
  • Loading branch information
ForNeVeR committed Nov 3, 2023
1 parent d5dbf03 commit 5a66ce2
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
2 changes: 1 addition & 1 deletion rd-net/Lifetimes/Lifetimes/Lifetime.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
using JetBrains.Core;
using JetBrains.Diagnostics;
using JetBrains.Threading;

#if !NET35

#endif
Expand Down Expand Up @@ -612,6 +611,7 @@ public async Task UsingNestedAsync([InstantHandle] Func<Lifetime, Task> action)
[PublicAPI]
public Lifetime KeepAlive(object @object)
{
Assertion.Assert(!IsEternal);
if (@object == null) throw new ArgumentNullException(nameof(@object));

return OnTermination(() => GC.KeepAlive(@object));
Expand Down
15 changes: 14 additions & 1 deletion rd-net/Test.Lifetimes/Lifetimes/LifetimeTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@
using JetBrains.Diagnostics;
using JetBrains.Diagnostics.Internal;
using JetBrains.Lifetimes;
using JetBrains.Threading;
using NUnit.Framework;
#if !NET35
using JetBrains.Threading;
#endif

// ReSharper disable MethodSupportsCancellation

namespace Test.Lifetimes.Lifetimes
Expand Down Expand Up @@ -1414,5 +1417,15 @@ public void DefineLifetimeInheritTimeoutKindTest()

Assert.AreEqual(LifetimeTerminationTimeoutKind.ExtraLong, OuterLifetime.Define(definition.Lifetime, "id", (ld, lf) => {}).TerminationTimeoutKind);
}

[Test]
public void EternalLifetimeKeepalive()
{
Assert.Throws<Assertion.AssertionException>(() =>
{
var o = new object();
Lifetime.Eternal.KeepAlive(o);
});
}
}
}

0 comments on commit 5a66ce2

Please sign in to comment.