Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Async TestKit] Convert Akka.Streams.Tests to async - OutputStreamSinkSpec #5919

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 29 additions & 20 deletions src/core/Akka.Streams.Tests/IO/OutputStreamSinkSpec.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,19 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Threading.Tasks;
using Akka.Actor;
using Akka.IO;
using Akka.Streams.Dsl;
using Akka.Streams.IO;
using Akka.Streams.TestKit;
using Akka.TestKit;
using Akka.TestKit.Extensions;
using FluentAssertions;
using FluentAssertions.Extensions;
using Xunit;
using Xunit.Abstractions;
using static FluentAssertions.FluentActions;

namespace Akka.Streams.Tests.IO
{
Expand Down Expand Up @@ -199,9 +204,9 @@ public OutputStreamSinkSpec(ITestOutputHelper helper) : base(Utils.UnboundedMail
}

[Fact]
public void OutputStreamSink_must_write_bytes_to_void_OutputStream()
public async Task OutputStreamSink_must_write_bytes_to_void_OutputStream()
{
this.AssertAllStagesStopped(() =>
await this.AssertAllStagesStoppedAsync(async () =>
{
var p = CreateTestProbe();
var datas = new List<ByteString>
Expand All @@ -214,48 +219,52 @@ public void OutputStreamSink_must_write_bytes_to_void_OutputStream()
var completion = Source.From(datas)
.RunWith(StreamConverters.FromOutputStream(() => new VoidOutputStream(p)), _materializer);

p.ExpectMsg(datas[0].ToString());
p.ExpectMsg(datas[1].ToString());
p.ExpectMsg(datas[2].ToString());
completion.Wait(TimeSpan.FromSeconds(3));
await p.ExpectMsgAsync(datas[0].ToString());
await p.ExpectMsgAsync(datas[1].ToString());
await p.ExpectMsgAsync(datas[2].ToString());
await completion.ShouldCompleteWithin(3.Seconds());
}, _materializer);
}

[Fact]
public void OutputStreamSink_must_close_underlying_stream_when_error_received()
public async Task OutputStreamSink_must_close_underlying_stream_when_error_received()
{
this.AssertAllStagesStopped(() =>
await this.AssertAllStagesStoppedAsync(async () =>
{
var p = CreateTestProbe();
Source.Failed<ByteString>(new Exception("Boom!"))
var completion = Source.Failed<ByteString>(new Exception("Boom!"))
.RunWith(StreamConverters.FromOutputStream(() => new CloseOutputStream(p)), _materializer);

p.ExpectMsg("closed");
await p.ExpectMsgAsync("closed");
await completion.ShouldCompleteWithin(3.Seconds());
}, _materializer);
}

[Fact]
public void OutputStreamSink_must_complete_materialized_value_with_the_error()
public async Task OutputStreamSink_must_complete_materialized_value_with_the_error()
{
this.AssertAllStagesStopped(() =>
await this.AssertAllStagesStoppedAsync(async () =>
{
var completion = Source.Failed<ByteString>(new Exception("Boom!"))
.RunWith(StreamConverters.FromOutputStream(() => new OutputStream()), _materializer);

AssertThrows<AbruptIOTerminationException>(completion.Wait);
await Awaiting(async () =>
{
await Source.Failed<ByteString>(new Exception("Boom!"))
.RunWith(StreamConverters.FromOutputStream(() => new OutputStream()), _materializer)
.ShouldCompleteWithin(3.Seconds());
}).Should().ThrowAsync<AbruptIOTerminationException>();
}, _materializer);
}

[Fact]
public void OutputStreamSink_must_close_underlying_stream_when_completion_received()
public async Task OutputStreamSink_must_close_underlying_stream_when_completion_received()
{
this.AssertAllStagesStopped(() =>
await this.AssertAllStagesStoppedAsync(async () =>
{
var p = CreateTestProbe();
Source.Empty<ByteString>()
var completion = Source.Empty<ByteString>()
.RunWith(StreamConverters.FromOutputStream(() => new CompletionOutputStream(p)), _materializer);

p.ExpectMsg("closed");
await p.ExpectMsgAsync("closed");
await completion.ShouldCompleteWithin(3.Seconds());
}, _materializer);
}
}
Expand Down