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

Upgrade to NUnit 3.12, Add NetCore 3.0 variant #46

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -207,4 +207,6 @@ UpgradeLog*.htm
.dotnet/

# Tools
tools/
tools/

.vs/
8 changes: 4 additions & 4 deletions build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ Param(
)

$FakeVersion = "4.57.4"
$NUnitVersion = "3.6.0"
$NUnitVersion = "3.9.0"
$DotNetChannel = "preview";
$DotNetVersion = "1.0.0";
$DotNetInstallerUri = "https://raw.githubusercontent.com/dotnet/cli/rel/1.0.0/scripts/obtain/dotnet-install.ps1";
$NugetVersion = "4.1.0";
$DotNetVersion = "3.0.100";
$DotNetInstallerUri = "https://dot.net/v1/dotnet-install.ps1";
$NugetVersion = "5.3.1";
$NugetUrl = "https://dist.nuget.org/win-x86-commandline/v$NugetVersion/nuget.exe"

# Make sure tools folder exists
Expand Down
2 changes: 1 addition & 1 deletion src/api/Reactive.Streams/Reactive.Streams.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<Copyright>CC0 1.0 Universal</Copyright>
<VersionPrefix>1.0.3</VersionPrefix>
<Authors>Reactive Streams</Authors>
<TargetFrameworks>netstandard1.0;net45</TargetFrameworks>
<TargetFrameworks>netstandard1.0;net45;netcoreapp3.0</TargetFrameworks>
<PackageTags>reactive;stream</PackageTags>
<PackageProjectUrl>https://github.com/reactive-streams/reactive-streams-dotnet</PackageProjectUrl>
<PackageLicenseUrl>http://creativecommons.org/publicdomain/zero/1.0/</PackageLicenseUrl>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<AssemblyName>Reactive.Streams.Example.Unicast.Tests</AssemblyName>
<TargetFrameworks>net45</TargetFrameworks>
<TargetFrameworks>net45;netcoreapp3.0</TargetFrameworks>
<RuntimeIdentifier>win7-x64</RuntimeIdentifier>
</PropertyGroup>

Expand All @@ -13,8 +13,8 @@

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.0.0" />
<PackageReference Include="NUnit" Version="3.7.1" />
<PackageReference Include="NUnit3TestAdapter" Version="3.8.0" />
<PackageReference Include="NUnit" Version="3.12" />
<PackageReference Include="NUnit3TestAdapter" Version="3.15.1" />
</ItemGroup>

<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Diagnostics;
using System.Threading.Tasks;

