Skip to content

Commit

Permalink
Fail FileSubscriber's Task if it can't open the file
Browse files Browse the repository at this point in the history
  • Loading branch information
ismaelhamed committed May 25, 2021
1 parent 6e53684 commit 03338fa
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
12 changes: 12 additions & 0 deletions src/core/Akka.Streams.Tests/IO/FileSinkSpec.cs
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,18 @@ public void SynchronousFileSink_should_complete_materialized_task_with_an_except
}, _materializer);
}

[Fact]
public void SynchronousFileSink_should_complete_with_failure_when_file_cannot_be_open()
{
TargetFile(f =>
{
var completion = Source.Single(ByteString.FromString("42"))
.RunWith(FileIO.ToFile(new FileInfo("I-hope-this-file-doesnt-exist.txt"), FileMode.Open), _materializer);
AssertThrows<FileNotFoundException>(completion.Wait);
}, _materializer);
}

[Fact]
public void SynchronousFileSink_should_write_each_element_if_auto_flush_is_set()
{
Expand Down
2 changes: 1 addition & 1 deletion src/core/Akka.Streams/Implementation/IO/FileSubscriber.cs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ protected override void PreStart()
}
catch (Exception ex)
{
CloseAndComplete(IOResult.Failed(_bytesWritten, ex));
CloseAndComplete(new Try<IOResult>(ex));
Cancel();
}
}
Expand Down

0 comments on commit 03338fa

Please sign in to comment.