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 5c495ba commit 4d18f07
Show file tree
Hide file tree
Showing 2 changed files with 12 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
12 changes: 11 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,8 @@
using JetBrains.Diagnostics;
using JetBrains.Diagnostics.Internal;
using JetBrains.Lifetimes;
using JetBrains.Threading;
using NUnit.Framework;

// ReSharper disable MethodSupportsCancellation

namespace Test.Lifetimes.Lifetimes
Expand Down Expand Up @@ -1414,5 +1414,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 4d18f07

Please sign in to comment.