namespace Reactive.Streams.Example.Unicast
{
public class AsyncIterablePublisher<T> : IPublisher<T>
{
{
// These represent the protocol of the `AsyncIterablePublishers` SubscriptionImpls
private interface ISignal { }

Expand Down Expand Up @@ -61,7 +62,7 @@ public AsyncIterablePublisher(IEnumerable<T> elements) : this(elements, DefaultB

private AsyncIterablePublisher(IEnumerable<T> elements, int batchSize)
{
if(elements == null)
if (elements == null)
throw new ArgumentNullException(nameof(elements));
if (batchSize < 1)
throw new ArgumentNullException(nameof(batchSize), "batchSize must be greater than zero!");
Expand Down Expand Up @@ -121,13 +122,13 @@ public SubscriptionImplementation(IEnumerable<T> elements, int batchSize, ISubsc
if (_inboundSignals.TryDequeue(out signal) && !_cancelled) // to make sure that we follow rule 1.8, 3.6 and 3.7
{
// Below we simply unpack the `Signal`s and invoke the corresponding method
if(signal is RequestSignal)
if (signal is RequestSignal)
DoRequest(((RequestSignal)signal).N);
else if (signal == SendSignal.Instance)
DoSend();
else if(signal == CancelSignal.Instance)
else if (signal == CancelSignal.Instance)
DoCancel();
else if(signal == SubscribeSignal.Instance)
else if (signal == SubscribeSignal.Instance)
DoSubscribe();
}
}
Expand All @@ -144,12 +145,12 @@ public SubscriptionImplementation(IEnumerable<T> elements, int batchSize, ISubsc
private void DoRequest(long n)
{
if (n < 1)
TerminateDueTo(new ArgumentException(_subscriber +" violated the Reactive Streams rule 3.9 by requesting a non-positive number of elements"));
TerminateDueTo(new ArgumentException(_subscriber + " violated the Reactive Streams rule 3.9 by requesting a non-positive number of elements"));
else if (_demand + n < 1)
{
// As governed by rule 3.17, when demand overflows `long.MaxValue` we treat the signalled demand as "effectively unbounded"
_demand = long.MaxValue;
// Here we protect from the overflow and treat it as "effectively unbounded"
// Here we protect from the overflow and treat it as "effectively unbounded"
DoSend(); // Then we proceed with sending data downstream
}
else
Expand Down Expand Up @@ -250,13 +251,13 @@ private void DoSend()
try
{
next = _enumerator.Current;
// We have already checked `MoveNext` when subscribing, so we can fall back to testing -after- `Current` is called.
// We have already checked `MoveNext` when subscribing, so we can fall back to testing -after- `Current` is called.
hasNext = _enumerator.MoveNext(); // Need to keep track of End-of-Stream
}
catch (Exception ex)
{
TerminateDueTo(ex);
// If `Current` or `MoveNext` throws (they can, since it is user-provided), we need to treat the stream as errored as per rule 1.4
// If `Current` or `MoveNext` throws (they can, since it is user-provided), we need to treat the stream as errored as per rule 1.4
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@ public bool Value
{
get
{
Interlocked.MemoryBarrier();
return _value == TrueValue;
return Volatile.Read(ref _value) == TrueValue;
}
set
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<AssemblyName>Reactive.Streams.Example.Unicast</AssemblyName>
<TargetFrameworks>netstandard1.4;net45</TargetFrameworks>
<TargetFrameworks>netstandard1.4;net45;netcoreapp3.0</TargetFrameworks>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
</PropertyGroup>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<AssemblyName>Reactive.Streams.TCK.Tests</AssemblyName>
<TargetFrameworks>net45</TargetFrameworks>
<TargetFrameworks>net45;netcoreapp3.0</TargetFrameworks>
<RuntimeIdentifier>win7-x64</RuntimeIdentifier>
</PropertyGroup>

Expand All @@ -13,8 +13,8 @@

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.0.0" />
<PackageReference Include="NUnit" Version="3.7.1" />
<PackageReference Include="NUnit3TestAdapter" Version="3.8.0" />
<PackageReference Include="NUnit" Version="3.12" />
<PackageReference Include="NUnit3TestAdapter" Version="3.15.1" />
</ItemGroup>

<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
Expand Down
42 changes: 29 additions & 13 deletions src/tck/Reactive.Streams.TCK/PublisherVerification.cs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ public void Required_createPublisher1MustProduceAStreamOfExactly1Element()
ActivePublisherTest(1, true, publisher =>
{
var subscriber = _environment.NewManualSubscriber(publisher);
Assert.True(requestNextElementOrEndOfStream(publisher, subscriber).HasValue, $"Publisher {publisher} produced no elements");
InternalAssertTrue(requestNextElementOrEndOfStream(publisher, subscriber).HasValue, $"Publisher {publisher} produced no elements");
subscriber.RequestEndOfStream();
});
}
Expand All @@ -145,20 +145,20 @@ public void Required_createPublisher3MustProduceAStreamOfExactly3Elements()
ActivePublisherTest(3, true, publisher =>
{
var subscriber = _environment.NewManualSubscriber(publisher);
Assert.True(requestNextElementOrEndOfStream(publisher, subscriber).HasValue, $"Publisher {publisher} produced no elements");
Assert.True(requestNextElementOrEndOfStream(publisher, subscriber).HasValue, $"Publisher {publisher} produced only 1 element");
Assert.True(requestNextElementOrEndOfStream(publisher, subscriber).HasValue, $"Publisher {publisher} produced only 3 element");
InternalAssertTrue(requestNextElementOrEndOfStream(publisher, subscriber).HasValue, $"Publisher {publisher} produced no elements");
InternalAssertTrue(requestNextElementOrEndOfStream(publisher, subscriber).HasValue, $"Publisher {publisher} produced only 1 element");
InternalAssertTrue(requestNextElementOrEndOfStream(publisher, subscriber).HasValue, $"Publisher {publisher} produced only 3 element");
subscriber.RequestEndOfStream();
});
}

[Test]
public void Required_validate_maxElementsFromPublisher()
=> Assert.True(MaxElementsFromPublisher >= 0, "maxElementsFromPublisher MUST return a number >= 0");
=> InternalAssertTrue(MaxElementsFromPublisher >= 0, "maxElementsFromPublisher MUST return a number >= 0");

[Test]
public void Required_validate_boundedDepthOfOnNextAndRequestRecursion()
=> Assert.True(BoundedDepthOfOnNextAndRequestRecursion >= 1, "boundedDepthOfOnNextAndRequestRecursion must return a number >= 1");
=> InternalAssertTrue(BoundedDepthOfOnNextAndRequestRecursion >= 1, "boundedDepthOfOnNextAndRequestRecursion must return a number >= 1");


////////////////////// SPEC RULE VERIFICATION ///////////////////////////////
Expand Down Expand Up @@ -642,8 +642,8 @@ public void Optional_spec111_multicast_mustProduceTheSameElementsInTheSameSequen
check2.Add(z2);
check2.Add(z3);

Assert.AreEqual(r, check1, $"Publisher {publisher} did not produce the same element sequence for subscribers 1 and 2");
Assert.AreEqual(r, check2, $"Publisher {publisher} did not produce the same element sequence for subscribers 1 and 3");
InternalAssertAreEqual(r, check1, $"Publisher {publisher} did not produce the same element sequence for subscribers 1 and 2");
InternalAssertAreEqual(r, check2, $"Publisher {publisher} did not produce the same element sequence for subscribers 1 and 3");
});


Expand All @@ -670,10 +670,18 @@ public void Optional_spec111_multicast_mustProduceTheSameElementsInTheSameSequen
// a similar test *with* completion checking is implemented


Assert.AreEqual(received1, received2, "Expected elements to be signaled in the same sequence to 1st and 2nd subscribers");
Assert.AreEqual(received2, received3, "Expected elements to be signaled in the same sequence to 2st and 3nd subscribers");
InternalAssertAreEqual(received1, received2, "Expected elements to be signaled in the same sequence to 1st and 2nd subscribers");
InternalAssertAreEqual(received2, received3, "Expected elements to be signaled in the same sequence to 2st and 3nd subscribers");
});

private void InternalAssertAreEqual(object one, object two, string message)
{
if (!object.Equals(one, two))
{
throw new AssertionException(message + "\r\nExpected: " + one + "\r\nBut was: " + two);
}
}

// Verifies rule: https://github.com/reactive-streams/reactive-streams-jvm#1.11
[Test]
public void Optional_spec111_multicast_mustProduceTheSameElementsInTheSameSequenceToAllOfItsSubscribersWhenRequestingManyUpfrontAndCompleteAsExpected()
Expand All @@ -697,8 +705,8 @@ public void Optional_spec111_multicast_mustProduceTheSameElementsInTheSameSequen
sub2.ExpectCompletion();
sub3.ExpectCompletion();

Assert.AreEqual(received1, received2, "Expected elements to be signaled in the same sequence to 1st and 2nd subscribers");
Assert.AreEqual(received2, received3, "Expected elements to be signaled in the same sequence to 2st and 3nd subscribers");
InternalAssertAreEqual(received1, received2, "Expected elements to be signaled in the same sequence to 1st and 2nd subscribers");
InternalAssertAreEqual(received2, received3, "Expected elements to be signaled in the same sequence to 2st and 3nd subscribers");
});

///////////////////// SUBSCRIPTION TESTS //////////////////////////////////
Expand Down Expand Up @@ -965,14 +973,22 @@ public void Required_spec312_cancelMustMakeThePublisherToEventuallyStopSignaling
}

