1+ // -----------------------------------------------------------------------
2+ // <copyright file="Issue7794Spec.cs" company="Akka.NET Project">
3+ // Copyright (C) 2009-2022 Lightbend Inc. <http://www.lightbend.com>
4+ // Copyright (C) 2013-2025 .NET Foundation <https://github.com/akkadotnet/akka.net>
5+ // </copyright>
6+ // -----------------------------------------------------------------------
7+
8+ using System . Threading . Channels ;
9+ using System . Threading . Tasks ;
10+ using Akka . Streams . Dsl ;
11+ using Akka . TestKit ;
12+ using Xunit ;
13+ using Xunit . Abstractions ;
14+
15+ namespace Akka . Streams . Tests . Implementation ;
16+
17+ public class Issue7794Spec : AkkaSpec
18+ {
19+ private ActorMaterializer Materializer { get ; }
20+
21+ public Issue7794Spec ( ITestOutputHelper helper ) : base ( helper )
22+ {
23+ Materializer = Sys . Materializer ( ) ;
24+ }
25+
26+ [ Fact ( DisplayName = "ChannelSource should not throw NRE when Channel completes" ) ]
27+ public async Task Issue_7794_ChannelSource_NRE ( )
28+ {
29+ var channel = Channel . CreateBounded < Message < string , string > > ( new BoundedChannelOptions ( capacity : 100 )
30+ {
31+ FullMode = BoundedChannelFullMode . Wait ,
32+ SingleReader = true ,
33+ SingleWriter = true ,
34+ AllowSynchronousContinuations = false
35+ } ) ;
36+
37+ var streamRes = ChannelSource . FromReader ( channel . Reader )
38+ . Select ( e => e )
39+ . RunWith ( Sink . Ignore < Message < string , string > > ( ) , Materializer ) ;
40+
41+ _ = Task . Run ( async ( ) =>
42+ {
43+ await Task . Delay ( 100 ) ;
44+ channel . Writer . Complete ( ) ;
45+ } ) ;
46+
47+ await streamRes ;
48+ }
49+
50+ private class Message < TKey , TValue >
51+ {
52+ public TKey Key { get ; set ; }
53+ public TValue Value { get ; set ; }
54+ }
55+ }
0 commit comments