// if the Publisher tries to emit more elements than was requested (and/or ignores cancellation) this will throw
Assert.True(onNextSignalled <= totalDemand,
InternalAssertTrue(onNextSignalled <= totalDemand,
$"Publisher signalled {onNextSignalled} elements, which is more than the signalled demand: {totalDemand}");
} while (stillbeeingSignalled);
});

_environment.VerifyNoAsyncErrorsNoDelay();
}

private void InternalAssertTrue(bool condition, string message)
{
if (!condition)
{
throw new AssertionException(message);
}
}

// Verifies rule: https://github.com/reactive-streams/reactive-streams-jvm#3.13
[Test]
public void Required_spec313_cancelMustMakeThePublisherEventuallyDropAllReferencesToTheSubscriber()
Expand Down
4 changes: 2 additions & 2 deletions src/tck/Reactive.Streams.TCK/Reactive.Streams.TCK.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<Copyright>CC0 1.0 Universal</Copyright>
<VersionPrefix>1.0.3</VersionPrefix>
<Authors>Reactive Streams</Authors>
<TargetFrameworks>net45</TargetFrameworks>
<TargetFrameworks>net45;netcoreapp3.0</TargetFrameworks>
<PackageTags>reactive;stream</PackageTags>
<PackageProjectUrl>https://github.com/reactive-streams/reactive-streams-dotnet</PackageProjectUrl>
<PackageLicenseUrl>http://creativecommons.org/publicdomain/zero/1.0/</PackageLicenseUrl>
Expand All @@ -19,7 +19,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="NUnit" Version="3.7.1" />
<PackageReference Include="NUnit" Version="3.12" />
</ItemGroup>

<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
Expand Down
14 changes: 11 additions & 3 deletions src/tck/Reactive.Streams.TCK/SubscriberBlackboxVerification.cs
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ public void Required_spec213_blackbox_onSubscribe_mustThrowNullPointerExceptionW
gotNpe = true;
}

Assert.True(gotNpe, "OnSubscribe(null) did not throw ArgumentNullException");
InternalAssertTrue(gotNpe, "OnSubscribe(null) did not throw ArgumentNullException");
Environment.VerifyNoAsyncErrorsNoDelay();
});

Expand All @@ -327,7 +327,7 @@ public void Required_spec213_blackbox_onNext_mustThrowNullPointerExceptionWhenPa
gotNpe = true;
}

Assert.True(gotNpe, "OnNext(null) did not throw ArgumentNullException");
InternalAssertTrue(gotNpe, "OnNext(null) did not throw ArgumentNullException");
Environment.VerifyNoAsyncErrorsNoDelay();
});

Expand All @@ -349,10 +349,18 @@ public void Required_spec213_blackbox_onError_mustThrowNullPointerExceptionWhenP
gotNpe = true;
}

Assert.True(gotNpe, "OnError(null) did not throw ArgumentNullException");
InternalAssertTrue(gotNpe, "OnError(null) did not throw ArgumentNullException");
Environment.VerifyNoAsyncErrorsNoDelay();
});

private void InternalAssertTrue(bool condition, string message)
{
if (!condition)
{
throw new AssertionException(message);
}
}

private sealed class Spec213DummySubscription : ISubscription
{
public void Request(long n)
Expand Down
Loading